Skip to content

Commit

Permalink
chore: update deps (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Tronje Krop <[email protected]>
  • Loading branch information
Tronje Krop authored Mar 6, 2024
1 parent 68ee813 commit c774272
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22.0
go-version: 1.22.1

- name: Build and tests
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22.0
go-version: 1.22.1

- name: Release new version
env:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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/[email protected].58
GOMAKE_DEP ?= github.com/tkrop/[email protected].61
# Request targets from go-make targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
$(GO) install $(GOMAKE_DEP) >/dev/stderr && \
Expand Down
53 changes: 53 additions & 0 deletions cmd/mock/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"errors"
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
"github.com/tkrop/go-testing/test"
)

type MainParams struct {
args []string
expectExitCode int
}

var testMainParams = map[string]MainParams{
"no mock to generate": {
args: []string{"mock"},
expectExitCode: 0,
},
}

func TestMain(t *testing.T) {
test.Map(t, testMainParams).
Run(func(t test.Test, param MainParams) {
// Switch to execute main function in test process.
if name := os.Getenv("TEST"); name != "" {
// Ensure only expected test is running.
if name == t.Name() {
os.Args = param.args
main()
assert.Fail(t, "os-exit not called")
}
// Skip other test.
return
}

// Call the main function in a separate process to prevent capture
// regular process exit behavior.
cmd := exec.Command(os.Args[0], "-test.run=TestMain")
cmd.Env = append(os.Environ(), "TEST="+t.Name())
if err := cmd.Run(); err != nil || param.expectExitCode != 0 {
errExit := &exec.ExitError{}
if errors.As(err, &errExit) {
assert.Equal(t, param.expectExitCode, errExit.ExitCode())
} else {
assert.Fail(t, "unexpected error", err)
}
}
})
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
module github.com/tkrop/go-testing

go 1.22.0
go 1.22.1

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.8.4
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/text v0.13.0
golang.org/x/tools v0.18.0
golang.org/x/tools v0.19.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
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.15.0 // indirect
golang.org/x/mod v0.16.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
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-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
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/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=
Expand All @@ -58,8 +58,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.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
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/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=
Expand Down
10 changes: 5 additions & 5 deletions gock/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ var errAny = errors.New("any error")
// NewFooMatcher creates a special foo matcher.
func NewFooMatcher() *gock.MockMatcher {
matcher := gock.NewEmptyMatcher()
matcher.Add(func(req *http.Request, ereq *gock.Request) (bool, error) {
matcher.Add(func(req *http.Request, _ *gock.Request) (bool, error) {
if req.URL.Scheme == "https" {
return true, errAny
}
return true, nil
})
matcher.Add(func(req *http.Request, ereq *gock.Request) (bool, error) {
matcher.Add(func(req *http.Request, _ *gock.Request) (bool, error) {
return req.URL.Host == "foo.com", nil
})
matcher.Add(func(req *http.Request, ereq *gock.Request) (bool, error) {
matcher.Add(func(req *http.Request, _ *gock.Request) (bool, error) {
return req.URL.Path == "/baz" || req.URL.Path == "/bar", nil
})
return matcher
}

// NewRoundTrippertError creates the same round trip error usually returned in
// NewRoundTripperError creates the same round trip error usually returned in
// case of a transport error. This method is used for validating tests that are
// replacing the transport against the error `RoundTripper` via
// `NewErrorRoundTripper`.
func NewRoundTrippertError(method string, _url string, err error) error {
func NewRoundTripperError(method string, _url string, err error) error {
op := cases.Title(language.Und).String(method)
return &url.Error{Op: op, URL: _url, Err: err}
}
2 changes: 1 addition & 1 deletion gock/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestController(t *testing.T) {

// Then
if param.expectError != nil {
assert.Equal(t, NewRoundTrippertError(
assert.Equal(t, NewRoundTripperError(
http.MethodGet, param.url, param.expectError), err)
} else {
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func FieldArgOf(v reflect.Value, i int) any {

// Get the field value from the copy.
vf = vr.Field(i)
//#nosec G103 -- is necessary
// #nosec G103 -- is necessary
rf := reflect.NewAt(vf.Type(), unsafe.Pointer(vf.UnsafeAddr())).Elem()

var value any
Expand Down
8 changes: 4 additions & 4 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func CallB(input string, output string) mock.SetupFunc {
return func(mocks *mock.Mocks) any {
return mock.Get(mocks, NewMockIFace).EXPECT().
CallB(input).DoAndReturn(
mocks.Call(IFace.CallB, func(a ...any) []any {
mocks.Call(IFace.CallB, func(...any) []any {
return []any{output}
}))
}
Expand Down Expand Up @@ -734,7 +734,7 @@ var testFuncDoNoReturnParams = map[string]FuncParams{
}

func TestFuncDo(t *testing.T) {
test.Map(t /*, testFuncParams*/, testFuncDoNoReturnParams).
test.Map(t, testFuncParams, testFuncDoNoReturnParams).
Run(func(t test.Test, param FuncParams) {
// Given
mocks := MockSetup(t, param.mockSetup)
Expand Down Expand Up @@ -881,7 +881,7 @@ var testFailureParams = map[string]FailureParam{
},

"panic": {
test: func(t test.Test) { panic("panic") },
test: func(test.Test) { panic("panic") },
expect: test.Failure,
},
}
Expand Down Expand Up @@ -920,7 +920,7 @@ var testWaitParams = map[string]WaitParam{

func TestFuncWait(t *testing.T) {
test.Map(t, testWaitParams).
Run(func(t test.Test, param WaitParam) {
Run(func(t test.Test, _ WaitParam) {
// Given
mocks := mock.NewMocks(t)

Expand Down
14 changes: 0 additions & 14 deletions revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,10 @@ enableAllRules = true
[rule.import-shadowing]
disabled = true

# Restricted alias naming conflicts with '.'-imports.
# Not supporte by current Codacy revive v1.2.3
#[rule.import-alias-naming]
# disabled = true

# Exluding '.'-import makes test package separation unnecessary difficult.
[rule.dot-imports]
disabled = true

# Fails to exclude nolint directives from reporting.
# Not supporte by current Codacy revive v1.2.3
#[rule.comment-spacings]
# disabled = true

# Revive v1.2.3 is reporting incorrect empty lines.
[rule.empty-lines]
disabled = true

# Fails to disable writers that actually cannot return errors.
[rule.unhandled-error]
disabled = true
Expand Down
2 changes: 1 addition & 1 deletion test/caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getCaller(call func(t test.Reporter)) string {
t := test.NewTester(&testing.T{}, test.Failure)
mocks := mock.NewMocks(t)
caller := mock.Get(mocks,
func(ctrl *gomock.Controller) *Caller {
func(*gomock.Controller) *Caller {
return &Caller{}
})
t.Reporter(caller)
Expand Down
4 changes: 2 additions & 2 deletions test/gomock.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func UnexpectedCall[T any](
creator func(*gomock.Controller) *T,
method, caller string, args ...any,
) func(Test, *mock.Mocks) mock.SetupFunc {
return func(t Test, mocks *mock.Mocks) mock.SetupFunc {
return func(_ Test, mocks *mock.Mocks) mock.SetupFunc {
return Fatalf("Unexpected call to %T.%v(%v) at %s because: %s",
mock.Get(mocks, creator), method, args, caller,
fmt.Errorf("there are no expected calls "+ //nolint:goerr113 // necessary
Expand All @@ -146,7 +146,7 @@ func ConsumedCall[T any](
creator func(*gomock.Controller) *T,
method, caller, ecaller string, args ...any,
) func(Test, *mock.Mocks) mock.SetupFunc {
return func(t Test, mocks *mock.Mocks) mock.SetupFunc {
return func(_ Test, mocks *mock.Mocks) mock.SetupFunc {
return Fatalf("Unexpected call to %T.%v(%v) at %s because: %s",
mock.Get(mocks, creator), method, args, caller,
fmt.Errorf("\nexpected call at %s has "+ //nolint:goerr113 // necessary
Expand Down
6 changes: 3 additions & 3 deletions test/gomock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var testReporterParams = map[string]ReporterParams{
},
"panic called": {
mockSetup: test.Panic("fail"),
call: func(t test.Test) {
call: func(test.Test) {
panic("fail")
},
},
Expand Down Expand Up @@ -224,7 +224,7 @@ var testReporterParams = map[string]ReporterParams{
"panic undeclared": {
failSetup: test.UnexpectedCall(test.NewValidator,
"Panic", CallerPanic, "fail"),
call: func(t test.Test) {
call: func(test.Test) {
panic("fail")
},
},
Expand Down Expand Up @@ -259,7 +259,7 @@ var testReporterParams = map[string]ReporterParams{
},
"panic consumed": {
mockSetup: test.Panic("fail"),
call: func(t test.Test) {
call: func(test.Test) {
panic("fail")
//nolint:govet // needed for testing
panic("fail")
Expand Down
Loading

0 comments on commit c774272

Please sign in to comment.