Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 16 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions rust-runtime/aws-smithy-runtime-api/src/client/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Comment on lines -51 to -61
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter was complaining about an unnecessary explicit lifetime here and in the auth option resolver so I switched it to an anonymous lifetime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I take it to mean that the compiler deterministically derives the anomalous lifeitme in this case from the first &.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what happens AFAICT

) -> Result<Cow<'_, [AuthSchemeId]>, BoxError> {
(**self).resolve_auth_options(params)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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)
}
}
24 changes: 0 additions & 24 deletions rust-runtime/aws-smithy-runtime-api/src/client/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,6 @@ impl Identity {
}
}

#[derive(Debug)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to aws_smithy_runtime_api::client::identity::anonymous

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;
Expand Down
3 changes: 3 additions & 0 deletions rust-runtime/aws-smithy-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions rust-runtime/aws-smithy-runtime/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 7 additions & 0 deletions rust-runtime/aws-smithy-runtime/src/client/identity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#[cfg(feature = "anonymous-auth")]
pub mod anonymous;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_runtime_api::client::identity::{Identity, IdentityResolver};
use aws_smithy_runtime_api::client::orchestrator::Future;
use aws_smithy_runtime_api::config_bag::ConfigBag;

#[derive(Debug, Default)]
pub struct AnonymousIdentity;

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

#[derive(Debug, Default)]
pub struct AnonymousIdentityResolver;

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

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