From 1320334a29e40bed63418a0e047aeff6089d4cc0 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Wed, 6 Mar 2024 13:52:23 -0500 Subject: [PATCH] dep: remove go-cmp usage from aws/ --- aws/credential_cache_test.go | 13 ++++++++++--- aws/defaults/defaults_test.go | 13 ++++++++++--- aws/middleware/user_agent_test.go | 17 ++++++++++++----- aws/retry/middleware_test.go | 10 ++++++++-- aws/signer/v4/middleware_test.go | 3 +-- aws/signer/v4/presign_middleware_test.go | 3 +-- aws/signer/v4/v4_test.go | 11 +++++++++-- 7 files changed, 51 insertions(+), 19 deletions(-) diff --git a/aws/credential_cache_test.go b/aws/credential_cache_test.go index 0c40fa6d48f..6bd30aba4f8 100644 --- a/aws/credential_cache_test.go +++ b/aws/credential_cache_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/rand" + "reflect" "strings" "sync" "sync/atomic" @@ -12,7 +13,6 @@ import ( sdkrand "github.com/aws/aws-sdk-go-v2/internal/rand" "github.com/aws/aws-sdk-go-v2/internal/sdk" - "github.com/google/go-cmp/cmp" ) type stubCredentialsProvider struct { @@ -543,7 +543,7 @@ func TestCredentialsCache_cacheStrategies(t *testing.T) { // Truncate expires time so its easy to compare creds.Expires = creds.Expires.Truncate(time.Second) - if diff := cmp.Diff(c.expectCreds, creds); diff != "" { + if diff := cmpDiff(c.expectCreds, creds); diff != "" { t.Errorf("expect creds match\n%s", diff) } }) @@ -611,7 +611,7 @@ func (m mockAdjustExpiryBy) AdjustExpiresBy(creds Credentials, dur time.Duration Credentials, error, ) { if m.expectInputCreds.HasKeys() { - if diff := cmp.Diff(m.expectInputCreds, creds); diff != "" { + if diff := cmpDiff(m.expectInputCreds, creds); diff != "" { return Credentials{}, fmt.Errorf("expect creds match\n%s", diff) } } @@ -660,3 +660,10 @@ func TestCredentialsCache_IsCredentialsProvider(t *testing.T) { } var _ isCredentialsProvider = (*CredentialsCache)(nil) + +func cmpDiff(e, a interface{}) string { + if !reflect.DeepEqual(e, a) { + return fmt.Sprintf("%v != %v", e, a) + } + return "" +} diff --git a/aws/defaults/defaults_test.go b/aws/defaults/defaults_test.go index 7eb37f1f537..2483cdae751 100644 --- a/aws/defaults/defaults_test.go +++ b/aws/defaults/defaults_test.go @@ -1,13 +1,13 @@ package defaults import ( + "fmt" + "reflect" "strconv" "testing" "time" "github.com/aws/aws-sdk-go-v2/aws" - - "github.com/google/go-cmp/cmp" ) func TestConfigV1(t *testing.T) { @@ -55,9 +55,16 @@ func TestConfigV1(t *testing.T) { if err != nil { t.Fatalf("expect no error, got %v", err) } - if diff := cmp.Diff(tt.Expected, got); len(diff) > 0 { + if diff := cmpDiff(tt.Expected, got); len(diff) > 0 { t.Error(diff) } }) } } + +func cmpDiff(e, a interface{}) string { + if !reflect.DeepEqual(e, a) { + return fmt.Sprintf("%v != %v", e, a) + } + return "" +} diff --git a/aws/middleware/user_agent_test.go b/aws/middleware/user_agent_test.go index 85e8a117878..a446f5366a9 100644 --- a/aws/middleware/user_agent_test.go +++ b/aws/middleware/user_agent_test.go @@ -2,8 +2,10 @@ package middleware import ( "context" + "fmt" "net/http" "os" + "reflect" "runtime" "strings" "testing" @@ -11,8 +13,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" ) var expectedAgent = aws.SDKName + "/" + aws.SDKVersion + " os/" + getNormalizedOSName() + " lang/go#" + languageVersion + " md/GOOS#" + runtime.GOOS + " md/GOARCH#" + runtime.GOARCH @@ -37,7 +37,7 @@ func TestRequestUserAgent_HandleBuild(t *testing.T) { }}, Next: func(t *testing.T, expect middleware.BuildInput) middleware.BuildHandler { return middleware.BuildHandlerFunc(func(ctx context.Context, input middleware.BuildInput) (o middleware.BuildOutput, m middleware.Metadata, err error) { - if diff := cmp.Diff(input, expect, cmpopts.IgnoreUnexported(http.Request{}, smithyhttp.Request{})); len(diff) > 0 { + if diff := cmpDiff(input, expect); len(diff) > 0 { t.Error(diff) } return o, m, err @@ -59,7 +59,7 @@ func TestRequestUserAgent_HandleBuild(t *testing.T) { }}, Next: func(t *testing.T, expect middleware.BuildInput) middleware.BuildHandler { return middleware.BuildHandlerFunc(func(ctx context.Context, input middleware.BuildInput) (o middleware.BuildOutput, m middleware.Metadata, err error) { - if diff := cmp.Diff(input, expect, cmpopts.IgnoreUnexported(http.Request{}, smithyhttp.Request{})); len(diff) > 0 { + if diff := cmpDiff(input, expect); len(diff) > 0 { t.Error(diff) } return o, m, err @@ -81,7 +81,7 @@ func TestRequestUserAgent_HandleBuild(t *testing.T) { }}, Next: func(t *testing.T, expect middleware.BuildInput) middleware.BuildHandler { return middleware.BuildHandlerFunc(func(ctx context.Context, input middleware.BuildInput) (o middleware.BuildOutput, m middleware.Metadata, err error) { - if diff := cmp.Diff(input, expect, cmpopts.IgnoreUnexported(http.Request{}, smithyhttp.Request{})); len(diff) > 0 { + if diff := cmpDiff(input, expect); len(diff) > 0 { t.Error(diff) } return o, m, err @@ -436,3 +436,10 @@ func TestAddUserAgentKeyValue_AddToStack(t *testing.T) { }) } } + +func cmpDiff(e, a interface{}) string { + if !reflect.DeepEqual(e, a) { + return fmt.Sprintf("%v != %v", e, a) + } + return "" +} diff --git a/aws/retry/middleware_test.go b/aws/retry/middleware_test.go index 28b3f386786..f4186b29d6b 100644 --- a/aws/retry/middleware_test.go +++ b/aws/retry/middleware_test.go @@ -15,7 +15,6 @@ import ( "github.com/aws/aws-sdk-go-v2/internal/sdk" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" - "github.com/google/go-cmp/cmp" ) func TestMetricsHeaderMiddleware(t *testing.T) { @@ -427,7 +426,7 @@ func TestAttemptMiddleware(t *testing.T) { t.Errorf("expect %v, got %v", tt.Err, err) } } - if diff := cmp.Diff(recorded, tt.Expect); len(diff) > 0 { + if diff := cmpDiff(recorded, tt.Expect); len(diff) > 0 { t.Error(diff) } @@ -493,3 +492,10 @@ type mockRawResponseKey struct{} func setMockRawResponse(m *middleware.Metadata, v interface{}) { m.Set(mockRawResponseKey{}, v) } + +func cmpDiff(e, a interface{}) string { + if !reflect.DeepEqual(e, a) { + return fmt.Sprintf("%v != %v", e, a) + } + return "" +} diff --git a/aws/signer/v4/middleware_test.go b/aws/signer/v4/middleware_test.go index f7c80e67a2a..9b56ecefda5 100644 --- a/aws/signer/v4/middleware_test.go +++ b/aws/signer/v4/middleware_test.go @@ -19,7 +19,6 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" - "github.com/google/go-cmp/cmp" ) func TestComputePayloadHashMiddleware(t *testing.T) { @@ -303,7 +302,7 @@ func TestSwapComputePayloadSHA256ForUnsignedPayloadMiddleware(t *testing.T) { t.Fatalf("expect no error, got %v", err) } - if diff := cmp.Diff(c.ExpectIDs, stack.Finalize.List()); len(diff) != 0 { + if diff := cmpDiff(c.ExpectIDs, stack.Finalize.List()); len(diff) != 0 { t.Errorf("expect match\n%v", diff) } }) diff --git a/aws/signer/v4/presign_middleware_test.go b/aws/signer/v4/presign_middleware_test.go index a037ce772db..05c50b241b8 100644 --- a/aws/signer/v4/presign_middleware_test.go +++ b/aws/signer/v4/presign_middleware_test.go @@ -15,7 +15,6 @@ import ( "github.com/aws/smithy-go/logging" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" - "github.com/google/go-cmp/cmp" ) type httpPresignerFunc func( @@ -202,7 +201,7 @@ func TestPresignHTTPRequestMiddleware(t *testing.T) { t.Fatalf("expect no error, got %v", err) } - if diff := cmp.Diff(c.ExpectResult, result.Result); len(diff) != 0 { + if diff := cmpDiff(c.ExpectResult, result.Result); len(diff) != 0 { t.Errorf("expect result match\n%v", diff) } diff --git a/aws/signer/v4/v4_test.go b/aws/signer/v4/v4_test.go index bd69644bb5c..44bfe86a145 100644 --- a/aws/signer/v4/v4_test.go +++ b/aws/signer/v4/v4_test.go @@ -10,13 +10,13 @@ import ( "io/ioutil" "net/http" "net/url" + "reflect" "strings" "testing" "time" "github.com/aws/aws-sdk-go-v2/aws" v4Internal "github.com/aws/aws-sdk-go-v2/aws/signer/internal/v4" - "github.com/google/go-cmp/cmp" ) var testCredentials = aws.Credentials{AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "SESSION"} @@ -329,7 +329,7 @@ func TestSign_buildCanonicalHeaders(t *testing.T) { `fooinnerspace;fooleadingspace;foomultiplespace;foonospace;footabspace;footrailingspace;foowrappedspace;host;x-amz-date`, ``, }, "\n") - if diff := cmp.Diff(expectCanonicalString, build.CanonicalString); diff != "" { + if diff := cmpDiff(expectCanonicalString, build.CanonicalString); diff != "" { t.Errorf("expect match, got\n%s", diff) } } @@ -354,3 +354,10 @@ func BenchmarkSignRequest(b *testing.B) { signer.SignHTTP(context.Background(), testCredentials, req, bodyHash, "dynamodb", "us-east-1", time.Now()) } } + +func cmpDiff(e, a interface{}) string { + if !reflect.DeepEqual(e, a) { + return fmt.Sprintf("%v != %v", e, a) + } + return "" +}