From 2abf54d845aa03aec2e114785760262181eac38e Mon Sep 17 00:00:00 2001 From: Tronje Krop Date: Tue, 27 Aug 2024 17:28:26 +0200 Subject: [PATCH] chore: update deps (#80) Signed-off-by: Tronje Krop --- .codacy.yaml | 2 + .github/workflows/build.yaml | 2 +- .github/workflows/release.yaml | 4 +- .markdownlint.yaml | 2 - Makefile | 20 ++++--- Makefile.vars | 2 +- VERSION | 2 +- go.mod | 8 +-- go.sum | 14 ++--- gock/README.md | 4 +- gock/store.go | 2 +- internal/math/math.go | 30 ---------- internal/math/math_test.go | 90 ---------------------------- internal/reflect/reflect.go | 25 ++++---- mock/{mock.go => mocks.go} | 0 mock/{mock_test.go => mocks_test.go} | 10 ++-- 16 files changed, 48 insertions(+), 169 deletions(-) delete mode 100644 internal/math/math.go delete mode 100644 internal/math/math_test.go rename mock/{mock.go => mocks.go} (100%) rename mock/{mock_test.go => mocks_test.go} (98%) diff --git a/.codacy.yaml b/.codacy.yaml index 38a96a7..2eac63b 100644 --- a/.codacy.yaml +++ b/.codacy.yaml @@ -5,4 +5,6 @@ engines: - "**/*_test.go" revive: exclude_paths: + - "**/zz_generated.*.go" - "**/mock_*_test.go" + - "**/mock_*.go" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fb64c39..7630131 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,7 +10,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.22.2 + go-version: 1.23.0 - name: Build and tests env: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 77e0d77..4cd851c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,7 +10,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.22.2 + go-version: 1.23.0 - name: Release new version env: @@ -22,4 +22,4 @@ jobs: env: GH_TOKEN: ${{ github.token }} if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - run: make --trace version-publish || true + run: sleep 60 && make --trace version-publish || true diff --git a/.markdownlint.yaml b/.markdownlint.yaml index 5769f66..b5e22df 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -20,8 +20,6 @@ MD013: tables: true # Include headings headings: true - # Include headings - headers: true # Strict length checking strict: true # Stern length checking diff --git a/Makefile b/Makefile index 6d0e728..4fdc1e3 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,28 @@ SHELL := /bin/bash # Include custom variables to modify behavior. -ifneq ("$(wildcard Makefile.vars)","") +GITROOT ?= $(shell git rev-parse --show-toplevel 2>/dev/null || echo $(CURDIR)) +ifneq ("$(wildcard $(GITROOT)/Makefile.vars)","") include Makefile.vars -else - $(warning warning: please customize variables in Makefile.vars) endif # Setup default go compiler environment. export GO ?= go export GOPATH ?= $(shell $(GO) env GOPATH) export GOBIN ?= $(GOPATH)/bin -# Setup go-make to utilize desired build and config scripts. -GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.71 + +# Setup go-make version to use desired build and config scripts. +GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.82 +INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto # Request targets from go-make targets target. TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \ - $(GO) install $(GOMAKE_DEP) >/dev/stderr && \ + $(GO) install $(INSTALL_FLAGS) $(GOMAKE_DEP) >/dev/stderr && \ $(GOBIN)/go-make show-targets 2>/dev/null) # Declare all targets phony to make them available for auto-completion. .PHONY:: $(TARGETS) -# Delegate all targets to go-make in a single call stubbing other targets. -$(eval $(wordlist 1,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))::;@:) -$(firstword $(MAKECMDGOALS) all):: +# Delegate all targets to go-make in a single stubbing call. +GOAL := $(firstword $(MAKECMDGOALS) all) +$(eval $(MAKECMDGOALS)::;@:) +$(GOAL):: $(GOBIN)/go-make @$(GOBIN)/go-make $(MAKECMDGOALS); diff --git a/Makefile.vars b/Makefile.vars index e41cd49..e939aeb 100644 --- a/Makefile.vars +++ b/Makefile.vars @@ -1,5 +1,5 @@ # Setup default test timeout (default: 10s). -TEST_TIMEOUT := 12s +TEST_TIMEOUT := 15s # Setup when to push images (default: pulls [never, pulls, merges]) IMAGE_PUSH := never # Setup the activated commit hooks (default: pre-commit [pre-commit, commit-msg]). diff --git a/VERSION b/VERSION index c5d54ec..7c1886b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.9 +0.0.10 diff --git a/go.mod b/go.mod index 9d9d083..d4bd23f 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,14 @@ module github.com/tkrop/go-testing -go 1.22.2 +go 1.23.0 require ( github.com/golang/mock v1.6.0 github.com/h2non/gock v1.2.0 github.com/huandu/go-clone v1.6.0 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 golang.org/x/text v0.13.0 - golang.org/x/tools v0.19.0 + golang.org/x/tools v0.24.0 ) require ( @@ -17,7 +16,8 @@ require ( github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/mod v0.16.0 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sync v0.8.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e66a7f3..463803f 100644 --- a/go.sum +++ b/go.sum @@ -33,18 +33,16 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 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/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw= -golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -58,8 +56,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= -golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/gock/README.md b/gock/README.md index e52e4f6..5ae6673 100644 --- a/gock/README.md +++ b/gock/README.md @@ -5,13 +5,13 @@ services (gateways) by mocking the network communication using [`gock`][gock]. **Note:** Since the controller is focused on testing, it does not support the same networking and observation features of [`gock`][gock] and requires manual -transport interception setup. However, the interface is mainly compatible with. +transport interception setup. However, the interface is mainly compatible. ## Example usage Just create a new controller on each test, connect it to your HTTP clients or -client wrappers, and than use it to create HTTP mock request/response cycles +client wrappers, and then use it to create HTTP mock request/response cycles as usual. diff --git a/gock/store.go b/gock/store.go index 379acca..e911262 100644 --- a/gock/store.go +++ b/gock/store.go @@ -72,7 +72,7 @@ func (s *MockStore) Match(req *http.Request) (gock.Mock, error) { return mock, nil } } - return nil, nil + return nil, nil //nolint:nilnil // externally defined behavior } // IsDone returns true if all the registered HTTP request/response mocks have diff --git a/internal/math/math.go b/internal/math/math.go deleted file mode 100644 index aa943f8..0000000 --- a/internal/math/math.go +++ /dev/null @@ -1,30 +0,0 @@ -// Package math contains a collection of helpful generic functions helping with -// mathematical problems. It is currently not part of the public interface and -// must be consider as highly instable. -package math - -import ( - "golang.org/x/exp/constraints" -) - -// Max returns the maximal argument of the given arguments. -func Max[T constraints.Ordered](args ...T) T { - max := args[0] - for _, arg := range args[1:] { - if arg > max { - max = arg - } - } - return max -} - -// Min returns the minimal argument of the given arguments. -func Min[T constraints.Ordered](args ...T) T { - min := args[0] - for _, arg := range args[1:] { - if arg < min { - min = arg - } - } - return min -} diff --git a/internal/math/math_test.go b/internal/math/math_test.go deleted file mode 100644 index afaf531..0000000 --- a/internal/math/math_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package math_test - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "github.com/tkrop/go-testing/internal/math" - "github.com/tkrop/go-testing/mock" - "github.com/tkrop/go-testing/test" -) - -type MinMaxParams struct { - setup mock.SetupFunc - values []int - result int - expect test.Expect -} - -var testMinParams = map[string]MinMaxParams{ - "no-values": { - setup: test.Panic("runtime error: index out of range [0] with length 0"), - }, - - "first-value": { - values: []int{-2, -1, 0, 1, 2}, - result: -2, - expect: test.Success, - }, - "last-value": { - values: []int{2, 1, 0, -1, -2}, - result: -2, - expect: test.Success, - }, - "middle-value": { - values: []int{-1, 1, -2, 2, 0}, - result: -2, - expect: test.Success, - }, -} - -func TestMin(t *testing.T) { - test.Map(t, testMinParams). - Run(func(t test.Test, param MinMaxParams) { - // Given - mock.NewMocks(t).Expect(param.setup) - - // When - result := math.Min(param.values...) - - // Then - assert.Equal(t, param.result, result) - }) -} - -var testMaxParams = map[string]MinMaxParams{ - "no-values": { - setup: test.Panic("runtime error: index out of range [0] with length 0"), - }, - - "first-value": { - values: []int{2, 1, 0, -1, -2}, - result: 2, - expect: test.Success, - }, - "last-value": { - values: []int{-2, -1, 0, 1, 2}, - result: 2, - expect: test.Success, - }, - "middle-value": { - values: []int{-1, 1, -2, 2, 0}, - result: 2, - expect: test.Success, - }, -} - -func TestMax(t *testing.T) { - test.Map(t, testMaxParams). - Run(func(t test.Test, param MinMaxParams) { - // Given - mock.NewMocks(t).Expect(param.setup) - - // When - result := math.Max(param.values...) - - // Then - assert.Equal(t, param.result, result) - }) -} diff --git a/internal/reflect/reflect.go b/internal/reflect/reflect.go index 4d5b75b..add86a7 100644 --- a/internal/reflect/reflect.go +++ b/internal/reflect/reflect.go @@ -8,8 +8,6 @@ import ( "fmt" "reflect" "unsafe" - - "github.com/tkrop/go-testing/internal/math" ) // Aliases for types. @@ -79,8 +77,9 @@ func FieldArgOf(v reflect.Value, i int) any { // Get the field value from the copy. vf = vr.Field(i) - // #nosec G103 -- is necessary - rf := reflect.NewAt(vf.Type(), unsafe.Pointer(vf.UnsafeAddr())).Elem() + // #nosec G103 G115 -- is necessary. + rf := reflect.NewAt(vf.Type(), + unsafe.Pointer(vf.UnsafeAddr())).Elem() var value any reflect.ValueOf(&value).Elem().Set(rf) @@ -93,27 +92,27 @@ func ArgOf(v reflect.Value) any { return nil } - switch v.Type().Kind() { //nolint:exhaustive // covered by default + switch v.Type().Kind() { //nolint:exhaustive // covered by default. case reflect.Bool: return v.Bool() case reflect.Int: return int(v.Int()) case reflect.Int8: - return int8(v.Int()) + return int8(v.Int()) // #nosec G115 // checked by type switch. case reflect.Int16: - return int16(v.Int()) + return int16(v.Int()) // #nosec G115 // checked by type switch. case reflect.Int32: - return int32(v.Int()) + return int32(v.Int()) // #nosec G115 // checked by type switch. case reflect.Int64: return v.Int() case reflect.Uint: return uint(v.Uint()) case reflect.Uint8: - return uint8(v.Uint()) + return uint8(v.Uint()) // #nosec G115 // checked by type switch. case reflect.Uint16: - return uint16(v.Uint()) + return uint16(v.Uint()) // #nosec G115 // checked by type switch. case reflect.Uint32: - return uint32(v.Uint()) + return uint32(v.Uint()) // #nosec G115 // checked by type switch. case reflect.Uint64: return v.Uint() // TODO find test case. @@ -280,12 +279,12 @@ func AnyFuncOf(args int, variadic bool) reflect.Type { // arguments. Use `1` to remove the first argument, or `NumIn/NumOut` to remove // all arguments. func BaseFuncOf(mtype reflect.Type, in, out int) reflect.Type { - it := make([]reflect.Type, 0, math.Max(mtype.NumIn()-in, 0)) + it := make([]reflect.Type, 0, max(mtype.NumIn()-in, 0)) for i := in; i < mtype.NumIn(); i++ { it = append(it, mtype.In(i)) } - ot := make([]reflect.Type, 0, math.Max(mtype.NumOut()-out, 0)) + ot := make([]reflect.Type, 0, max(mtype.NumOut()-out, 0)) for i := out; i < mtype.NumOut(); i++ { ot = append(ot, mtype.Out(i)) } diff --git a/mock/mock.go b/mock/mocks.go similarity index 100% rename from mock/mock.go rename to mock/mocks.go diff --git a/mock/mock_test.go b/mock/mocks_test.go similarity index 98% rename from mock/mock_test.go rename to mock/mocks_test.go index 0b32f9d..3c663ac 100644 --- a/mock/mock_test.go +++ b/mock/mocks_test.go @@ -20,7 +20,7 @@ import ( //revive:disable:line-length-limit // go:generate line length -//go:generate mockgen -package=mock_test -destination=mock_iface_test.go -source=mock_test.go IFace,XFace +//go:generate mockgen -package=mock_test -destination=mock_iface_test.go -source=mocks_test.go IFace,XFace //revive:enable:line-length-limit @@ -82,7 +82,7 @@ var ( }() // CallerCallA provides the file with the line number of the `CallA` call // in mock. - CallerCallA = path.Join(SourceDir, "mock/mock_test.go:35") + CallerCallA = path.Join(SourceDir, "mock/mocks_test.go:35") ) type MockParams struct { @@ -120,7 +120,7 @@ var testMockParams = map[string]MockParams{ }, "single mock with unexpected call": { failSetup: test.UnexpectedCall(NewMockIFace, - "CallA", path.Join(SourceDir, "mock_test.go:125"), "ok"), + "CallA", path.Join(SourceDir, "mocks_test.go:125"), "ok"), call: func(_ test.Test, mocks *mock.Mocks) { mock.Get(mocks, NewMockIFace).CallA("ok") }, @@ -130,8 +130,8 @@ var testMockParams = map[string]MockParams{ CallA("ok"), ), failSetup: test.ConsumedCall(NewMockIFace, - "CallA", path.Join(SourceDir, "mock_test.go:137"), - path.Join(SourceDir, "mock_test.go:37"), "ok"), + "CallA", path.Join(SourceDir, "mocks_test.go:137"), + path.Join(SourceDir, "mocks_test.go:37"), "ok"), call: func(_ test.Test, mocks *mock.Mocks) { mock.Get(mocks, NewMockIFace).CallA("ok") mock.Get(mocks, NewMockIFace).CallA("ok")