diff --git a/.circleci/config.yml b/.circleci/config.yml index 6d07033..9564c7f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ orbs: executors: default: docker: - - image: cimg/go:1.21.1 + - image: cimg/go:1.24.5 # Define the jobs we want to run for this project jobs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70e04e7..96f50a5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,7 @@ jobs: with: token: ${{ github.token }} branch: main + noVersionBumpBehavior: patch - name: Create tag run: git tag ${{ steps.semver.outputs.next }} diff --git a/.golangci.yaml b/.golangci.yaml index 590d614..2b3f961 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,13 +3,6 @@ run: - integration concurrency: 4 issues-exit-code: 1 - skip-dirs: - - "licenses" - - "pact" - - ".bin" - - ".github" - - ".vscode" - - "build" tests: true timeout: 5m @@ -38,7 +31,6 @@ linters-settings: gosimple: checks: ['all'] govet: - check-shadowing: true enable-all: true disable: - fieldalignment @@ -110,7 +102,7 @@ linters: # TODO(errorlint): revisit #- errorlint - exhaustive - - exportloopref + - copyloopvar # TODO(forbidigo): revisit #- forbidigo # TODO(forcetypeassert): revisit this one! beware fragile asserts in this codebase @@ -157,7 +149,6 @@ linters: # TODO(stylecheck): revisit in a followup; some breaking API changes #- stylecheck # NOTE: removed tagliatelle as it conflicts too much with existing API wireformats - - tenv # TODO(testpackage): improve open vs closed-box testing in a followup #- testpackage - thelper @@ -166,12 +157,21 @@ linters: # TODO(unparam): revisit #- unparam - usestdlibvars + - usetesting - wastedassign - whitespace # TODO(wrapcheck): wrap errors in a followup #- wrapcheck issues: + exclude-dirs: + - "licenses" + - "pact" + - ".bin" + - ".github" + - ".vscode" + - "build" + exclude-rules: - path: _test\.go linters: diff --git a/Makefile b/Makefile index b58b8ea..7397a33 100644 --- a/Makefile +++ b/Makefile @@ -4,14 +4,17 @@ GOARCH = $(shell go env GOARCH) TOOLS_BIN := $(shell pwd)/.bin -OVERRIDE_GOCI_LINT_V := v1.60.1 +OVERRIDE_GOCI_LINT_V := v1.64.8 +GOCI_LINT_TARGETS := $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/.golangci-lint_$(OVERRIDE_GOCI_LINT_V) SHELL:=env PATH=$(TOOLS_BIN)/go:$(TOOLS_BIN)/pact/bin:$(PATH) $(SHELL) ## tools: Install required tooling. .PHONY: tools -tools: $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/go -$(TOOLS_BIN)/golangci-lint: - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(OVERRIDE_GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN)/ $(OVERRIDE_GOCI_LINT_V) +tools: $(GOCI_LINT_TARGETS) $(TOOLS_BIN)/go +$(GOCI_LINT_TARGETS): + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(OVERRIDE_GOCI_LINT_V)/install.sh | sh -s -- -b $(TOOLS_BIN) $(OVERRIDE_GOCI_LINT_V) + @rm -f $(TOOLS_BIN)/.golangci-lint_* + @touch $(TOOLS_BIN)/.golangci-lint_$(OVERRIDE_GOCI_LINT_V) $(TOOLS_BIN)/pact-broker: @cd $(TOOLS_BIN); curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=v2.4.4 bash; cd ../ @@ -22,17 +25,17 @@ $(TOOLS_BIN)/go: @GOBIN=${TOOLS_BIN}/go ${TOOLS_BIN}/go/pact-go -l DEBUG install -d /tmp .PHONY: format -format: +format: $(GOCI_LINT_TARGETS) @gofmt -w -l -e . - @$(TOOLS_BIN)/golangci-lint run --fix -v ./... + @$(TOOLS_BIN)/golangci-lint run --fix ./... .PHONY: lint -lint: $(TOOLS_BIN)/golangci-lint +lint: $(GOCI_LINT_TARGETS) ifdef CI mkdir -p test/results @$(TOOLS_BIN)/golangci-lint run --out-format junit-xml ./... > test/results/lint-tests.xml else - @$(TOOLS_BIN)/golangci-lint run -v ./... + @$(TOOLS_BIN)/golangci-lint run ./... endif .PHONY: build @@ -45,6 +48,7 @@ clean: @echo "Cleaning up..." @GOOS=$(GOOS) GOARCH=$(GOARCH) go clean -testcache @rm -rf $(TOOLS_BIN) + @rm -f /tmp/libpact_ffi.* .PHONY: test test: diff --git a/bundle/bundle_manager_test.go b/bundle/bundle_manager_test.go index 54fbcd6..8ab0124 100644 --- a/bundle/bundle_manager_test.go +++ b/bundle/bundle_manager_test.go @@ -18,7 +18,6 @@ package bundle_test import ( "bytes" - "context" "os" "path/filepath" "strings" @@ -69,7 +68,7 @@ func Test_Create(t *testing.T) { require.NoError(t, err) var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", dir, sliceToChannel([]string{file}), @@ -109,7 +108,7 @@ func Test_Create(t *testing.T) { require.NoError(t, err) var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", dir, sliceToChannel([]string{file}), @@ -153,7 +152,7 @@ func Test_Create(t *testing.T) { require.NoError(t, err) var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", dir, sliceToChannel([]string{file}), @@ -196,7 +195,7 @@ func Test_Create(t *testing.T) { ) require.NoError(t, err) var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", dir, sliceToChannel([]string{file}), @@ -234,7 +233,7 @@ func Test_Create(t *testing.T) { assert.Nil(t, err) var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", tempDir, sliceToChannel([]string{file}), @@ -287,7 +286,7 @@ func Test_Create(t *testing.T) { } var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", tempDir, sliceToChannel(filesFullPaths), @@ -340,7 +339,7 @@ func Test_Create(t *testing.T) { } var bundleManager = bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) - bundle, err := bundleManager.Create(context.Background(), + bundle, err := bundleManager.Create(t.Context(), "testRequestId", tempDir, sliceToChannel(filesFullPaths), @@ -391,7 +390,7 @@ func Test_Upload(t *testing.T) { bundleFileMap[documentURI] = bundleFile _, err := bundleManager.Upload( - context.Background(), + t.Context(), "testRequestId", bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &logger, "rootPath", "bundleHash", bundleFileMap, []string{}, []string{documentURI}), bundleFileMap) @@ -440,7 +439,7 @@ func Test_Upload(t *testing.T) { missingFiles = append(missingFiles, path) _, err := bundleManager.Upload( - context.Background(), + t.Context(), "testRequestId", bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &logger, "rootPath", "bundleHash", bundleFileMap, []string{}, missingFiles), bundleFileMap) @@ -470,19 +469,19 @@ func Test_IsSupported_Extensions(t *testing.T) { bundler := bundle.NewBundleManager(mockSnykCodeClient, newLogger(t), mockInstrumentor, mockErrorReporter, mockTrackerFactory) t.Run("should return true for supported languages", func(t *testing.T) { - supported, _ := bundler.IsSupported(context.Background(), "C:\\some\\path\\Test.java") + supported, _ := bundler.IsSupported(t.Context(), "C:\\some\\path\\Test.java") assert.True(t, supported) }) t.Run("should return false for unsupported languages", func(t *testing.T) { - supported, _ := bundler.IsSupported(context.Background(), "C:\\some\\path\\Test.rs") + supported, _ := bundler.IsSupported(t.Context(), "C:\\some\\path\\Test.rs") assert.False(t, supported) }) t.Run("should cache supported extensions", func(t *testing.T) { path := "C:\\some\\path\\Test.rs" - _, _ = bundler.IsSupported(context.Background(), path) - _, _ = bundler.IsSupported(context.Background(), path) + _, _ = bundler.IsSupported(t.Context(), path) + _, _ = bundler.IsSupported(t.Context(), path) }) } @@ -514,34 +513,33 @@ func Test_IsSupported_ConfigFiles(t *testing.T) { t.Run("should return true for supported config files", func(t *testing.T) { for _, file := range expectedConfigFiles { path := filepath.Join(dir, file) - supported, _ := bundler.IsSupported(context.Background(), path) + supported, _ := bundler.IsSupported(t.Context(), path) assert.True(t, supported) } }) t.Run("should exclude .gitignore and .dcignore", func(t *testing.T) { for _, file := range []string{".gitignore", ".dcignore"} { path := filepath.Join(dir, file) - supported, _ := bundler.IsSupported(context.Background(), path) + supported, _ := bundler.IsSupported(t.Context(), path) assert.False(t, supported) } }) t.Run("should return false for unsupported config files", func(t *testing.T) { path := "C:\\some\\path\\.unsupported" - supported, _ := bundler.IsSupported(context.Background(), path) + supported, _ := bundler.IsSupported(t.Context(), path) assert.False(t, supported) }) t.Run("should cache supported extensions", func(t *testing.T) { path := "C:\\some\\path\\Test.rs" - _, _ = bundler.IsSupported(context.Background(), path) - _, _ = bundler.IsSupported(context.Background(), path) + _, _ = bundler.IsSupported(t.Context(), path) + _, _ = bundler.IsSupported(t.Context(), path) }) } func setup(t *testing.T) string { t.Helper() - dir, err := os.MkdirTemp("", "createFileOfSize") - require.NoError(t, err) + dir := t.TempDir() return dir } diff --git a/bundle/bundle_test.go b/bundle/bundle_test.go index 9d2aa69..19daddc 100644 --- a/bundle/bundle_test.go +++ b/bundle/bundle_test.go @@ -18,11 +18,9 @@ package bundle_test import ( "bytes" - "context" "crypto/sha256" "encoding/hex" "fmt" - "golang.org/x/net/html/charset" "io" "os" "testing" @@ -31,6 +29,7 @@ import ( "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "golang.org/x/net/html/charset" "github.com/snyk/code-client-go/bundle" "github.com/snyk/code-client-go/internal/deepcode" @@ -83,7 +82,7 @@ func Test_UploadBatch(t *testing.T) { b := bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &testLogger, "testRootPath", "testBundleHash", map[string]deepcode.BundleFile{}, []string{}, []string{}) emptyBundle := &bundle.Batch{} - err := b.UploadBatch(context.Background(), "testRequestId", emptyBundle) + err := b.UploadBatch(t.Context(), "testRequestId", emptyBundle) assert.NoError(t, err) }) @@ -102,7 +101,7 @@ func Test_UploadBatch(t *testing.T) { mockErrorReporter := mocks.NewMockErrorReporter(ctrl) b := bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &testLogger, "testRootPath", "testBundleHash", map[string]deepcode.BundleFile{}, []string{}, []string{}) - err := b.UploadBatch(context.Background(), "testRequestId", bundleWithFiles) + err := b.UploadBatch(t.Context(), "testRequestId", bundleWithFiles) assert.NoError(t, err) }) @@ -125,10 +124,10 @@ func Test_UploadBatch(t *testing.T) { mockErrorReporter := mocks.NewMockErrorReporter(ctrl) b := bundle.NewBundle(mockSnykCodeClient, mockInstrumentor, mockErrorReporter, &testLogger, "testRootPath", "testBundleHash", map[string]deepcode.BundleFile{}, []string{}, []string{}) - err := b.UploadBatch(context.Background(), "testRequestId", bundleWithFiles) + err := b.UploadBatch(t.Context(), "testRequestId", bundleWithFiles) require.NoError(t, err) oldHash := b.GetBundleHash() - err = b.UploadBatch(context.Background(), "testRequestId", bundleWithMultipleFiles) + err = b.UploadBatch(t.Context(), "testRequestId", bundleWithMultipleFiles) require.NoError(t, err) newHash := b.GetBundleHash() assert.NotEqual(t, oldHash, newHash) @@ -153,7 +152,7 @@ func Test_RawContentBatch(t *testing.T) { require.NoError(t, batchErr) oldHash := b.GetBundleHash() - err := b.UploadBatch(context.Background(), "testRequestId", bundleFromRawContent) + err := b.UploadBatch(t.Context(), "testRequestId", bundleFromRawContent) require.NoError(t, err) newHash := b.GetBundleHash() assert.NotEqual(t, oldHash, newHash) diff --git a/go.mod b/go.mod index ec5f548..80341ee 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/snyk/code-client-go -go 1.23.6 +go 1.24.6 require ( github.com/go-git/go-git/v5 v5.14.0 @@ -9,7 +9,7 @@ require ( github.com/hexops/gotextdiff v1.0.3 github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 github.com/oapi-codegen/runtime v1.1.1 - github.com/pact-foundation/pact-go/v2 v2.0.5 + github.com/pact-foundation/pact-go/v2 v2.4.1 github.com/pkg/errors v0.9.1 github.com/puzpuzpuz/xsync v1.5.2 github.com/rs/zerolog v1.32.0 @@ -33,7 +33,7 @@ require ( github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect - github.com/hashicorp/go-version v1.6.0 // indirect + github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/invopop/yaml v0.3.1 // indirect @@ -50,9 +50,9 @@ require ( github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/skeema/knownhosts v1.3.1 // indirect github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect - github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cobra v1.8.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/afero v1.12.0 // indirect + github.com/spf13/cobra v1.9.1 // indirect + github.com/spf13/pflag v1.0.6 // indirect github.com/stretchr/objx v0.5.2 // indirect github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect @@ -61,9 +61,9 @@ require ( golang.org/x/sys v0.30.0 // indirect golang.org/x/text v0.22.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/grpc v1.63.2 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect + google.golang.org/grpc v1.71.0 // indirect + google.golang.org/protobuf v1.36.5 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 6e816ab..cf5d14d 100644 --- a/go.sum +++ b/go.sum @@ -19,7 +19,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/cloudflare/circl v1.6.0 h1:cr5JKic4HI+LkINy2lg3W2jF8sHCVTBncJr5gIIq7qk= github.com/cloudflare/circl v1.6.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -48,6 +48,10 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.14.0 h1:/MD3lCrGjCen5WfEAzKg00MJJffKhC8gzS80ycmCi60= github.com/go-git/go-git/v5 v5.14.0/go.mod h1:Z5Xhoia5PcWA3NF8vRLURn9E5FRhSl7dGj9ItW3Wk5k= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= @@ -69,6 +73,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -78,8 +84,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= -github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= +github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= @@ -134,8 +140,8 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= -github.com/pact-foundation/pact-go/v2 v2.0.5 h1:t7Ngeug5TYYREKYBLAb+jmNUB84mJdBNTYRAfPLyY90= -github.com/pact-foundation/pact-go/v2 v2.0.5/go.mod h1:OO003128Co8mczCV7UrD6kmeCdyxFOAv4dt3BFvqy5E= +github.com/pact-foundation/pact-go/v2 v2.4.1 h1:eaLC58qzeCTbwdlCY8UvWz1HmDW+qrjTFfH8Xoq0rWs= +github.com/pact-foundation/pact-go/v2 v2.4.1/go.mod h1:OwnXXRliPZvKDMJn/IsAwQ95tQprmp5gPTzPYz54mTg= github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4= @@ -161,12 +167,12 @@ github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnB github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= github.com/speakeasy-api/openapi-overlay v0.9.0 h1:Wrz6NO02cNlLzx1fB093lBlYxSI54VRhy1aSutx0PQg= github.com/speakeasy-api/openapi-overlay v0.9.0/go.mod h1:f5FloQrHA7MsxYg9djzMD5h6dxrHjVVByWKh7an8TRc= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs= +github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= @@ -185,6 +191,18 @@ github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= +go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= +go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= +go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= +go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= +go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= +go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= +go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= +go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -258,10 +276,10 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50= +google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg= +google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -270,8 +288,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/internal/analysis/analysis_test.go b/internal/analysis/analysis_test.go index 10dbd89..7bffb83 100644 --- a/internal/analysis/analysis_test.go +++ b/internal/analysis/analysis_test.go @@ -17,7 +17,6 @@ package analysis_test import ( "bytes" - "context" _ "embed" "encoding/json" "fmt" @@ -185,7 +184,7 @@ func TestAnalysis_RunTest(t *testing.T) { // run method under test result, resultMetadata, err := analysisOrchestrator.RunTest( - context.Background(), + t.Context(), orgId, inputBundle, targetId, @@ -237,7 +236,7 @@ func TestAnalysis_RunTestRemote(t *testing.T) { // run method under test result, resultMetadata, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), orgId, analysis.AnalysisConfig{ ProjectId: &projectId, @@ -278,7 +277,7 @@ func TestAnalysis_RunTestRemote_CreateTestFailed(t *testing.T) { // run method under test result, resultMetadata, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), orgId, analysis.AnalysisConfig{ ProjectId: &projectId, @@ -322,7 +321,7 @@ func TestAnalysis_RunTestRemote_PollingFailed(t *testing.T) { // run method under test result, resultMetadata, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), orgId, analysis.AnalysisConfig{ ProjectId: &projectId, @@ -372,7 +371,7 @@ func TestAnalysis_RunTestRemote_GetDocumentFailed(t *testing.T) { // run method under test result, resultMetadata, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), orgId, analysis.AnalysisConfig{ ProjectId: &projectId, @@ -401,7 +400,7 @@ func TestAnalysis_RunTestRemote_MissingRequiredParams(t *testing.T) { t.Run("missing both projectId and commitId", func(t *testing.T) { result, _, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), "4a72d1db-b465-4764-99e1-ecedad03b06a", analysis.AnalysisConfig{}, ) @@ -414,7 +413,7 @@ func TestAnalysis_RunTestRemote_MissingRequiredParams(t *testing.T) { t.Run("missing projectId", func(t *testing.T) { commitId := "abc123" result, _, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), "4a72d1db-b465-4764-99e1-ecedad03b06a", analysis.AnalysisConfig{ CommitId: &commitId, @@ -429,7 +428,7 @@ func TestAnalysis_RunTestRemote_MissingRequiredParams(t *testing.T) { t.Run("missing commitId", func(t *testing.T) { projectId := uuid.New() result, _, err := analysisOrchestrator.RunTestRemote( - context.Background(), + t.Context(), "4a72d1db-b465-4764-99e1-ecedad03b06a", analysis.AnalysisConfig{ ProjectId: &projectId, diff --git a/internal/deepcode/client_test.go b/internal/deepcode/client_test.go index b88472a..0466187 100644 --- a/internal/deepcode/client_test.go +++ b/internal/deepcode/client_test.go @@ -17,7 +17,6 @@ package deepcode_test import ( "bytes" - "context" "fmt" "io" "net/http" @@ -89,7 +88,7 @@ func TestSnykCodeBackendService_GetFilters(t *testing.T) { mockErrorReporter := mocks.NewMockErrorReporter(ctrl) s := deepcode.NewDeepcodeClient(mockConfig, mockHTTPClient, newLogger(t), mockInstrumentor, mockErrorReporter) - filters, err := s.GetFilters(context.Background()) + filters, err := s.GetFilters(t.Context()) assert.Nil(t, err) assert.Equal(t, 1, len(filters.ConfigFiles)) assert.Equal(t, 1, len(filters.ConfigFiles)) @@ -124,7 +123,7 @@ func TestSnykCodeBackendService_GetFilters_Failure(t *testing.T) { mockErrorReporter := mocks.NewMockErrorReporter(ctrl) s := deepcode.NewDeepcodeClient(mockConfig, mockHTTPClient, newLogger(t), mockInstrumentor, mockErrorReporter) - _, err := s.GetFilters(context.Background()) + _, err := s.GetFilters(t.Context()) assert.Error(t, err) } @@ -162,7 +161,7 @@ func TestSnykCodeBackendService_CreateBundle(t *testing.T) { files := map[string]string{} randomAddition := fmt.Sprintf("\n public void random() { System.out.println(\"%d\") }", time.Now().UnixMicro()) files[path1], _ = util.Hash([]byte(content + randomAddition)) - bundleHash, missingFiles, err := s.CreateBundle(context.Background(), files) + bundleHash, missingFiles, err := s.CreateBundle(t.Context(), files) assert.Nil(t, err) assert.NotNil(t, bundleHash) assert.Equal(t, "bundleHash", bundleHash) @@ -202,7 +201,7 @@ func TestSnykCodeBackendService_CreateBundle_Failure(t *testing.T) { files := map[string]string{} randomAddition := fmt.Sprintf("\n public void random() { System.out.println(\"%d\") }", time.Now().UnixMicro()) files[path1], _ = util.Hash([]byte(content + randomAddition)) - _, _, err := s.CreateBundle(context.Background(), files) + _, _, err := s.CreateBundle(t.Context(), files) assert.Error(t, err) } @@ -251,10 +250,10 @@ func TestSnykCodeBackendService_ExtendBundle(t *testing.T) { var removedFiles []string files := map[string]string{} files[path1], _ = util.Hash([]byte(content)) - bundleHash, _, _ := s.CreateBundle(context.Background(), files) + bundleHash, _, _ := s.CreateBundle(t.Context(), files) filesExtend := createTestExtendMap() - bundleHash, missingFiles, err := s.ExtendBundle(context.Background(), bundleHash, filesExtend, removedFiles) + bundleHash, missingFiles, err := s.ExtendBundle(t.Context(), bundleHash, filesExtend, removedFiles) assert.Nil(t, err) assert.Equal(t, 0, len(missingFiles)) assert.NotEmpty(t, bundleHash) @@ -304,10 +303,10 @@ func TestSnykCodeBackendService_ExtendBundle_Failure(t *testing.T) { var removedFiles []string files := map[string]string{} files[path1], _ = util.Hash([]byte(content)) - bundleHash, _, _ := s.CreateBundle(context.Background(), files) + bundleHash, _, _ := s.CreateBundle(t.Context(), files) filesExtend := createTestExtendMap() - _, _, err := s.ExtendBundle(context.Background(), bundleHash, filesExtend, removedFiles) + _, _, err := s.ExtendBundle(t.Context(), bundleHash, filesExtend, removedFiles) assert.Error(t, err) } diff --git a/internal/deepcode/pacts/code-client-go-snykcodeapi.json b/internal/deepcode/pacts/code-client-go-snykcodeapi.json index 153f819..239eb70 100644 --- a/internal/deepcode/pacts/code-client-go-snykcodeapi.json +++ b/internal/deepcode/pacts/code-client-go-snykcodeapi.json @@ -3,6 +3,139 @@ "name": "code-client-go" }, "interactions": [ + { + "description": "Create bundle", + "providerState": "New bundle", + "request": { + "headers": { + "Content-Encoding": "gzip", + "Content-Type": "application/octet-stream", + "snyk-org-name": "00000000-0000-0000-0000-000000000023", + "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" + }, + "matchingRules": { + "$.headers['snyk-org-name']": { + "match": "regex", + "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + }, + "$.headers['snyk-request-id']": { + "match": "regex", + "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + } + }, + "method": "POST", + "path": "/bundle" + }, + "response": { + "body": { + "bundleHash": "string", + "missingFiles": [ + "string" + ] + }, + "headers": { + "Content-Type": "application/json" + }, + "matchingRules": { + "$.body.bundleHash": { + "match": "type" + }, + "$.body.missingFiles": { + "match": "type", + "min": 1 + }, + "$.body.missingFiles[*]": { + "match": "type" + } + }, + "status": 200 + } + }, + { + "description": "Create bundle", + "providerState": "New bundle and invalid token", + "request": { + "headers": { + "Content-Encoding": "gzip", + "Content-Type": "application/octet-stream", + "snyk-org-name": "00000000-0000-0000-0000-000000000023", + "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" + }, + "matchingRules": { + "$.headers['snyk-org-name']": { + "match": "regex", + "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + }, + "$.headers['snyk-request-id']": { + "match": "regex", + "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + } + }, + "method": "POST", + "path": "/bundle" + }, + "response": { + "body": { + "message": "Invalid auth token provided" + }, + "headers": { + "Content-Type": "application/json; charset=utf-8" + }, + "status": 401 + } + }, + { + "description": "Extend bundle", + "providerState": "Existing bundle", + "request": { + "headers": { + "Content-Encoding": "gzip", + "Content-Type": "application/octet-stream", + "snyk-org-name": "00000000-0000-0000-0000-000000000023", + "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" + }, + "matchingRules": { + "$.headers['snyk-org-name']": { + "match": "regex", + "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + }, + "$.headers['snyk-request-id']": { + "match": "regex", + "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" + }, + "$.path": { + "match": "regex", + "regex": "/bundle/[A-Fa-f0-9]{64}" + } + }, + "method": "PUT", + "path": "/bundle/faa6b7161c14f933ef4ca79a18ad9283eab362d5e6d3a977125eb95b37c377d8" + }, + "response": { + "body": { + "bundleHash": "string", + "missingFiles": [ + "string" + ] + }, + "headers": { + "Content-Type": "application/json" + }, + "matchingRules": { + "$.body.bundleHash": { + "match": "type" + }, + "$.body.missingFiles": { + "match": "type", + "min": 1 + }, + "$.body.missingFiles[*]": { + "match": "type" + } + }, + "status": 200 + } + }, { "description": "Get filters", "request": { @@ -11,7 +144,7 @@ "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" }, "matchingRules": { - "$.header['snyk-request-id']": { + "$.headers['snyk-request-id']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" } @@ -61,11 +194,11 @@ "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" }, "matchingRules": { - "$.header['snyk-org-name']": { + "$.headers['snyk-org-name']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" }, - "$.header['snyk-request-id']": { + "$.headers['snyk-request-id']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" }, @@ -113,11 +246,11 @@ "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" }, "matchingRules": { - "$.header['snyk-org-name']": { + "$.headers['snyk-org-name']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" }, - "$.header['snyk-request-id']": { + "$.headers['snyk-request-id']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" } @@ -161,11 +294,11 @@ "snyk-request-id": "fc763eba-0905-41c5-a27f-3934ab26786c" }, "matchingRules": { - "$.header['snyk-org-name']": { + "$.headers['snyk-org-name']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" }, - "$.header['snyk-request-id']": { + "$.headers['snyk-request-id']": { "match": "regex", "regex": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" } @@ -185,10 +318,13 @@ } ], "metadata": { + "pact-go": { + "version": "2.4.1" + }, "pactRust": { - "ffi": "0.4.16", - "mockserver": "1.2.5", - "models": "1.1.19" + "ffi": "0.4.27", + "mockserver": "1.2.11", + "models": "1.2.8" }, "pactSpecification": { "version": "2.0.0" diff --git a/llm/api_client_test.go b/llm/api_client_test.go index 704c8b1..ae6be40 100644 --- a/llm/api_client_test.go +++ b/llm/api_client_test.go @@ -1,7 +1,6 @@ package llm import ( - "context" "encoding/base64" "encoding/json" "io" @@ -97,7 +96,7 @@ func TestDeepcodeLLMBinding_runExplain(t *testing.T) { d := NewDeepcodeLLMBinding() - ctx := context.Background() + ctx := t.Context() ctx = observability.GetContextWithTraceId(ctx, "test-trace-id") response, err := d.runExplain(ctx, tt.options) diff --git a/llm/binding_smoke_test.go b/llm/binding_smoke_test.go index ddac1c0..8eea201 100644 --- a/llm/binding_smoke_test.go +++ b/llm/binding_smoke_test.go @@ -1,7 +1,6 @@ package llm import ( - "context" "net/url" "testing" @@ -24,6 +23,6 @@ func TestDeepcodeLLMBinding_Explain_Smoke(t *testing.T) { endpoint, errEndpoint := url.Parse(defaultEndpointURL) assert.NoError(t, errEndpoint) - err := binding.Explain(context.Background(), AIRequest{Id: uuid.New().String(), Input: "{}", Endpoint: endpoint}, HTML, outputChain) + err := binding.Explain(t.Context(), AIRequest{Id: uuid.New().String(), Input: "{}", Endpoint: endpoint}, HTML, outputChain) assert.NoError(t, err) } diff --git a/llm/binding_test.go b/llm/binding_test.go index 8f35e48..88b61a3 100644 --- a/llm/binding_test.go +++ b/llm/binding_test.go @@ -1,7 +1,6 @@ package llm import ( - "context" "encoding/json" "io" http2 "net/http" @@ -15,13 +14,12 @@ import ( "github.com/snyk/code-client-go/http" "github.com/snyk/code-client-go/http/mocks" - "github.com/snyk/code-client-go/observability" ) func TestDeepcodeLLMBinding_PublishIssues(t *testing.T) { binding := NewDeepcodeLLMBinding() - assert.PanicsWithValue(t, "implement me", func() { _ = binding.PublishIssues(context.Background(), []map[string]string{}) }) + assert.PanicsWithValue(t, "implement me", func() { _ = binding.PublishIssues(t.Context(), []map[string]string{}) }) } func TestExplainWithOptions(t *testing.T) { @@ -49,7 +47,7 @@ func TestExplainWithOptions(t *testing.T) { mockHTTPClient.EXPECT().Do(gomock.Any()).Return(&mockResponse, nil) testDiff := "test diff" endpoint := &url.URL{Scheme: "http", Host: "test.com"} - explanation, err := d.ExplainWithOptions(context.Background(), ExplainOptions{Diffs: []string{testDiff}, Endpoint: endpoint}) + explanation, err := d.ExplainWithOptions(t.Context(), ExplainOptions{Diffs: []string{testDiff}, Endpoint: endpoint}) assert.NoError(t, err) var exptectedExplanationsResponse explainResponse err = json.Unmarshal(expectedResponseBody, &exptectedExplanationsResponse) diff --git a/scan_test.go b/scan_test.go index e4ad604..7b3218c 100644 --- a/scan_test.go +++ b/scan_test.go @@ -16,7 +16,6 @@ package codeclient_test import ( - "context" "os" "path/filepath" "testing" @@ -67,7 +66,7 @@ func Test_UploadAndAnalyze(t *testing.T) { mockConfig.EXPECT().Organization().AnyTimes().Return(testOrgId) mockConfig.EXPECT().SnykApi().AnyTimes().Return("") mockSpan := mocks.NewMockSpan(ctrl) - mockSpan.EXPECT().Context().Return(context.Background()).AnyTimes() + mockSpan.EXPECT().Context().Return(t.Context()).AnyTimes() mockInstrumentor := mocks.NewMockInstrumentor(ctrl) mockInstrumentor.EXPECT().StartSpan(gomock.Any(), gomock.Any()).Return(mockSpan).AnyTimes() mockInstrumentor.EXPECT().Finish(gomock.Any()).AnyTimes() @@ -93,7 +92,7 @@ func Test_UploadAndAnalyze(t *testing.T) { codeclient.WithLogger(&logger), ) - response, bundleHash, err := codeScanner.WithBundleManager(mockBundleManager).UploadAndAnalyze(context.Background(), requestId, target, docs, map[string]bool{}) + response, bundleHash, err := codeScanner.WithBundleManager(mockBundleManager).UploadAndAnalyze(t.Context(), requestId, target, docs, map[string]bool{}) require.NoError(t, err) assert.Equal(t, "", bundleHash) assert.Nil(t, response) @@ -119,7 +118,7 @@ func Test_UploadAndAnalyze(t *testing.T) { uploadedBundle, err := codeScanner. WithBundleManager(mockBundleManager). - Upload(context.Background(), requestId, target, docs, map[string]bool{}) + Upload(t.Context(), requestId, target, docs, map[string]bool{}) require.NoError(t, err) assert.Equal(t, mockBundle.GetBundleHash(), uploadedBundle.GetBundleHash()) }, @@ -154,7 +153,7 @@ func Test_UploadAndAnalyze(t *testing.T) { response, bundleHash, err := codeScanner. WithBundleManager(mockBundleManager). WithAnalysisOrchestrator(mockAnalysisOrchestrator). - UploadAndAnalyze(context.Background(), requestId, target, docs, map[string]bool{}) + UploadAndAnalyze(t.Context(), requestId, target, docs, map[string]bool{}) require.NoError(t, err) assert.Equal(t, "COMPLETE", response.Status) assert.Equal(t, mockBundle.GetBundleHash(), bundleHash) @@ -191,7 +190,7 @@ func Test_UploadAndAnalyze(t *testing.T) { response, _, err := codeScanner. WithBundleManager(mockBundleManager). WithAnalysisOrchestrator(mockAnalysisOrchestrator). - UploadAndAnalyze(context.Background(), requestId, target, docs, map[string]bool{}) + UploadAndAnalyze(t.Context(), requestId, target, docs, map[string]bool{}) require.NoError(t, err) assert.Equal(t, "COMPLETE", response.Status) }, @@ -209,7 +208,7 @@ func TestAnalyzeRemote(t *testing.T) { mockErrorReporter := mocks.NewMockErrorReporter(ctrl) mockSpan := mocks.NewMockSpan(ctrl) mockSpan.EXPECT().GetTraceId().AnyTimes().Return("testTraceId") - mockSpan.EXPECT().Context().AnyTimes().Return(context.Background()) + mockSpan.EXPECT().Context().AnyTimes().Return(t.Context()) mockInstrumentor.EXPECT().StartSpan(gomock.Any(), gomock.Any()).AnyTimes().Return(mockSpan) mockInstrumentor.EXPECT().Finish(gomock.Any()).AnyTimes() @@ -231,7 +230,7 @@ func TestAnalyzeRemote(t *testing.T) { gomock.Any(), ).Return(&sarif.SarifResponse{Status: "COMPLETE"}, &scan.ResultMetaData{}, nil) - response, _, err := codeScanner.AnalyzeRemote(context.Background()) + response, _, err := codeScanner.AnalyzeRemote(t.Context()) if err != nil { t.Fatalf("AnalyzeRemote failed: %v", err) } @@ -249,7 +248,7 @@ func TestAnalyzeRemote(t *testing.T) { mockErrorReporter.EXPECT().CaptureError(gomock.Any(), gomock.Any()) - response, _, err := codeScanner.AnalyzeRemote(context.Background()) + response, _, err := codeScanner.AnalyzeRemote(t.Context()) assert.Nil(t, response) assert.Error(t, err) })