Unverified Commit 97c70c42 authored by Zelda Hessler's avatar Zelda Hessler Committed by GitHub
Browse files

add: tests to ensure all interceptors are run if an error occurs in one (#2664)

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->
#2662

## Description
<!--- Describe your changes in detail -->
This PR adds tests for all interceptor hooks to ensure the correct error
handling behavior and defines a set of stub components for orchestrator
testing.

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
This PR includes tests.
----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent c6d36790
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -48,17 +48,17 @@ impl AuthOptionResolverParams {
}

pub trait AuthOptionResolver: Send + Sync + fmt::Debug {
    fn resolve_auth_options<'a>(
        &'a self,
    fn resolve_auth_options(
        &self,
        params: &AuthOptionResolverParams,
    ) -> Result<Cow<'a, [AuthSchemeId]>, BoxError>;
    ) -> Result<Cow<'_, [AuthSchemeId]>, BoxError>;
}

impl AuthOptionResolver for Box<dyn AuthOptionResolver> {
    fn resolve_auth_options<'a>(
        &'a self,
    fn resolve_auth_options(
        &self,
        params: &AuthOptionResolverParams,
    ) -> Result<Cow<'a, [AuthSchemeId]>, BoxError> {
    ) -> Result<Cow<'_, [AuthSchemeId]>, BoxError> {
        (**self).resolve_auth_options(params)
    }
}
+10 −4
Original line number Diff line number Diff line
@@ -23,10 +23,10 @@ impl StaticAuthOptionResolver {
}

impl AuthOptionResolver for StaticAuthOptionResolver {
    fn resolve_auth_options<'a>(
        &'a self,
    fn resolve_auth_options(
        &self,
        _params: &AuthOptionResolverParams,
    ) -> Result<Cow<'a, [AuthSchemeId]>, BoxError> {
    ) -> Result<Cow<'_, [AuthSchemeId]>, BoxError> {
        Ok(Cow::Borrowed(&self.auth_options))
    }
}
@@ -36,8 +36,14 @@ impl AuthOptionResolver for StaticAuthOptionResolver {
pub struct StaticAuthOptionResolverParams;

impl StaticAuthOptionResolverParams {
    /// Creates new `StaticAuthOptionResolverParams`.
    /// Creates a new `StaticAuthOptionResolverParams`.
    pub fn new() -> Self {
        Self
    }
}

impl From<StaticAuthOptionResolverParams> for AuthOptionResolverParams {
    fn from(params: StaticAuthOptionResolverParams) -> Self {
        AuthOptionResolverParams::new(params)
    }
}
+0 −24
Original line number Diff line number Diff line
@@ -65,30 +65,6 @@ impl Identity {
    }
}

#[derive(Debug)]
pub struct AnonymousIdentity;

impl AnonymousIdentity {
    pub fn new() -> Self {
        Self
    }
}

#[derive(Debug)]
pub struct AnonymousIdentityResolver;

impl AnonymousIdentityResolver {
    pub fn new() -> Self {
        AnonymousIdentityResolver
    }
}

impl IdentityResolver for AnonymousIdentityResolver {
    fn resolve_identity(&self, _: &ConfigBag) -> Future<Identity> {
        Future::ready(Ok(Identity::new(AnonymousIdentity::new(), None)))
    }
}

pub mod builders {
    use super::*;
    use crate::client::auth::AuthSchemeId;
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ repository = "https://github.com/awslabs/smithy-rs"

[features]
http-auth = ["aws-smithy-runtime-api/http-auth"]
anonymous-auth = []
test-util = ["dep:aws-smithy-protocol-test"]

[dependencies]
@@ -31,6 +32,8 @@ tracing = "0.1"
[dev-dependencies]
aws-smithy-async = { path = "../aws-smithy-async", features = ["rt-tokio"] }
tokio = { version = "1.25", features = ["macros", "rt", "test-util"] }
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
tracing-test = "0.2.1"

[package.metadata.docs.rs]
all-features = true
+12 −0
Original line number Diff line number Diff line
@@ -16,4 +16,16 @@ pub mod connections;
/// used to limit the rate at which requests are sent.
pub mod retries;

/// Utilities for testing orchestrators. An orchestrator missing required components will panic when
/// run. This module contains stub components that can be used when you only care about testing some
/// specific aspect of the orchestrator.
#[cfg(feature = "test-util")]
pub mod test_util;

mod timeout;

/// Runtime plugins for Smithy clients.
pub mod runtime_plugin;

/// Smithy identity used by auth and signing.
pub mod identity;
Loading