@@ -17,16 +17,13 @@ use aws_smithy_runtime::assert_str_contains;
1717use aws_smithy_runtime_api:: http:: Response ;
1818use aws_types:: endpoint_config:: AccountIdEndpointMode ;
1919
20- fn test_client < F > ( update_builder : F ) -> ( Client , CaptureRequestReceiver )
21- where
22- F : Fn ( Builder ) -> Builder ,
23- {
20+ fn test_client ( update_builder : fn ( Builder ) -> Builder ) -> ( Client , CaptureRequestReceiver ) {
2421 let ( http_client, request) = capture_request ( None ) ;
2522 let builder = Config :: builder ( )
2623 . region ( Region :: new ( "us-east-1" ) )
2724 . credentials_provider (
2825 Credentials :: builder ( )
29- . account_id ( "333333333333 " )
26+ . account_id ( "123456789012 " )
3027 . access_key_id ( "ANOTREAL" )
3128 . secret_access_key ( "notrealrnrELgWzOk3IfjzDKtFBhDby" )
3229 . provider_name ( "test" )
3835
3936async fn call_operation (
4037 client : Client ,
38+ table_name : & str ,
4139) -> Result < BatchGetItemOutput , SdkError < BatchGetItemError , Response > > {
4240 let mut attr_v = std:: collections:: HashMap :: new ( ) ;
4341 attr_v. insert ( ":s" . to_string ( ) , AttributeValue :: S ( "value" . into ( ) ) ) ;
@@ -46,66 +44,68 @@ async fn call_operation(
4644 client
4745 . batch_get_item ( )
4846 . request_items (
49- "arn:aws:dynamodb:us-east-1:333333333333:table/ table_name" ,
47+ table_name,
5048 KeysAndAttributes :: builder ( ) . keys ( kv) . build ( ) . unwrap ( ) ,
5149 )
5250 . send ( )
5351 . await
5452}
5553
5654#[ tokio:: test]
57- async fn account_id_should_be_included_in_request_uri ( ) {
58- // With the default `AccountIdEndpointMode::Preferred`
59- {
60- let ( client, rx) = test_client ( std:: convert:: identity) ;
61- let _ = call_operation ( client) . await ;
62- let req = rx. expect_request ( ) ;
63- assert_eq ! (
55+ async fn basic_positive_cases ( ) {
56+ let test_cases: & [ ( fn ( Builder ) -> Builder , & str , & str ) ] = & [
57+ (
58+ std:: convert:: identity,
59+ "arn:aws:dynamodb:us-east-1:333333333333:table/table_name" ,
6460 "https://333333333333.ddb.us-east-1.amazonaws.com/" ,
65- req. uri( )
66- )
67- }
68-
69- // With `AccountIdEndpointMode::Required`
70- {
71- let ( client, rx) =
72- test_client ( |b| b. account_id_endpoint_mode ( AccountIdEndpointMode :: Required ) ) ;
73- let _ = call_operation ( client) . await ;
74- let req = rx. expect_request ( ) ;
75- assert_eq ! (
61+ ) ,
62+ (
63+ std:: convert:: identity,
64+ "table_name" , // doesn't specify ARN for the table name
65+ "https://123456789012.ddb.us-east-1.amazonaws.com/" , // the account ID should come from credentials
66+ ) ,
67+ (
68+ |b : Builder | b. credentials_provider ( Credentials :: for_tests ( ) ) , // credentials do not provide an account ID
69+ "arn:aws:dynamodb:us-east-1:333333333333:table/table_name" ,
7670 "https://333333333333.ddb.us-east-1.amazonaws.com/" ,
77- req. uri( )
78- )
79- }
80- }
81-
82- #[ tokio:: test]
83- async fn account_id_should_not_be_included_in_request_uri ( ) {
84- // If we disable the account-based endpoints, the resulting URI should not include the account ID.
85- {
86- let ( client, rx) =
87- test_client ( |b| b. account_id_endpoint_mode ( AccountIdEndpointMode :: Disabled ) ) ;
88- let _ = call_operation ( client) . await ;
89- let req = rx. expect_request ( ) ;
90- assert_eq ! ( "https://dynamodb.us-east-1.amazonaws.com/" , req. uri( ) ) ;
91- }
71+ ) ,
72+ (
73+ |b : Builder | b. account_id_endpoint_mode ( AccountIdEndpointMode :: Preferred ) , // sets the default mode `Preferred` explicitly
74+ "arn:aws:dynamodb:us-east-1:333333333333:table/table_name" ,
75+ "https://333333333333.ddb.us-east-1.amazonaws.com/" ,
76+ ) ,
77+ (
78+ |b : Builder | b. account_id_endpoint_mode ( AccountIdEndpointMode :: Disabled ) ,
79+ "arn:aws:dynamodb:us-east-1:333333333333:table/table_name" ,
80+ "https://dynamodb.us-east-1.amazonaws.com/" ,
81+ ) ,
82+ (
83+ |b : Builder | b. account_id_endpoint_mode ( AccountIdEndpointMode :: Required ) ,
84+ "arn:aws:dynamodb:us-east-1:333333333333:table/table_name" ,
85+ "https://333333333333.ddb.us-east-1.amazonaws.com/" ,
86+ ) ,
87+ ] ;
9288
93- // If credentials do not include the account ID, neither should the resulting URI.
94- {
95- let ( client, rx) = test_client ( |b| b. credentials_provider ( Credentials :: for_tests ( ) ) ) ;
96- let _ = call_operation ( client) . await ;
89+ for ( i, ( update_builder, table_name, expected_uri) ) in test_cases. into_iter ( ) . enumerate ( ) {
90+ let ( client, rx) = test_client ( * update_builder) ;
91+ let _ = call_operation ( client, table_name) . await ;
9792 let req = rx. expect_request ( ) ;
98- assert_eq ! ( "https://dynamodb.us-east-1.amazonaws.com/" , req. uri( ) ) ;
93+ assert_eq ! (
94+ * expected_uri,
95+ req. uri( ) ,
96+ "on the {i}th test case where table name is `{table_name}`"
97+ ) ;
9998 }
10099}
101100
102101#[ tokio:: test]
103- async fn error_should_be_raised_when_account_id_is_expected_but_not_provided ( ) {
102+ async fn error_should_be_raised_when_account_id_is_expected_but_not_resolved ( ) {
104103 let ( client, _) = test_client ( |b| {
105104 b. account_id_endpoint_mode ( AccountIdEndpointMode :: Required )
106105 . credentials_provider ( Credentials :: for_tests ( ) )
107106 } ) ;
108- let err = call_operation ( client)
107+ // doesn't specify ARN for the table name
108+ let err = call_operation ( client, "table_name" )
109109 . await
110110 . err ( )
111111 . expect ( "request should fail" ) ;
0 commit comments