From 60372e3e888c1a43656b5b495fabf1ba95fc2d6e Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Thu, 12 Sep 2024 00:00:45 +0300 Subject: [PATCH] chore: gofumpt -w . (#202) Signed-off-by: Sasha Melentyev --- gomock/call.go | 6 ++-- gomock/controller.go | 2 ++ gomock/controller_test.go | 8 +++--- gomock/matchers_test.go | 28 ++++++++++++------- .../internal/tests/sanitization/any/any.go | 2 +- mockgen/model/model_test.go | 1 - mockgen/reflect.go | 4 +-- sample/user.go | 6 ++-- 8 files changed, 34 insertions(+), 23 deletions(-) diff --git a/gomock/call.go b/gomock/call.go index ef76fd3..e1fe222 100644 --- a/gomock/call.go +++ b/gomock/call.go @@ -75,8 +75,10 @@ func newCall(t TestHelper, receiver any, method string, methodType reflect.Type, } return rets }} - return &Call{t: t, receiver: receiver, method: method, methodType: methodType, - args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions} + return &Call{ + t: t, receiver: receiver, method: method, methodType: methodType, + args: mArgs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions, + } } // AnyTimes allows the expectation to be called 0 or more times diff --git a/gomock/controller.go b/gomock/controller.go index ee7df98..674c329 100644 --- a/gomock/controller.go +++ b/gomock/controller.go @@ -128,6 +128,7 @@ type cancelReporter struct { func (r *cancelReporter) Errorf(format string, args ...any) { r.t.Errorf(format, args...) } + func (r *cancelReporter) Fatalf(format string, args ...any) { defer r.cancel() r.t.Fatalf(format, args...) @@ -156,6 +157,7 @@ type nopTestHelper struct { func (h *nopTestHelper) Errorf(format string, args ...any) { h.t.Errorf(format, args...) } + func (h *nopTestHelper) Fatalf(format string, args ...any) { h.t.Fatalf(format, args...) } diff --git a/gomock/controller_test.go b/gomock/controller_test.go index 03d9e64..7e0397d 100644 --- a/gomock/controller_test.go +++ b/gomock/controller_test.go @@ -563,8 +563,8 @@ func TestSetArgSlice(t *testing.T) { _, ctrl := createFixtures(t) subject := new(Subject) - var in = []byte{4, 5, 6} - var set = []byte{1, 2, 3} + in := []byte{4, 5, 6} + set := []byte{1, 2, 3} ctrl.RecordCall(subject, "SetArgMethod", in, nil, nil).SetArg(0, set) ctrl.Call(subject, "SetArgMethod", in, nil, nil) @@ -584,8 +584,8 @@ func TestSetArgMap(t *testing.T) { _, ctrl := createFixtures(t) subject := new(Subject) - var in = map[any]any{"int": 1, "string": "random string", 1: "1", 0: 0} - var set = map[any]any{"int": 2, 1: "2", 2: 100} + in := map[any]any{"int": 1, "string": "random string", 1: "1", 0: 0} + set := map[any]any{"int": 2, 1: "2", 2: 100} ctrl.RecordCall(subject, "SetArgMethod", nil, nil, in).SetArg(2, set) ctrl.Call(subject, "SetArgMethod", nil, nil, in) diff --git a/gomock/matchers_test.go b/gomock/matchers_test.go index 1f5d58c..ee82479 100644 --- a/gomock/matchers_test.go +++ b/gomock/matchers_test.go @@ -26,10 +26,12 @@ import ( "go.uber.org/mock/gomock/internal/mock_gomock" ) -type A []string -type B struct { - Name string -} +type ( + A []string + B struct { + Name string + } +) func TestMatchers(t *testing.T) { type e any @@ -39,21 +41,27 @@ func TestMatchers(t *testing.T) { yes, no []e }{ {"test Any", gomock.Any(), []e{3, nil, "foo"}, nil}, - {"test AnyOf", gomock.AnyOf(gomock.Nil(), gomock.Len(2), 1, 2, 3), + { + "test AnyOf", gomock.AnyOf(gomock.Nil(), gomock.Len(2), 1, 2, 3), []e{nil, "hi", "to", 1, 2, 3}, - []e{"s", "", 0, 4, 10}}, + []e{"s", "", 0, 4, 10}, + }, {"test All", gomock.Eq(4), []e{4}, []e{3, "blah", nil, int64(4)}}, - {"test Nil", gomock.Nil(), + { + "test Nil", gomock.Nil(), []e{nil, (error)(nil), (chan bool)(nil), (*int)(nil)}, - []e{"", 0, make(chan bool), errors.New("err"), new(int)}}, + []e{"", 0, make(chan bool), errors.New("err"), new(int)}, + }, {"test Not", gomock.Not(gomock.Eq(4)), []e{3, "blah", nil, int64(4)}, []e{4}}, {"test Regex", gomock.Regex("[0-9]{2}:[0-9]{2}"), []e{"23:02", "[23:02]: Hello world", []byte("23:02")}, []e{4, "23-02", "hello world", true, []byte("23-02")}}, {"test All", gomock.All(gomock.Any(), gomock.Eq(4)), []e{4}, []e{3, "blah", nil, int64(4)}}, - {"test Len", gomock.Len(2), + { + "test Len", gomock.Len(2), []e{[]int{1, 2}, "ab", map[string]int{"a": 0, "b": 1}, [2]string{"a", "b"}}, []e{[]int{1}, "a", 42, 42.0, false, [1]string{"a"}}, }, - {"test assignable types", gomock.Eq(A{"a", "b"}), + { + "test assignable types", gomock.Eq(A{"a", "b"}), []e{[]string{"a", "b"}, A{"a", "b"}}, []e{[]string{"a"}, A{"b"}}, }, diff --git a/mockgen/internal/tests/sanitization/any/any.go b/mockgen/internal/tests/sanitization/any/any.go index 463403d..1b6abb5 100644 --- a/mockgen/internal/tests/sanitization/any/any.go +++ b/mockgen/internal/tests/sanitization/any/any.go @@ -2,4 +2,4 @@ package any // Any is a type of a package that tests the sanitization of imported packages // named any. -type Any struct {} +type Any struct{} diff --git a/mockgen/model/model_test.go b/mockgen/model/model_test.go index 02ad6be..c0ea0f1 100644 --- a/mockgen/model/model_test.go +++ b/mockgen/model/model_test.go @@ -9,7 +9,6 @@ func TestImpPath(t *testing.T) { nonVendor := "github.com/foo/bar" if nonVendor != impPath(nonVendor) { t.Errorf("") - } testCases := []struct { input string diff --git a/mockgen/reflect.go b/mockgen/reflect.go index ca80ebb..68d922b 100644 --- a/mockgen/reflect.go +++ b/mockgen/reflect.go @@ -142,13 +142,13 @@ func runInDir(program []byte, dir string) (*model.Package, error) { } }() const progSource = "prog.go" - var progBinary = "prog.bin" + progBinary := "prog.bin" if runtime.GOOS == "windows" { // Windows won't execute a program unless it has a ".exe" suffix. progBinary += ".exe" } - if err := os.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil { + if err := os.WriteFile(filepath.Join(tmpDir, progSource), program, 0o600); err != nil { return nil, err } diff --git a/sample/user.go b/sample/user.go index 58a66b2..a1b3971 100644 --- a/sample/user.go +++ b/sample/user.go @@ -5,14 +5,14 @@ package user // Random bunch of imports to test mockgen. import ( - "io" - - btz "bytes" "hash" + "io" "log" "net" "net/http" + btz "bytes" + // Two imports with the same base name. t1 "html/template"