@@ -73,25 +73,43 @@ func TestNewS3ClientOptions(t *testing.T) {
7373 disableDualStack := false
7474
7575 tests := map [string ]struct {
76- s3Config common.CacheS3Config
77- expectedRegion string
78- expectedScheme string
79- usePathStyle bool
80- expectedAccelerate bool
81- expectedDualStack bool
82- expectedEndpoint string
76+ s3Config common.CacheS3Config
77+ expectedStaticCreds bool
78+ expectedRegion string
79+ expectedScheme string
80+ usePathStyle bool
81+ expectedAccelerate bool
82+ expectedDualStack bool
83+ expectedEndpoint string
8384 }{
8485 "s3-standard" : {
8586 s3Config : common.CacheS3Config {
8687 AccessKey : "test-access-key" ,
8788 SecretKey : "test-secret-key" ,
89+ ServerAddress : "s3.amazonaws.com" ,
8890 BucketName : "test-bucket" ,
8991 BucketLocation : "us-west-2" ,
9092 },
91- expectedRegion : "us-west-2" ,
92- expectedScheme : "https" ,
93- expectedEndpoint : "" ,
94- expectedDualStack : true ,
93+ expectedStaticCreds : true ,
94+ expectedRegion : "us-west-2" ,
95+ expectedScheme : "https" ,
96+ expectedEndpoint : "" ,
97+ expectedDualStack : true ,
98+ },
99+ "s3-standard-with-session-token" : {
100+ s3Config : common.CacheS3Config {
101+ AccessKey : "test-access-key" ,
102+ SecretKey : "test-secret-key" ,
103+ SessionToken : "test-session-token" ,
104+ ServerAddress : "s3.amazonaws.com" ,
105+ BucketName : "test-bucket" ,
106+ BucketLocation : "us-west-2" ,
107+ },
108+ expectedStaticCreds : true ,
109+ expectedRegion : "us-west-2" ,
110+ expectedScheme : "https" ,
111+ expectedEndpoint : "" ,
112+ expectedDualStack : true ,
95113 },
96114 "s3-standard-dual-stack" : {
97115 s3Config : common.CacheS3Config {
@@ -212,8 +230,19 @@ func TestNewS3ClientOptions(t *testing.T) {
212230 client , err := newS3Client (& tt .s3Config )
213231 require .NoError (t , err )
214232
215- clientOptions := client .(* s3Client ).client .Options ()
233+ s3Client := client .(* s3Client ).client
234+
235+ if tt .expectedStaticCreds {
236+ credsProvider := s3Client .Options ().Credentials
237+
238+ creds , err := credsProvider .Retrieve (t .Context ())
239+ require .NoError (t , err )
240+ require .Equal (t , tt .s3Config .AccessKey , creds .AccessKeyID )
241+ require .Equal (t , tt .s3Config .SecretKey , creds .SecretAccessKey )
242+ require .Equal (t , tt .s3Config .SessionToken , creds .SessionToken )
243+ }
216244
245+ clientOptions := s3Client .Options ()
217246 require .Equal (t , tt .expectedRegion , clientOptions .Region )
218247 require .Equal (t , tt .s3Config .Accelerate , clientOptions .UseAccelerate )
219248 require .Equal (t , tt .expectedDualStack , clientOptions .UseDualstack ) // nolint:staticcheck
0 commit comments