Skip to content

Commit

Permalink
dep: remove go-cmp usage from aws/
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Mar 6, 2024
1 parent bd15f86 commit 1320334
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
13 changes: 10 additions & 3 deletions aws/credential_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"reflect"
"strings"
"sync"
"sync/atomic"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 ""
}
13 changes: 10 additions & 3 deletions aws/defaults/defaults_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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 ""
}
17 changes: 12 additions & 5 deletions aws/middleware/user_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package middleware

import (
"context"
"fmt"
"net/http"
"os"
"reflect"
"runtime"
"strings"
"testing"

"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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ""
}
10 changes: 8 additions & 2 deletions aws/retry/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 ""
}
3 changes: 1 addition & 2 deletions aws/signer/v4/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
})
Expand Down
3 changes: 1 addition & 2 deletions aws/signer/v4/presign_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}

Expand Down
11 changes: 9 additions & 2 deletions aws/signer/v4/v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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 ""
}

0 comments on commit 1320334

Please sign in to comment.