From a3c5f3f04eda8efddfa0c740b470e1539d6dc8ba Mon Sep 17 00:00:00 2001 From: AWS Gopher Date: Fri, 22 Aug 2025 10:34:07 -0400 Subject: [PATCH 1/2] test: Update integration test for go1.23 - Add `testContext(*testing.T) context.Context` in `./test` package, with version-specific implementations matching `package unstructured` - Add `randText() string` in `./test` package. Version-specific implmentation for go1.24 and later delegates to `crypto/rand.Text`, while the implementation for go1.23 simply copies the body of `crypto/rand.Text` into a local implementation. --- test/context_new_test.go | 18 ++++++++++++++++++ test/context_old_test.go | 27 +++++++++++++++++++++++++++ test/destination_test.go | 3 +-- test/source_test.go | 3 +-- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 test/context_new_test.go create mode 100644 test/context_old_test.go diff --git a/test/context_new_test.go b/test/context_new_test.go new file mode 100644 index 0000000..acb5721 --- /dev/null +++ b/test/context_new_test.go @@ -0,0 +1,18 @@ +//go:build go1.24 && integration + +package test + +import ( + "context" + "crypto/rand" + "testing" +) + +// textContext mimics [*testing.T.Context], which was added in go1.24. +func testContext(t *testing.T) context.Context { + return t.Context() +} + +func randText() string { + return rand.Text() +} diff --git a/test/context_old_test.go b/test/context_old_test.go new file mode 100644 index 0000000..5eb83e2 --- /dev/null +++ b/test/context_old_test.go @@ -0,0 +1,27 @@ +//go:build !go1.24 && integration + +package test + +import ( + "context" + "crypto/rand" + "testing" +) + +// textContext mimics [*testing.T.Context], which was added in go1.24. +func testContext(t *testing.T) context.Context { + t.Helper() + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + return ctx +} + +func randText() string { + const base32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" + src := make([]byte, 26) + rand.Read(src) + for i := range src { + src[i] = base32[src[i]%32] + } + return string(src) +} diff --git a/test/destination_test.go b/test/destination_test.go index f79f5a1..f9cdb92 100644 --- a/test/destination_test.go +++ b/test/destination_test.go @@ -4,7 +4,6 @@ package test import ( "context" - "crypto/rand" "fmt" "os" "testing" @@ -201,7 +200,7 @@ func TestDestinationPermutations(t *testing.T) { t.Parallel() destination, err := client.CreateDestination(testContext(t), unstructured.CreateDestinationRequest{ - Name: fmt.Sprintf("test-%s-%s", name, rand.Text()), + Name: fmt.Sprintf("test-%s-%s", name, randText()), Config: src, }) if err != nil { diff --git a/test/source_test.go b/test/source_test.go index 4636879..88855ef 100644 --- a/test/source_test.go +++ b/test/source_test.go @@ -4,7 +4,6 @@ package test import ( "context" - "crypto/rand" "fmt" "os" "testing" @@ -187,7 +186,7 @@ func TestSourcePermutations(t *testing.T) { t.Parallel() source, err := client.CreateSource(testContext(t), unstructured.CreateSourceRequest{ - Name: fmt.Sprintf("test-%s-%s", name, rand.Text()), + Name: fmt.Sprintf("test-%s-%s", name, randText()), Config: src, }) if err != nil { From eea9a0b345d4b5848d57d9b0e5e04cbe183a21bd Mon Sep 17 00:00:00 2001 From: AWS Gopher Date: Fri, 22 Aug 2025 10:34:33 -0400 Subject: [PATCH 2/2] test: run integration test with API key after local tests. --- .github/workflows/ci.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b4366d2..ab035f9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,4 +24,7 @@ jobs: - run: go vet ./... - uses: dominikh/staticcheck-action@v1 with: { install-go: false } - - run: go test -v ./... \ No newline at end of file + - run: go test -v . + - run: go test -v -tags integration ./test + env: + UNSTRUCTURED_API_KEY: ${{ secrets.UNSTRUCTURED_API_KEY }} \ No newline at end of file