Skip to content

Commit

Permalink
Add DynamoDB pseudo integration test (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh authored Mar 9, 2021
1 parent 9959d9b commit 7d39bf6
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 12 deletions.
8 changes: 7 additions & 1 deletion aws/rust-runtime/aws-hyper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
test-util = ["protocol-test-helpers"]

[dependencies]
hyper = { version = "0.14.2", features = ["client", "http1", "http2", "tcp", "runtime"] }
tower = { version = "0.4.6", features = ["util", "retry"] }
Expand All @@ -21,10 +24,13 @@ smithy-http = { path = "../../../rust-runtime/smithy-http" }
smithy-types = { path = "../../../rust-runtime/smithy-types" }
smithy-http-tower = { path = "../../../rust-runtime/smithy-http-tower" }
fastrand = "1.4.0"
tokio = { version = "1", features = ["time"]}
tokio = { version = "1", features = ["time"] }

pin-project = "1"
tracing = "0.1.25"

protocol-test-helpers = { path = "../../../rust-runtime/protocol-test-helpers", optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["full", "test-util"] }
tower-test = "0.4.0"
Expand Down
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-hyper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod conn;
mod retry;
#[cfg(feature = "test-util")]
pub mod test_connection;

pub use retry::RetryConfig;
Expand Down
21 changes: 14 additions & 7 deletions aws/rust-runtime/aws-hyper/src/test_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use http::header::HeaderName;
use http::header::{HeaderName, CONTENT_TYPE};
use http::Request;
use smithy_http::body::SdkBody;
use std::future::Ready;
use std::ops::Deref;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use tower::BoxError;
use protocol_test_helpers::{validate_body, MediaType, assert_ok};

type ConnectVec<B> = Vec<(http::Request<SdkBody>, http::Response<B>)>;

Expand All @@ -27,14 +28,20 @@ impl ValidateRequest {
let actual_header = actual
.headers()
.get(name)
.unwrap_or_else(||panic!("Header {:?} missing", name));
.unwrap_or_else(|| panic!("Header {:?} missing", name));
assert_eq!(actual_header, value, "Header mismatch for {:?}", name);
}
}
let actual_str = std::str::from_utf8(actual.body().bytes().unwrap_or(&[]));
let expected_str = std::str::from_utf8(expected.body().bytes().unwrap_or(&[]));
let media_type = if actual.headers().get(CONTENT_TYPE).map(|v| v.to_str().unwrap().contains("json")).unwrap_or(false) {
MediaType::Json
} else {
MediaType::Other("unknown".to_string())
};
match (actual_str, expected_str) {
(Ok(actual), Ok(expected)) => assert_eq!(actual, expected),
(Ok(actual), Ok(expected)) =>
assert_ok(validate_body(actual, expected, media_type)),
_ => assert_eq!(actual.body().bytes(), expected.body().bytes()),
};
assert_eq!(actual.uri(), expected.uri());
Expand Down Expand Up @@ -87,7 +94,7 @@ impl<B> TestConnection<B> {
}
}

pub fn requests(&self) -> impl Deref<Target = Vec<ValidateRequest>> + '_ {
pub fn requests(&self) -> impl Deref<Target=Vec<ValidateRequest>> + '_ {
self.requests.lock().unwrap()
}
}
Expand Down Expand Up @@ -126,9 +133,9 @@ mod tests {
fn meets_trait_bounds() {
fn check() -> impl tower::Service<
http::Request<SdkBody>,
Response = http::Response<hyper::Body>,
Error = BoxError,
Future = impl Send,
Response=http::Response<hyper::Body>,
Error=BoxError,
Future=impl Send,
> + Clone {
TestConnection::<String>::new(vec![])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import software.amazon.smithy.rust.codegen.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolConfig
import software.amazon.smithy.rust.codegen.smithy.letIf

val TestedServices = setOf("kms")
val TestedServices = setOf("kms", "dynamodb")

class IntegrationTestDecorator : RustCodegenDecorator {
override val name: String = "IntegrationTest"
Expand All @@ -41,5 +41,5 @@ class AwsHyperDevDep(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat
}
}

val Tokio = CargoDependency("tokio", CratesIo("1"), features = listOf("macros"), scope = DependencyScope.Dev)
fun RuntimeConfig.awsHyper() = CargoDependency("aws-hyper", Local(relativePath))
val Tokio = CargoDependency("tokio", CratesIo("1"), features = listOf("macros", "test-util"), scope = DependencyScope.Dev)
fun RuntimeConfig.awsHyper() = CargoDependency("aws-hyper", Local(relativePath), features = listOf("test-util"))
2 changes: 1 addition & 1 deletion aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
val smithyVersion: String by project

val sdkOutputDir = buildDir.resolve("aws-sdk")
val runtimeModules = listOf("smithy-types", "smithy-http", "smithy-http-tower")
val runtimeModules = listOf("smithy-types", "smithy-http", "smithy-http-tower", "protocol-test-helpers")
val awsModules = listOf("aws-auth", "aws-endpoint", "aws-types", "aws-hyper", "aws-sig-auth", "aws-http")

buildscript {
Expand Down
53 changes: 53 additions & 0 deletions aws/sdk/integration-tests/dynamodb/tests/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[
{
"year": 2013,
"title": "Turn It Down, Or Else!",
"info": {
"directors": [
"Alice Smith",
"Bob Jones"
],
"release_date": "2013-01-18T00:00:00Z",
"rating": 6.2,
"genres": [
"Comedy",
"Drama"
],
"image_url": "http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg",
"plot": "A rock band plays their music at high volumes, annoying the neighbors.",
"rank": 11,
"running_time_secs": 5215,
"actors": [
"David Matthewman",
"Ann Thomas",
"Jonathan G. Neff"
]
}
},
{
"year": 2013,
"title": "Rush",
"info": {
"directors": [
"Ron Howard"
],
"release_date": "2013-09-02T00:00:00Z",
"rating": 8.3,
"genres": [
"Action",
"Biography",
"Drama",
"Sport"
],
"image_url": "http://ia.media-imdb.com/images/M/MV5BMTQyMDE0MTY0OV5BMl5BanBnXkFtZTcwMjI2OTI0OQ@@._V1_SX400_.jpg",
"plot": "A re-creation of the merciless 1970s rivalry between Formula One rivals James Hunt and Niki Lauda.",
"rank": 2,
"running_time_secs": 7380,
"actors": [
"Daniel Bruhl",
"Chris Hemsworth",
"Olivia Wilde"
]
}
}
]
Loading

0 comments on commit 7d39bf6

Please sign in to comment.