Unverified Commit f192530f authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Pseudo-Integration tests for KMS (#239)

* wip

* Generate Cargo.toml after lib rs, cleanup deps

* Move RecordingConnection into an extras crate

* Move generation code into extras crate

* Delete unused conn method

* Add todo about storing req/resps externally

* Add note about credential expiry

* Fix clippy lint

* Replace creds with fake creds

* Delete note about real credentials

* Give cargo fmt a hand
parent 00671a23
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -116,7 +116,9 @@ mod test {
    fn missing() {
        let env = HashMap::new();
        let provider = EnvironmentVariableCredentialsProvider::for_map(env);
        let err = provider.provide_credentials().expect_err("no credentials defined");
        let err = provider
            .provide_credentials()
            .expect_err("no credentials defined");
        match err {
            CredentialsError::Unhandled(_) => panic!("wrong error type"),
            _ => (),
+4 −2
Original line number Diff line number Diff line
@@ -256,10 +256,12 @@ where
            RetryKind::Error(err) => self.attempt_retry(Err(err))?,
            _ => return None,
        };

        let fut = async move {
            tokio::time::sleep(dur).await;
            next
        }.instrument(tracing::info_span!("retry", kind = &debug(retry)));
        }
        .instrument(tracing::info_span!("retry", kind = &debug(retry)));
        Some(Box::pin(fut))
    }

+23 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use http::header::HeaderName;
use http::Request;
use smithy_http::body::SdkBody;
use std::future::Ready;
@@ -18,6 +19,28 @@ pub struct ValidateRequest {
    pub actual: http::Request<SdkBody>,
}

impl ValidateRequest {
    pub fn assert_matches(&self, ignore_headers: Vec<HeaderName>) {
        let (actual, expected) = (&self.actual, &self.expected);
        for (name, value) in expected.headers() {
            if !ignore_headers.contains(name) {
                let actual_header = actual
                    .headers()
                    .get(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(&[]));
        match (actual_str, expected_str) {
            (Ok(actual), Ok(expected)) => assert_eq!(actual, expected),
            _ => assert_eq!(actual.body().bytes(), expected.body().bytes()),
        };
        assert_eq!(actual.uri(), expected.uri());
    }
}

/// TestConnection for use with a [`aws_hyper::Client`](crate::Client)
///
/// A basic test connection. It will:
+2 −5
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ use aws_auth::Credentials;
use aws_endpoint::{set_endpoint_resolver, DefaultAwsEndpointResolver};
use aws_http::user_agent::AwsUserAgent;
use aws_http::AwsErrorRetryPolicy;
use aws_hyper::test_connection::{TestConnection, ValidateRequest};
use aws_hyper::test_connection::TestConnection;
use aws_hyper::{Client, RetryConfig, SdkError};
use aws_sig_auth::signer::OperationSigningConfig;
use aws_types::region::Region;
@@ -115,10 +115,7 @@ async fn e2e_test() {
    assert_eq!(resp, "Hello!");

    assert_eq!(conn.requests().len(), 1);
    let ValidateRequest { expected, actual } = &conn.requests()[0];
    assert_eq!(actual.headers(), expected.headers());
    assert_eq!(actual.body().bytes(), expected.body().bytes());
    assert_eq!(actual.uri(), expected.uri());
    conn.requests()[0].assert_matches(vec![]);
}

#[tokio::test]
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ use std::borrow::Cow;
pub struct Region(
    // Regions are almost always known statically. However, as an escape hatch for when they
    // are not, allow for an owned region
    Cow<'static, str>
    Cow<'static, str>,
);

impl AsRef<str> for Region {
Loading