@@ -2088,7 +2088,7 @@ func TestEC2MetadataServiceEndpoint(t *testing.T) {
20882088 EnvironmentVariables map [string ]string
20892089 SharedConfigurationFile string
20902090 ExpectedEC2MetadataServiceEndpoint string
2091- ValidateDiags test. DiagsValidator
2091+ ExpectedDiags diag. Diagnostics
20922092 }{
20932093 "no configuration" : {
20942094 Config : & Config {
@@ -2126,10 +2126,12 @@ func TestEC2MetadataServiceEndpoint(t *testing.T) {
21262126 "AWS_METADATA_URL" : "https://127.0.0.1:1234" ,
21272127 },
21282128 ExpectedEC2MetadataServiceEndpoint : "https://127.0.0.1:1234" ,
2129- ValidateDiags : test .ExpectWarningDiagValidator (diag .NewWarningDiagnostic (
2130- "Deprecated Environment Variable" ,
2131- `The environment variable "AWS_METADATA_URL" is deprecated. Use "AWS_EC2_METADATA_SERVICE_ENDPOINT" instead.` ,
2132- )),
2129+ ExpectedDiags : diag.Diagnostics {
2130+ diag .NewWarningDiagnostic (
2131+ "Deprecated Environment Variable" ,
2132+ `The environment variable "AWS_METADATA_URL" is deprecated. Use "AWS_EC2_METADATA_SERVICE_ENDPOINT" instead.` ,
2133+ ),
2134+ },
21332135 },
21342136 "envvar overrides deprecated envvar" : {
21352137 Config : & Config {
@@ -2141,11 +2143,13 @@ func TestEC2MetadataServiceEndpoint(t *testing.T) {
21412143 "AWS_EC2_METADATA_SERVICE_ENDPOINT" : "https://127.0.0.1:1234" ,
21422144 },
21432145 ExpectedEC2MetadataServiceEndpoint : "https://127.0.0.1:1234" ,
2144- ValidateDiags : test .ExpectWarningDiagValidator (diag .NewWarningDiagnostic (
2145- "Deprecated Environment Variable" ,
2146- `The environment variable "AWS_METADATA_URL" is deprecated. Use "AWS_EC2_METADATA_SERVICE_ENDPOINT" instead.` + "\n " +
2147- `"AWS_EC2_METADATA_SERVICE_ENDPOINT" is set to "https://127.0.0.1:1234" and "AWS_METADATA_URL" is set to "https://127.1.1.1:1111". Ignoring "AWS_METADATA_URL".` ,
2148- )),
2146+ ExpectedDiags : diag.Diagnostics {
2147+ diag .NewWarningDiagnostic (
2148+ "Deprecated Environment Variable" ,
2149+ `The environment variable "AWS_METADATA_URL" is deprecated. Use "AWS_EC2_METADATA_SERVICE_ENDPOINT" instead.` + "\n " +
2150+ `"AWS_EC2_METADATA_SERVICE_ENDPOINT" is set to "https://127.0.0.1:1234" and "AWS_METADATA_URL" is set to "https://127.1.1.1:1111". Ignoring "AWS_METADATA_URL".` ,
2151+ ),
2152+ },
21492153 },
21502154
21512155 "shared configuration file" : {
@@ -2210,20 +2214,18 @@ ec2_metadata_service_endpoint = https://127.1.1.1:1111
22102214ec2_metadata_service_endpoint = https://127.1.1.1:1111
22112215` ,
22122216 ExpectedEC2MetadataServiceEndpoint : "https://127.0.0.1:1234" ,
2213- ValidateDiags : test .ExpectWarningDiagValidator (diag .NewWarningDiagnostic (
2214- "Deprecated Environment Variable" ,
2215- `The environment variable "AWS_METADATA_URL" is deprecated. Use "AWS_EC2_METADATA_SERVICE_ENDPOINT" instead.` ,
2216- )),
2217+ ExpectedDiags : diag.Diagnostics {
2218+ diag .NewWarningDiagnostic (
2219+ "Deprecated Environment Variable" ,
2220+ `The environment variable "AWS_METADATA_URL" is deprecated. Use "AWS_EC2_METADATA_SERVICE_ENDPOINT" instead.` ,
2221+ ),
2222+ },
22172223 },
22182224 }
22192225
22202226 for testName , testCase := range testCases {
22212227 testCase := testCase
22222228
2223- if testCase .ValidateDiags == nil {
2224- testCase .ValidateDiags = test .ExpectNoDiags
2225- }
2226-
22272229 t .Run (testName , func (t * testing.T ) {
22282230 servicemocks .InitSessionTestEnv (t )
22292231
@@ -2253,7 +2255,12 @@ ec2_metadata_service_endpoint = https://127.1.1.1:1111
22532255
22542256 _ , awsConfig , diags := GetAwsConfig (context .Background (), testCase .Config )
22552257
2256- testCase .ValidateDiags (t , diags )
2258+ if diff := cmp .Diff (diags , testCase .ExpectedDiags ); diff != "" {
2259+ t .Errorf ("Unexpected response (+wanted, -got): %s" , diff )
2260+ }
2261+ if diags .HasError () {
2262+ return
2263+ }
22572264
22582265 ec2MetadataServiceEndpoint , _ , err := awsconfig .ResolveEC2IMDSEndpointConfig (awsConfig .ConfigSources )
22592266 if err != nil {
@@ -2582,7 +2589,7 @@ func TestAssumeRole(t *testing.T) {
25822589 Config * Config
25832590 SharedConfigurationFile string
25842591 ExpectedCredentialsValue aws.Credentials
2585- ValidateDiags test. DiagsValidator
2592+ ExpectedDiags diag. Diagnostics
25862593 MockStsEndpoints []* servicemocks.MockEndpoint
25872594 }{
25882595 "config" : {
@@ -2682,22 +2689,18 @@ aws_secret_access_key = SharedConfigurationSourceSecretKey
26822689 SecretKey : servicemocks .MockStaticSecretKey ,
26832690 },
26842691 ExpectedCredentialsValue : mockdata .MockStsAssumeRoleCredentials ,
2685- ValidateDiags : test . ExpectDiagValidator ( `"role ARN not set" error` , func ( d diag.Diagnostic ) bool {
2686- return d . Equal ( diag .NewErrorDiagnostic (
2692+ ExpectedDiags : diag.Diagnostics {
2693+ diag .NewErrorDiagnostic (
26872694 "Cannot assume IAM Role" ,
26882695 "IAM Role ARN not set" ,
2689- ))
2690- }) ,
2696+ ),
2697+ },
26912698 },
26922699 }
26932700
26942701 for testName , testCase := range testCases {
26952702 testCase := testCase
26962703
2697- if testCase .ValidateDiags == nil {
2698- testCase .ValidateDiags = test .ExpectNoDiags
2699- }
2700-
27012704 t .Run (testName , func (t * testing.T ) {
27022705 servicemocks .InitSessionTestEnv (t )
27032706
@@ -2735,7 +2738,9 @@ aws_secret_access_key = SharedConfigurationSourceSecretKey
27352738
27362739 ctx , awsConfig , diags := GetAwsConfig (context .Background (), testCase .Config )
27372740
2738- testCase .ValidateDiags (t , diags )
2741+ if diff := cmp .Diff (diags , testCase .ExpectedDiags ); diff != "" {
2742+ t .Errorf ("Unexpected response (+wanted, -got): %s" , diff )
2743+ }
27392744 if diags .HasError () {
27402745 return
27412746 }
@@ -3053,7 +3058,6 @@ web_identity_token_file = no-such-file
30533058 if diff := cmp .Diff (diags , testCase .ExpectedDiags ); diff != "" {
30543059 t .Errorf ("Unexpected response (+wanted, -got): %s" , diff )
30553060 }
3056-
30573061 if diags .HasError () {
30583062 return
30593063 }
@@ -3201,7 +3205,7 @@ func TestGetAwsConfigWithAccountIDAndPartition(t *testing.T) {
32013205 expectedPartition string
32023206 expectError bool
32033207 mockStsEndpoints []* servicemocks.MockEndpoint
3204- ValidateDiags test. DiagsValidator
3208+ ExpectedDiags diag. Diagnostics
32053209 }{
32063210 {
32073211 desc : "StandardProvider_Config" ,
@@ -3259,10 +3263,6 @@ func TestGetAwsConfigWithAccountIDAndPartition(t *testing.T) {
32593263 for _ , testCase := range testCases {
32603264 tc := testCase
32613265
3262- if testCase .ValidateDiags == nil {
3263- testCase .ValidateDiags = test .ExpectNoDiags
3264- }
3265-
32663266 t .Run (tc .desc , func (t * testing.T ) {
32673267 ts := servicemocks .MockAwsApiServer ("STS" , tc .mockStsEndpoints )
32683268 defer ts .Close ()
@@ -3275,7 +3275,12 @@ func TestGetAwsConfigWithAccountIDAndPartition(t *testing.T) {
32753275
32763276 acctID , part , diags := GetAwsAccountIDAndPartition (ctx , awsConfig , tc .config )
32773277
3278- testCase .ValidateDiags (t , diags )
3278+ if diff := cmp .Diff (diags , testCase .ExpectedDiags ); diff != "" {
3279+ t .Errorf ("Unexpected response (+wanted, -got): %s" , diff )
3280+ }
3281+ if diags .HasError () {
3282+ return
3283+ }
32793284
32803285 if acctID != tc .expectedAcctID {
32813286 t .Errorf ("expected account ID (%s), got: %s" , tc .expectedAcctID , acctID )
0 commit comments