Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump min go to 1.20 and remove 95% of the go-cmp dependency #499

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/5974e1d2ba434e1fba73f9632f9b1063.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "5974e1d2-ba43-4e1f-ba73-f9632f9b1063",
"type": "feature",
"description": "Bump minimum Go version to 1.20 per our language support policy.",
"modules": [
"."
]
}
2 changes: 1 addition & 1 deletion .github/workflows/api_diff_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
go-version: "1.20"
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
go-version: [1.19]
go-version: ["1.20"]
env:
JAVA_TOOL_OPTIONS: "-Xmx2g"
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ["1.19", "1.20", "1.21"]
go-version: ["1.20", "1.21", "1.22"]
steps:
- uses: actions/checkout@v2

Expand Down
17 changes: 8 additions & 9 deletions auth/bearer/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package bearer

import (
"context"
"net/http"
"net/url"
"reflect"
"strings"
"testing"

smithyhttp "github.com/aws/smithy-go/transport/http"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

func TestSignHTTPSMessage(t *testing.T) {
Expand Down Expand Up @@ -65,13 +63,14 @@ func TestSignHTTPSMessage(t *testing.T) {
t.Fatalf("expect no error, got %v", err)
}

options := []cmp.Option{
cmpopts.IgnoreUnexported(smithyhttp.Request{}),
cmpopts.IgnoreUnexported(http.Request{}),
}
expect := c.expectMessage.(*smithyhttp.Request)

if diff := cmp.Diff(c.expectMessage, message, options...); diff != "" {
t.Errorf("expect match\n%s", diff)
actual, ok := message.(*smithyhttp.Request)
if !ok {
t.Fatalf("*smithyhttp.Request != %T", actual)
}
if !reflect.DeepEqual(expect.Header, actual.Header) {
t.Errorf("%v != %v", expect.Header, actual.Header)
}
})
}
Expand Down
71 changes: 35 additions & 36 deletions auth/bearer/token_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"sync/atomic"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)

var _ TokenProvider = (*TokenCache)(nil)
Expand All @@ -33,17 +31,17 @@ func TestTokenCache_cache(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}

for i := 0; i < 100; i++ {
token, err := provider.RetrieveBearerToken(context.Background())
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
}
}
Expand All @@ -66,8 +64,8 @@ func TestTokenCache_cacheConcurrent(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}

for i := 0; i < 100; i++ {
Expand All @@ -78,8 +76,8 @@ func TestTokenCache_cacheConcurrent(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
})
}
Expand Down Expand Up @@ -115,8 +113,8 @@ func TestTokenCache_expired(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
}
if e, a := 1, int(atomic.LoadInt32(retrievedCount)); e != a {
Expand All @@ -132,8 +130,8 @@ func TestTokenCache_expired(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(refreshedToken, token); diff != "" {
t.Errorf("expect refreshed token match\n%s", diff)
if refreshedToken != token {
t.Errorf("expect refreshed token match: %v != %v", refreshedToken, token)
}
if e, a := 2, int(atomic.LoadInt32(retrievedCount)); e != a {
t.Errorf("expect %v provider calls, got %v", e, a)
Expand Down Expand Up @@ -192,8 +190,9 @@ func TestTokenCache_cancelled(t *testing.T) {
if err != nil {
t.Errorf("expect no error, got %v", err)
} else {
if diff := cmp.Diff(Token{Value: "abc123"}, token); diff != "" {
t.Errorf("expect token retrieve match\n%s", diff)
expect := Token{Value: "abc123"}
if expect != token {
t.Errorf("expect token retrieve match: %v != %v", expect, token)
}
}
}()
Expand Down Expand Up @@ -284,8 +283,8 @@ func TestTokenCache_asyncRefresh(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}

// 2-5: Offset time for subsequent calls to retrieve to trigger asynchronous
Expand All @@ -299,8 +298,8 @@ func TestTokenCache_asyncRefresh(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
}
// Wait for all async refreshes to complete
Expand All @@ -317,8 +316,8 @@ func TestTokenCache_asyncRefresh(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
testWaitAsyncRefreshDone(provider)
}
Expand All @@ -329,8 +328,8 @@ func TestTokenCache_asyncRefresh(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(refreshedToken, token); diff != "" {
t.Errorf("expect refreshed token match\n%s", diff)
if refreshedToken != token {
t.Errorf("expect refreshed token match: %v != %v", refreshedToken, token)
}
}

Expand Down Expand Up @@ -374,8 +373,8 @@ func TestTokenCache_asyncRefreshWithMinDelay(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}

// 2-5: Offset time for subsequent calls to retrieve to trigger asynchronous
Expand All @@ -389,8 +388,8 @@ func TestTokenCache_asyncRefreshWithMinDelay(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
// Wait for all async refreshes to complete ensure not deduped
testWaitAsyncRefreshDone(provider)
Expand All @@ -411,8 +410,8 @@ func TestTokenCache_asyncRefreshWithMinDelay(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}
// Wait for all async refreshes to complete ensure not deduped
testWaitAsyncRefreshDone(provider)
Expand All @@ -423,8 +422,8 @@ func TestTokenCache_asyncRefreshWithMinDelay(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(refreshedToken, token); diff != "" {
t.Errorf("expect refreshed token match\n%s", diff)
if refreshedToken != token {
t.Errorf("expect refreshed token match: %v != %v", refreshedToken, token)
}
}

Expand Down Expand Up @@ -468,8 +467,8 @@ func TestTokenCache_disableAsyncRefresh(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(expectToken, token); diff != "" {
t.Errorf("expect token match\n%s", diff)
if expectToken != token {
t.Errorf("expect token match: %v != %v", expectToken, token)
}

// Update time into refresh window before token expires
Expand Down Expand Up @@ -499,8 +498,8 @@ func TestTokenCache_disableAsyncRefresh(t *testing.T) {
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if diff := cmp.Diff(refreshedToken, token); diff != "" {
t.Errorf("expect refreshed token match\n%s", diff)
if refreshedToken != token {
t.Errorf("expect refreshed token match: %v != %v", refreshedToken, token)
}
}

Expand Down
15 changes: 6 additions & 9 deletions document/json/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package json_test

import (
"math/big"
"reflect"
"testing"
"time"

"github.com/aws/smithy-go/document"
"github.com/aws/smithy-go/document/internal/serde"
"github.com/aws/smithy-go/document/json"
"github.com/google/go-cmp/cmp"
)

var decodeArrayTestCases = map[string]testCase{
Expand Down Expand Up @@ -153,14 +153,11 @@ func testDecodeJSONInterface(t *testing.T, tt testCase) {
if err := d.DecodeJSONInterface(MustJSONUnmarshal(tt.json, !tt.disableJSONNumber), tt.actual); (err != nil) != tt.wantErr {
t.Errorf("DecodeJSONInterface() error = %v, wantErr %v", err, tt.wantErr)
}
if diff := cmp.Diff(
serde.PtrToValue(tt.want),
serde.PtrToValue(tt.actual),
cmp.AllowUnexported(StructA{}, StructB{}),
cmp.Comparer(cmpBigFloat()),
cmp.Comparer(cmpBigInt()),
); len(diff) > 0 {
t.Error(diff)

expect := serde.PtrToValue(tt.want)
actual := serde.PtrToValue(tt.actual)
if !reflect.DeepEqual(expect, actual) {
t.Errorf("%v != %v", expect, actual)
}
}

Expand Down
19 changes: 7 additions & 12 deletions document/json/encoder_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package json_test

import (
"github.com/aws/smithy-go/document"
"github.com/aws/smithy-go/document/internal/serde"
"github.com/aws/smithy-go/document/json"
"github.com/google/go-cmp/cmp"
"reflect"
"testing"
"time"

"github.com/aws/smithy-go/document"
"github.com/aws/smithy-go/document/json"
)

func TestEncoder_Encode(t *testing.T) {
Expand Down Expand Up @@ -79,15 +79,10 @@ func testEncode(t *testing.T, tt testCase) {
t.Errorf("Encode() error = %v, wantErr %v", err, tt.wantErr)
}

expect := MustJSONUnmarshal(tt.json, !tt.disableJSONNumber)
got := MustJSONUnmarshal(encodeBytes, !tt.disableJSONNumber)

if diff := cmp.Diff(
serde.PtrToValue(MustJSONUnmarshal(tt.json, !tt.disableJSONNumber)),
serde.PtrToValue(got),
cmp.AllowUnexported(StructA{}, StructB{}),
cmp.Comparer(cmpBigFloat()),
cmp.Comparer(cmpBigInt()),
); len(diff) > 0 {
t.Error(diff)
if !reflect.DeepEqual(expect, got) {
t.Errorf("%v != %v", expect, got)
}
}
4 changes: 3 additions & 1 deletion document/json/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ var sharedNumberTestCases = map[string]testCase{
return &x
}(),
want: func() *big.Float {
return big.NewFloat(math.MaxFloat64)
// this is slightly different than big.NewFloat(math.MaxFloat64)
x, _ := (&big.Float{}).SetString(strconv.FormatFloat(math.MaxFloat64, 'e', -1, 64))
return x
}(),
},
"float64 to big.Float": {
Expand Down
Loading
Loading