├── LICENSE.md ├── Makefile ├── README.md ├── cmd └── mockigo │ └── main.go ├── go.mod ├── go.sum ├── internal ├── fixtures │ ├── mockery │ │ ├── MapToInterface.go │ │ ├── argument_is_func_type.go │ │ ├── argument_is_map_func.go │ │ ├── async.go │ │ ├── buildtag │ │ │ ├── comment │ │ │ │ ├── custom2_iface.go │ │ │ │ ├── custom_iface.go │ │ │ │ ├── darwin_iface.go │ │ │ │ ├── freebsd_iface.go │ │ │ │ ├── linux_iface.go │ │ │ │ ├── mocks_test.go │ │ │ │ └── windows_iface.go │ │ │ └── filename │ │ │ │ ├── iface_darwin.go │ │ │ │ ├── iface_freebsd.go │ │ │ │ ├── iface_linux.go │ │ │ │ ├── iface_windows.go │ │ │ │ └── mocks_test.go │ │ ├── consul.go │ │ ├── custom_error.go │ │ ├── empty_interface.go │ │ ├── example_project │ │ │ ├── bar │ │ │ │ └── foo │ │ │ │ │ ├── client.go │ │ │ │ │ └── mocks_test.go │ │ │ ├── context │ │ │ │ ├── context.go │ │ │ │ └── mocks_test.go │ │ │ ├── foo │ │ │ │ ├── foo.go │ │ │ │ ├── mocks_test.go │ │ │ │ └── pkg_name_same_as_import.go │ │ │ ├── mocks_test.go │ │ │ └── root.go │ │ ├── expecterTest.go │ │ ├── func_args_collision.go │ │ ├── function.go │ │ ├── http │ │ │ └── http.go │ │ ├── imports_from_nested_interface.go │ │ ├── imports_same_as_package.go │ │ ├── io_import.go │ │ ├── mock_method_uses_pkg_iface.go │ │ ├── mockery │ │ │ └── mockery.go │ │ ├── mocks_test.go │ │ ├── requester.go │ │ ├── requester2.go │ │ ├── requester3.go │ │ ├── requester4.go │ │ ├── requester_arg_same_as_import.go │ │ ├── requester_arg_same_as_named_import.go │ │ ├── requester_arg_same_as_pkg.go │ │ ├── requester_array.go │ │ ├── requester_elided.go │ │ ├── requester_iface.go │ │ ├── requester_ns.go │ │ ├── requester_ptr.go │ │ ├── requester_ret_elided.go │ │ ├── requester_slice.go │ │ ├── requester_unexported.go │ │ ├── requester_variadic.go │ │ ├── same_name_imports.go │ │ ├── struct_value.go │ │ └── unsafe.go │ └── our │ │ ├── foo_bar.go │ │ ├── generic.go │ │ ├── mocks_test.go │ │ ├── simple.go │ │ ├── some-interface │ │ └── some_interface.go │ │ ├── tester_test.go │ │ ├── variadic.go │ │ └── with_same_pkg_name.go ├── generator │ ├── generator.go │ ├── generator_test.go │ ├── path_trie │ │ ├── path_trie.go │ │ └── path_trie_test.go │ ├── testdata │ │ ├── base.go │ │ └── mocks.go │ ├── tuple_formatter.go │ ├── tuple_formatter_test.go │ └── writer.go └── util │ ├── file_in_dir.go │ ├── file_in_dir_test.go │ ├── map_slice.go │ ├── map_slice_test.go │ ├── string_util.go │ └── string_util_test.go ├── match ├── match.go └── match_test.go └── mock ├── call.go ├── callset.go ├── match.go ├── mock.go ├── mock_test.go ├── ordinal.go ├── ordinal_test.go ├── rets.go ├── slice_to_any_slice.go └── t_test.go /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 mockigo contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | echo "Target not selected" 3 | 4 | gen-fixtures: 5 | go generate ./internal/fixtures/... 6 | 7 | test: 8 | go test -cover ./... 9 | 10 | install: 11 | go install ./cmd/mockigo -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mockigo 2 | ======= 3 | [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/subtle-byte/mockigo?tab=overview) 4 | 5 | `mockigo` provides the ability to easily generate type-safe mocks for golang interfaces. 6 | 7 | > [!WARNING] 8 | > This project still is quite experimental and the backward incompatible changes are possible. 9 | 10 | Table of Contents 11 | ----------------- 12 | 13 | - [Installation](#installation) 14 | - [Usage in command line](#usage-in-command-line) 15 | - [Generated mocks usage](#generated-mocks-usage) 16 | - [Comparison with `mockery` and `gomock`](#comparison-with-mockery-and-gomock) 17 | 18 | 19 | Installation 20 | ------------ 21 | 22 | You can use the `go install`: 23 | 24 | ``` 25 | go install github.com/subtle-byte/mockigo/cmd/mockigo@latest 26 | ``` 27 | 28 | Usage in command line 29 | ------------ 30 | 31 | Easiest way to create mocks: run `mockigo` without any arguments in the directory with the package you want to generate mocks for. The generated mocks will be placed in the `mocks_test.go` file in the same directory. 32 | 33 | `mockigo` tool has following command line flags: 34 | 35 | | flag | default value |description | 36 | |---|---|---| 37 | | `--targets` | | Comma separated list of interfaces/function types to generate mocks for, if not provided then mocks are generated for all. | 38 | | `--test-pkg` | `false` | Should the generated mocks to be placed in the package with _test suffix. | 39 | | `--out-file` | `mocks_test.go` | Output file (with the mocks). | 40 | | `--gogen` | `true` | Generate `//go:generate` in the output file to ease the regeneration. | 41 | 42 | Having `//go:generate` in the generated files, it easy to regenerate all mocks using `go generate ./...` command. 43 | 44 | Generated mocks usage 45 | ------------ 46 | 47 | For example you had the file `internal/service/service.go`: 48 | 49 | ```go 50 | package service 51 | 52 | type FooBar interface { 53 | Foo(n int) (string, error) 54 | Bar() 55 | } 56 | 57 | type MyFunc func(a, b int) int 58 | ``` 59 | 60 | Being in the `internal/service` directory you run `mockigo` and get the `mocks_test.go` file (in the same directory) with mocks. 61 | 62 | Then you can create file `internal/service/service_test.go` and use the generated mocks: 63 | 64 | ```go 65 | package service 66 | 67 | import ( 68 | "testing" 69 | 70 | "github.com/stretchr/testify/require" 71 | "github.com/subtle-byte/mockigo/match" 72 | ) 73 | 74 | func TestMocks(t *testing.T) { 75 | fooBar := NewFooBarMock(t) 76 | fooBar.EXPECT().Foo(match.Eq(7)).Return("7", nil) 77 | r1, err := fooBar.Foo(7) 78 | require.Equal(t, "7", r1) 79 | require.NoError(t, err) 80 | 81 | myFunc := NewMyFuncMock(t) 82 | myFunc.EXPECT().Execute(match.Any[int](), match.Any[int]()).Return(10) 83 | r2 := myFunc.Execute(1, 2) 84 | require.Equal(t, 10, r2) 85 | } 86 | ``` 87 | 88 | `mathc.Eq` and `match.Any` check the arguments of mock method when it is called. Everything in this testing code is typechecked in compile time using Go 1.18 generics. 89 | 90 | More powerful usage (also everything is typechecked in compile time): 91 | 92 | ```go 93 | package service 94 | 95 | import ( 96 | "strconv" 97 | "testing" 98 | 99 | "github.com/stretchr/testify/require" 100 | "github.com/subtle-byte/mockigo/match" 101 | "github.com/subtle-byte/mockigo/mock" 102 | ) 103 | 104 | func TestMocks(t *testing.T) { 105 | fooBar := NewFooBarMock(t) 106 | mock.InOrder( // Foo can be called only after at least one call of Bar 107 | fooBar.EXPECT().Bar(), 108 | fooBar.EXPECT().Foo(match.MatchedBy(func(n int) bool { 109 | return n > 0 110 | })).RunReturn(func(n int) (string, error) { 111 | return strconv.Itoa(n), nil 112 | }), 113 | ) 114 | fooBar.Bar() 115 | r1, err := fooBar.Foo(9) 116 | require.Equal(t, "9", r1) 117 | require.NoError(t, err) 118 | } 119 | ``` 120 | 121 | Comparison with `mockery` and `gomock` 122 | ------------ 123 | 124 | Neither `mockery` nor `gomock` generate type-safe mocks. 125 | 126 | For example with `gomock` the following code (which generated using `FooBar` interface defined above) is valid during compilation, but it will fail in runtime: 127 | 128 | ```go 129 | fooBar.EXPECT().Foo("not int").Return([]byte("not string"), "not error", "not allowed third return") 130 | ``` 131 | 132 | Also with `mockery` the following code is valid during compilation, but it will fail in runtime: 133 | 134 | ```go 135 | fooBar.EXPECT().Foo("not int").Call.Return(func(notInt string) { 136 | // returns nothing instead of 2 expected returns 137 | }) 138 | ``` 139 | -------------------------------------------------------------------------------- /cmd/mockigo/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "log" 6 | "os" 7 | "strings" 8 | 9 | "github.com/subtle-byte/mockigo/internal/generator" 10 | "github.com/subtle-byte/mockigo/internal/util" 11 | ) 12 | 13 | func main() { 14 | var targets, outFile string 15 | var testPkg, gogen bool 16 | flag.StringVar(&targets, "targets", "", "Comma separated list of interfaces/function types to generate mocks for, all if empty") 17 | flag.BoolVar(&testPkg, "test-pkg", false, "Should the generated mocks to be placed in the package with _test suffix") 18 | flag.StringVar(&outFile, "out-file", "mocks_test.go", "Output file") 19 | flag.BoolVar(&gogen, "gogen", true, "Generate go:generate in the output file to ease the regeneration") 20 | flag.Parse() 21 | 22 | targetsSplitted := strings.Split(targets, ",") 23 | if len(targetsSplitted) == 1 && targetsSplitted[0] == "" { 24 | targetsSplitted = nil 25 | } 26 | gogenCmd := "" 27 | if gogen { 28 | sameDir, err := util.FileInDir(".", outFile) 29 | if err != nil { 30 | log.Fatalln("ERROR:", err) 31 | } 32 | if sameDir { 33 | gogenCmd = "mockigo " + strings.Join(os.Args[1:], " ") 34 | } else { 35 | log.Println("WARNING: go:generate is not added to output because generating to the different directory") 36 | } 37 | } 38 | err := generator.Generate(generator.Config{ 39 | TargetPkgDirPath: ".", 40 | Targets: generator.Targets{ 41 | Include: len(targetsSplitted) == 0, 42 | Exceptions: util.SliceToSet(targetsSplitted), 43 | }, 44 | OutPkgName: func(inspectedPkgName string) string { 45 | if testPkg { 46 | inspectedPkgName += "_test" 47 | } 48 | return inspectedPkgName 49 | }, 50 | OutFilePath: outFile, 51 | OutPublic: true, 52 | GoGenCmd: gogenCmd, 53 | }) 54 | if err != nil { 55 | log.Fatalln("ERROR:", err) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/subtle-byte/mockigo 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/k0kubun/pp/v3 v3.2.0 7 | github.com/stretchr/testify v1.8.4 8 | golang.org/x/tools v0.10.0 9 | ) 10 | 11 | require ( 12 | github.com/davecgh/go-spew v1.1.1 // indirect 13 | github.com/mattn/go-colorable v0.1.13 // indirect 14 | github.com/mattn/go-isatty v0.0.19 // indirect 15 | github.com/pmezard/go-difflib v1.0.0 // indirect 16 | golang.org/x/mod v0.11.0 // indirect 17 | golang.org/x/sys v0.9.0 // indirect 18 | golang.org/x/text v0.10.0 // indirect 19 | gopkg.in/yaml.v3 v3.0.1 // indirect 20 | ) 21 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs= 4 | github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA= 5 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 6 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 7 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 8 | github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= 9 | github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 10 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 11 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 12 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 13 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 14 | golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= 15 | golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 16 | golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= 17 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 18 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 19 | golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= 20 | golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 21 | golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= 22 | golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 23 | golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg= 24 | golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM= 25 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 26 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 27 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 28 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 29 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/MapToInterface.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type MapToInterface interface { 4 | Foo(arg1 ...map[string]interface{}) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/argument_is_func_type.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Fooer interface { 4 | Foo(f func(x string) string) error 5 | Bar(f func([]int)) 6 | Baz(path string) func(x string) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/argument_is_map_func.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type MapFunc interface { 4 | Get(m map[string]func(string) string) error 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/async.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type AsyncProducer interface { 4 | Input() chan<- bool 5 | Output() <-chan bool 6 | Whatever() chan bool 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/custom2_iface.go: -------------------------------------------------------------------------------- 1 | // +build custom2 2 | 3 | package comment 4 | 5 | type IfaceWithCustomBuildTagInComment interface { 6 | Sprintf(format string, a ...interface{}) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/custom_iface.go: -------------------------------------------------------------------------------- 1 | // +build custom 2 | 3 | package comment 4 | 5 | type IfaceWithCustomBuildTagInComment interface { 6 | Sprintf(format string, a ...interface{}) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/darwin_iface.go: -------------------------------------------------------------------------------- 1 | // +build darwin 2 | 3 | package comment 4 | 5 | type IfaceWithBuildTagInComment interface { 6 | Sprintf(format string, a ...interface{}) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/freebsd_iface.go: -------------------------------------------------------------------------------- 1 | // +build freebsd 2 | 3 | package comment 4 | 5 | type IfaceWithBuildTagInComment interface { 6 | Sprintf(format string, a ...interface{}) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/linux_iface.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package comment 4 | 5 | type IfaceWithBuildTagInComment interface { 6 | Sprintf(format string, a ...interface{}) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package comment 6 | 7 | import match "github.com/subtle-byte/mockigo/match" 8 | import mock "github.com/subtle-byte/mockigo/mock" 9 | 10 | var _ = match.Any[int] 11 | 12 | type IfaceWithBuildTagInCommentMock struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func NewIfaceWithBuildTagInCommentMock(t mock.Testing) *IfaceWithBuildTagInCommentMock { 17 | t.Helper() 18 | return &IfaceWithBuildTagInCommentMock{mock: mock.NewMock(t)} 19 | } 20 | 21 | type _IfaceWithBuildTagInCommentMock_Expecter struct { 22 | mock *mock.Mock 23 | } 24 | 25 | func (_mock *IfaceWithBuildTagInCommentMock) EXPECT() _IfaceWithBuildTagInCommentMock_Expecter { 26 | return _IfaceWithBuildTagInCommentMock_Expecter{mock: _mock.mock} 27 | } 28 | 29 | type _IfaceWithBuildTagInCommentMock_Sprintf_Call struct { 30 | *mock.Call 31 | } 32 | 33 | func (_mock *IfaceWithBuildTagInCommentMock) Sprintf(format string, a ...interface{}) (string) { 34 | _mock.mock.T.Helper() 35 | _args := []any{format, mock.SliceToAnySlice(a)} 36 | _results := _mock.mock.Called("Sprintf", _args...) 37 | _r0 := _results.Get(0).(string) 38 | return _r0 39 | } 40 | 41 | func (_expecter _IfaceWithBuildTagInCommentMock_Expecter) Sprintf(format match.Arg[string], a ...match.Arg[interface{}]) _IfaceWithBuildTagInCommentMock_Sprintf_Call { 42 | _args := append([]mock.Matcher{format.Matcher}, match.ArgsToMatchers(a)...) 43 | return _IfaceWithBuildTagInCommentMock_Sprintf_Call{Call: _expecter.mock.ExpectCall("Sprintf", _args...)} 44 | } 45 | 46 | func (_call _IfaceWithBuildTagInCommentMock_Sprintf_Call) Return(_r0 string) _IfaceWithBuildTagInCommentMock_Sprintf_Call { 47 | _call.Call.Return(_r0) 48 | return _call 49 | } 50 | 51 | func (_call _IfaceWithBuildTagInCommentMock_Sprintf_Call) RunReturn(f func(format string, a ...interface{}) (string)) _IfaceWithBuildTagInCommentMock_Sprintf_Call { 52 | _call.Call.RunReturn(f) 53 | return _call 54 | } 55 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/comment/windows_iface.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package comment 4 | 5 | type IfaceWithBuildTagInComment interface { 6 | Sprintf(format string, a ...interface{}) string 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/filename/iface_darwin.go: -------------------------------------------------------------------------------- 1 | package filename 2 | 3 | type IfaceWithBuildTagInFilename interface { 4 | Sprintf(format string, a ...interface{}) string 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/filename/iface_freebsd.go: -------------------------------------------------------------------------------- 1 | package filename 2 | 3 | type IfaceWithBuildTagInFilename interface { 4 | Sprintf(format string, a ...interface{}) string 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/filename/iface_linux.go: -------------------------------------------------------------------------------- 1 | package filename 2 | 3 | type IfaceWithBuildTagInFilename interface { 4 | Sprintf(format string, a ...interface{}) string 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/filename/iface_windows.go: -------------------------------------------------------------------------------- 1 | package filename 2 | 3 | type IfaceWithBuildTagInFilename interface { 4 | Sprintf(format string, a ...interface{}) string 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/buildtag/filename/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package filename 6 | 7 | import match "github.com/subtle-byte/mockigo/match" 8 | import mock "github.com/subtle-byte/mockigo/mock" 9 | 10 | var _ = match.Any[int] 11 | 12 | type IfaceWithBuildTagInFilenameMock struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func NewIfaceWithBuildTagInFilenameMock(t mock.Testing) *IfaceWithBuildTagInFilenameMock { 17 | t.Helper() 18 | return &IfaceWithBuildTagInFilenameMock{mock: mock.NewMock(t)} 19 | } 20 | 21 | type _IfaceWithBuildTagInFilenameMock_Expecter struct { 22 | mock *mock.Mock 23 | } 24 | 25 | func (_mock *IfaceWithBuildTagInFilenameMock) EXPECT() _IfaceWithBuildTagInFilenameMock_Expecter { 26 | return _IfaceWithBuildTagInFilenameMock_Expecter{mock: _mock.mock} 27 | } 28 | 29 | type _IfaceWithBuildTagInFilenameMock_Sprintf_Call struct { 30 | *mock.Call 31 | } 32 | 33 | func (_mock *IfaceWithBuildTagInFilenameMock) Sprintf(format string, a ...interface{}) (string) { 34 | _mock.mock.T.Helper() 35 | _args := []any{format, mock.SliceToAnySlice(a)} 36 | _results := _mock.mock.Called("Sprintf", _args...) 37 | _r0 := _results.Get(0).(string) 38 | return _r0 39 | } 40 | 41 | func (_expecter _IfaceWithBuildTagInFilenameMock_Expecter) Sprintf(format match.Arg[string], a ...match.Arg[interface{}]) _IfaceWithBuildTagInFilenameMock_Sprintf_Call { 42 | _args := append([]mock.Matcher{format.Matcher}, match.ArgsToMatchers(a)...) 43 | return _IfaceWithBuildTagInFilenameMock_Sprintf_Call{Call: _expecter.mock.ExpectCall("Sprintf", _args...)} 44 | } 45 | 46 | func (_call _IfaceWithBuildTagInFilenameMock_Sprintf_Call) Return(_r0 string) _IfaceWithBuildTagInFilenameMock_Sprintf_Call { 47 | _call.Call.Return(_r0) 48 | return _call 49 | } 50 | 51 | func (_call _IfaceWithBuildTagInFilenameMock_Sprintf_Call) RunReturn(f func(format string, a ...interface{}) (string)) _IfaceWithBuildTagInFilenameMock_Sprintf_Call { 52 | _call.Call.RunReturn(f) 53 | return _call 54 | } 55 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/consul.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type ConsulLock interface { 4 | Lock(<-chan struct{}) (<-chan struct{}, error) 5 | Unlock() error 6 | } 7 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/custom_error.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Err struct { 4 | msg string 5 | code uint64 6 | } 7 | 8 | func (e *Err) Error() string { 9 | return e.msg 10 | } 11 | 12 | func (e *Err) Code() uint64 { 13 | return e.code 14 | } 15 | 16 | type KeyManager interface { 17 | GetKey(string, uint16) ([]byte, *Err) 18 | } 19 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/empty_interface.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Blank interface { 4 | Create(x interface{}) error 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/bar/foo/client.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | type Client interface { 4 | Search(query string) ([]string, error) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/bar/foo/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package foo 6 | 7 | import match "github.com/subtle-byte/mockigo/match" 8 | import mock "github.com/subtle-byte/mockigo/mock" 9 | 10 | var _ = match.Any[int] 11 | 12 | type ClientMock struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func NewClientMock(t mock.Testing) *ClientMock { 17 | t.Helper() 18 | return &ClientMock{mock: mock.NewMock(t)} 19 | } 20 | 21 | type _ClientMock_Expecter struct { 22 | mock *mock.Mock 23 | } 24 | 25 | func (_mock *ClientMock) EXPECT() _ClientMock_Expecter { 26 | return _ClientMock_Expecter{mock: _mock.mock} 27 | } 28 | 29 | type _ClientMock_Search_Call struct { 30 | *mock.Call 31 | } 32 | 33 | func (_mock *ClientMock) Search(query string) ([]string, error) { 34 | _mock.mock.T.Helper() 35 | _results := _mock.mock.Called("Search", query) 36 | var _r0 []string 37 | if _got := _results.Get(0); _got != nil { 38 | _r0 = _got.([]string) 39 | } 40 | _r1 := _results.Error(1) 41 | return _r0, _r1 42 | } 43 | 44 | func (_expecter _ClientMock_Expecter) Search(query match.Arg[string]) _ClientMock_Search_Call { 45 | return _ClientMock_Search_Call{Call: _expecter.mock.ExpectCall("Search", query.Matcher)} 46 | } 47 | 48 | func (_call _ClientMock_Search_Call) Return(_r0 []string, _r1 error) _ClientMock_Search_Call { 49 | _call.Call.Return(_r0, _r1) 50 | return _call 51 | } 52 | 53 | func (_call _ClientMock_Search_Call) RunReturn(f func(query string) ([]string, error)) _ClientMock_Search_Call { 54 | _call.Call.RunReturn(f) 55 | return _call 56 | } 57 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/context/context.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | type CollideWithStdLib interface { 8 | NewClient(ctx context.Context) 9 | } 10 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/context/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package context 6 | 7 | import context "context" 8 | import match "github.com/subtle-byte/mockigo/match" 9 | import mock "github.com/subtle-byte/mockigo/mock" 10 | 11 | var _ = match.Any[int] 12 | 13 | type CollideWithStdLibMock struct { 14 | mock *mock.Mock 15 | } 16 | 17 | func NewCollideWithStdLibMock(t mock.Testing) *CollideWithStdLibMock { 18 | t.Helper() 19 | return &CollideWithStdLibMock{mock: mock.NewMock(t)} 20 | } 21 | 22 | type _CollideWithStdLibMock_Expecter struct { 23 | mock *mock.Mock 24 | } 25 | 26 | func (_mock *CollideWithStdLibMock) EXPECT() _CollideWithStdLibMock_Expecter { 27 | return _CollideWithStdLibMock_Expecter{mock: _mock.mock} 28 | } 29 | 30 | type _CollideWithStdLibMock_NewClient_Call struct { 31 | *mock.Call 32 | } 33 | 34 | func (_mock *CollideWithStdLibMock) NewClient(ctx context.Context) () { 35 | _mock.mock.T.Helper() 36 | _mock.mock.Called("NewClient", ctx) 37 | } 38 | 39 | func (_expecter _CollideWithStdLibMock_Expecter) NewClient(ctx match.Arg[context.Context]) _CollideWithStdLibMock_NewClient_Call { 40 | return _CollideWithStdLibMock_NewClient_Call{Call: _expecter.mock.ExpectCall("NewClient", ctx.Matcher)} 41 | } 42 | 43 | func (_call _CollideWithStdLibMock_NewClient_Call) Return() _CollideWithStdLibMock_NewClient_Call { 44 | _call.Call.Return() 45 | return _call 46 | } 47 | 48 | func (_call _CollideWithStdLibMock_NewClient_Call) RunReturn(f func(ctx context.Context) ()) _CollideWithStdLibMock_NewClient_Call { 49 | _call.Call.RunReturn(f) 50 | return _call 51 | } 52 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/foo/foo.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | type Baz struct { 4 | One string 5 | Two int 6 | } 7 | 8 | type Foo interface { 9 | DoFoo() string 10 | GetBaz() (*Baz, error) 11 | } 12 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/foo/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package foo 6 | 7 | import bar__foo "github.com/subtle-byte/mockigo/internal/fixtures/mockery/example_project/bar/foo" 8 | import match "github.com/subtle-byte/mockigo/match" 9 | import mock "github.com/subtle-byte/mockigo/mock" 10 | 11 | var _ = match.Any[int] 12 | 13 | type FooMock struct { 14 | mock *mock.Mock 15 | } 16 | 17 | func NewFooMock(t mock.Testing) *FooMock { 18 | t.Helper() 19 | return &FooMock{mock: mock.NewMock(t)} 20 | } 21 | 22 | type _FooMock_Expecter struct { 23 | mock *mock.Mock 24 | } 25 | 26 | func (_mock *FooMock) EXPECT() _FooMock_Expecter { 27 | return _FooMock_Expecter{mock: _mock.mock} 28 | } 29 | 30 | type _FooMock_DoFoo_Call struct { 31 | *mock.Call 32 | } 33 | 34 | func (_mock *FooMock) DoFoo() (string) { 35 | _mock.mock.T.Helper() 36 | _results := _mock.mock.Called("DoFoo", ) 37 | _r0 := _results.Get(0).(string) 38 | return _r0 39 | } 40 | 41 | func (_expecter _FooMock_Expecter) DoFoo() _FooMock_DoFoo_Call { 42 | return _FooMock_DoFoo_Call{Call: _expecter.mock.ExpectCall("DoFoo", )} 43 | } 44 | 45 | func (_call _FooMock_DoFoo_Call) Return(_r0 string) _FooMock_DoFoo_Call { 46 | _call.Call.Return(_r0) 47 | return _call 48 | } 49 | 50 | func (_call _FooMock_DoFoo_Call) RunReturn(f func() (string)) _FooMock_DoFoo_Call { 51 | _call.Call.RunReturn(f) 52 | return _call 53 | } 54 | 55 | type _FooMock_GetBaz_Call struct { 56 | *mock.Call 57 | } 58 | 59 | func (_mock *FooMock) GetBaz() (*Baz, error) { 60 | _mock.mock.T.Helper() 61 | _results := _mock.mock.Called("GetBaz", ) 62 | var _r0 *Baz 63 | if _got := _results.Get(0); _got != nil { 64 | _r0 = _got.(*Baz) 65 | } 66 | _r1 := _results.Error(1) 67 | return _r0, _r1 68 | } 69 | 70 | func (_expecter _FooMock_Expecter) GetBaz() _FooMock_GetBaz_Call { 71 | return _FooMock_GetBaz_Call{Call: _expecter.mock.ExpectCall("GetBaz", )} 72 | } 73 | 74 | func (_call _FooMock_GetBaz_Call) Return(_r0 *Baz, _r1 error) _FooMock_GetBaz_Call { 75 | _call.Call.Return(_r0, _r1) 76 | return _call 77 | } 78 | 79 | func (_call _FooMock_GetBaz_Call) RunReturn(f func() (*Baz, error)) _FooMock_GetBaz_Call { 80 | _call.Call.RunReturn(f) 81 | return _call 82 | } 83 | 84 | type PackageNameSameAsImportMock struct { 85 | mock *mock.Mock 86 | } 87 | 88 | func NewPackageNameSameAsImportMock(t mock.Testing) *PackageNameSameAsImportMock { 89 | t.Helper() 90 | return &PackageNameSameAsImportMock{mock: mock.NewMock(t)} 91 | } 92 | 93 | type _PackageNameSameAsImportMock_Expecter struct { 94 | mock *mock.Mock 95 | } 96 | 97 | func (_mock *PackageNameSameAsImportMock) EXPECT() _PackageNameSameAsImportMock_Expecter { 98 | return _PackageNameSameAsImportMock_Expecter{mock: _mock.mock} 99 | } 100 | 101 | type _PackageNameSameAsImportMock_NewClient_Call struct { 102 | *mock.Call 103 | } 104 | 105 | func (_mock *PackageNameSameAsImportMock) NewClient() (bar__foo.Client) { 106 | _mock.mock.T.Helper() 107 | _results := _mock.mock.Called("NewClient", ) 108 | var _r0 bar__foo.Client 109 | if _got := _results.Get(0); _got != nil { 110 | _r0 = _got.(bar__foo.Client) 111 | } 112 | return _r0 113 | } 114 | 115 | func (_expecter _PackageNameSameAsImportMock_Expecter) NewClient() _PackageNameSameAsImportMock_NewClient_Call { 116 | return _PackageNameSameAsImportMock_NewClient_Call{Call: _expecter.mock.ExpectCall("NewClient", )} 117 | } 118 | 119 | func (_call _PackageNameSameAsImportMock_NewClient_Call) Return(_r0 bar__foo.Client) _PackageNameSameAsImportMock_NewClient_Call { 120 | _call.Call.Return(_r0) 121 | return _call 122 | } 123 | 124 | func (_call _PackageNameSameAsImportMock_NewClient_Call) RunReturn(f func() (bar__foo.Client)) _PackageNameSameAsImportMock_NewClient_Call { 125 | _call.Call.RunReturn(f) 126 | return _call 127 | } 128 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/foo/pkg_name_same_as_import.go: -------------------------------------------------------------------------------- 1 | package foo 2 | 3 | import "github.com/subtle-byte/mockigo/internal/fixtures/mockery/example_project/bar/foo" 4 | 5 | type PackageNameSameAsImport interface { 6 | NewClient() foo.Client 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package example_project 6 | 7 | import foo "github.com/subtle-byte/mockigo/internal/fixtures/mockery/example_project/foo" 8 | import match "github.com/subtle-byte/mockigo/match" 9 | import mock "github.com/subtle-byte/mockigo/mock" 10 | 11 | var _ = match.Any[int] 12 | 13 | type RootMock struct { 14 | mock *mock.Mock 15 | } 16 | 17 | func NewRootMock(t mock.Testing) *RootMock { 18 | t.Helper() 19 | return &RootMock{mock: mock.NewMock(t)} 20 | } 21 | 22 | type _RootMock_Expecter struct { 23 | mock *mock.Mock 24 | } 25 | 26 | func (_mock *RootMock) EXPECT() _RootMock_Expecter { 27 | return _RootMock_Expecter{mock: _mock.mock} 28 | } 29 | 30 | type _RootMock_ReturnsFoo_Call struct { 31 | *mock.Call 32 | } 33 | 34 | func (_mock *RootMock) ReturnsFoo() (foo.Foo, error) { 35 | _mock.mock.T.Helper() 36 | _results := _mock.mock.Called("ReturnsFoo", ) 37 | var _r0 foo.Foo 38 | if _got := _results.Get(0); _got != nil { 39 | _r0 = _got.(foo.Foo) 40 | } 41 | _r1 := _results.Error(1) 42 | return _r0, _r1 43 | } 44 | 45 | func (_expecter _RootMock_Expecter) ReturnsFoo() _RootMock_ReturnsFoo_Call { 46 | return _RootMock_ReturnsFoo_Call{Call: _expecter.mock.ExpectCall("ReturnsFoo", )} 47 | } 48 | 49 | func (_call _RootMock_ReturnsFoo_Call) Return(_r0 foo.Foo, _r1 error) _RootMock_ReturnsFoo_Call { 50 | _call.Call.Return(_r0, _r1) 51 | return _call 52 | } 53 | 54 | func (_call _RootMock_ReturnsFoo_Call) RunReturn(f func() (foo.Foo, error)) _RootMock_ReturnsFoo_Call { 55 | _call.Call.RunReturn(f) 56 | return _call 57 | } 58 | 59 | type _RootMock_TakesBaz_Call struct { 60 | *mock.Call 61 | } 62 | 63 | func (_mock *RootMock) TakesBaz(_a0 *foo.Baz) () { 64 | _mock.mock.T.Helper() 65 | _mock.mock.Called("TakesBaz", _a0) 66 | } 67 | 68 | func (_expecter _RootMock_Expecter) TakesBaz(_a0 match.Arg[*foo.Baz]) _RootMock_TakesBaz_Call { 69 | return _RootMock_TakesBaz_Call{Call: _expecter.mock.ExpectCall("TakesBaz", _a0.Matcher)} 70 | } 71 | 72 | func (_call _RootMock_TakesBaz_Call) Return() _RootMock_TakesBaz_Call { 73 | _call.Call.Return() 74 | return _call 75 | } 76 | 77 | func (_call _RootMock_TakesBaz_Call) RunReturn(f func(*foo.Baz) ()) _RootMock_TakesBaz_Call { 78 | _call.Call.RunReturn(f) 79 | return _call 80 | } 81 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/example_project/root.go: -------------------------------------------------------------------------------- 1 | package example_project 2 | 3 | import "github.com/subtle-byte/mockigo/internal/fixtures/mockery/example_project/foo" 4 | 5 | type Root interface { 6 | TakesBaz(*foo.Baz) 7 | ReturnsFoo() (foo.Foo, error) 8 | } 9 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/expecterTest.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type ExpecterTest interface { 4 | NoArg() string 5 | NoReturn(str string) 6 | ManyArgsReturns(str string, i int) (strs []string, err error) 7 | Variadic(ints ...int) error 8 | VariadicMany(i int, a string, intfs ...interface{}) error 9 | } 10 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/func_args_collision.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type FuncArgsCollision interface { 4 | Foo(ret interface{}) error 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/function.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | type SendFunc func(ctx context.Context, data string) (int, error) 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/http/http.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | type MyStruct struct{} 4 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/imports_from_nested_interface.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import ( 4 | "github.com/subtle-byte/mockigo/internal/fixtures/mockery/http" 5 | ) 6 | 7 | type HasConflictingNestedImports interface { 8 | RequesterNS 9 | Z() http.MyStruct 10 | } 11 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/imports_same_as_package.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import ( 4 | "github.com/subtle-byte/mockigo/internal/fixtures/mockery/mockery" 5 | ) 6 | 7 | type C int 8 | 9 | type ImportsSameAsPackage interface { 10 | A() mockery.B 11 | B() KeyManager 12 | C(C) 13 | } 14 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/io_import.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "io" 4 | 5 | type MyReader interface { 6 | io.Reader 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/mock_method_uses_pkg_iface.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Sibling interface { 4 | DoSomething() 5 | } 6 | 7 | type UsesOtherPkgIface interface { 8 | DoSomethingElse(obj Sibling) 9 | } 10 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/mockery/mockery.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type B int 4 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package mockery 6 | 7 | import context "context" 8 | import io "io" 9 | import json "encoding/json" 10 | import match "github.com/subtle-byte/mockigo/match" 11 | import mock "github.com/subtle-byte/mockigo/mock" 12 | import mockery_http "github.com/subtle-byte/mockigo/internal/fixtures/mockery/http" 13 | import mockery_mockery "github.com/subtle-byte/mockigo/internal/fixtures/mockery/mockery" 14 | import net_http "net/http" 15 | import unsafe "unsafe" 16 | 17 | var _ = match.Any[int] 18 | 19 | type AMock struct { 20 | mock *mock.Mock 21 | } 22 | 23 | func NewAMock(t mock.Testing) *AMock { 24 | t.Helper() 25 | return &AMock{mock: mock.NewMock(t)} 26 | } 27 | 28 | type _AMock_Expecter struct { 29 | mock *mock.Mock 30 | } 31 | 32 | func (_mock *AMock) EXPECT() _AMock_Expecter { 33 | return _AMock_Expecter{mock: _mock.mock} 34 | } 35 | 36 | type _AMock_Call_Call struct { 37 | *mock.Call 38 | } 39 | 40 | func (_mock *AMock) Call() (B, error) { 41 | _mock.mock.T.Helper() 42 | _results := _mock.mock.Called("Call", ) 43 | _r0 := _results.Get(0).(B) 44 | _r1 := _results.Error(1) 45 | return _r0, _r1 46 | } 47 | 48 | func (_expecter _AMock_Expecter) Call() _AMock_Call_Call { 49 | return _AMock_Call_Call{Call: _expecter.mock.ExpectCall("Call", )} 50 | } 51 | 52 | func (_call _AMock_Call_Call) Return(_r0 B, _r1 error) _AMock_Call_Call { 53 | _call.Call.Return(_r0, _r1) 54 | return _call 55 | } 56 | 57 | func (_call _AMock_Call_Call) RunReturn(f func() (B, error)) _AMock_Call_Call { 58 | _call.Call.RunReturn(f) 59 | return _call 60 | } 61 | 62 | type AsyncProducerMock struct { 63 | mock *mock.Mock 64 | } 65 | 66 | func NewAsyncProducerMock(t mock.Testing) *AsyncProducerMock { 67 | t.Helper() 68 | return &AsyncProducerMock{mock: mock.NewMock(t)} 69 | } 70 | 71 | type _AsyncProducerMock_Expecter struct { 72 | mock *mock.Mock 73 | } 74 | 75 | func (_mock *AsyncProducerMock) EXPECT() _AsyncProducerMock_Expecter { 76 | return _AsyncProducerMock_Expecter{mock: _mock.mock} 77 | } 78 | 79 | type _AsyncProducerMock_Input_Call struct { 80 | *mock.Call 81 | } 82 | 83 | func (_mock *AsyncProducerMock) Input() (chan<- bool) { 84 | _mock.mock.T.Helper() 85 | _results := _mock.mock.Called("Input", ) 86 | var _r0 chan<- bool 87 | if _got := _results.Get(0); _got != nil { 88 | _r0 = _got.(chan<- bool) 89 | } 90 | return _r0 91 | } 92 | 93 | func (_expecter _AsyncProducerMock_Expecter) Input() _AsyncProducerMock_Input_Call { 94 | return _AsyncProducerMock_Input_Call{Call: _expecter.mock.ExpectCall("Input", )} 95 | } 96 | 97 | func (_call _AsyncProducerMock_Input_Call) Return(_r0 chan<- bool) _AsyncProducerMock_Input_Call { 98 | _call.Call.Return(_r0) 99 | return _call 100 | } 101 | 102 | func (_call _AsyncProducerMock_Input_Call) RunReturn(f func() (chan<- bool)) _AsyncProducerMock_Input_Call { 103 | _call.Call.RunReturn(f) 104 | return _call 105 | } 106 | 107 | type _AsyncProducerMock_Output_Call struct { 108 | *mock.Call 109 | } 110 | 111 | func (_mock *AsyncProducerMock) Output() (<-chan bool) { 112 | _mock.mock.T.Helper() 113 | _results := _mock.mock.Called("Output", ) 114 | var _r0 <-chan bool 115 | if _got := _results.Get(0); _got != nil { 116 | _r0 = _got.(<-chan bool) 117 | } 118 | return _r0 119 | } 120 | 121 | func (_expecter _AsyncProducerMock_Expecter) Output() _AsyncProducerMock_Output_Call { 122 | return _AsyncProducerMock_Output_Call{Call: _expecter.mock.ExpectCall("Output", )} 123 | } 124 | 125 | func (_call _AsyncProducerMock_Output_Call) Return(_r0 <-chan bool) _AsyncProducerMock_Output_Call { 126 | _call.Call.Return(_r0) 127 | return _call 128 | } 129 | 130 | func (_call _AsyncProducerMock_Output_Call) RunReturn(f func() (<-chan bool)) _AsyncProducerMock_Output_Call { 131 | _call.Call.RunReturn(f) 132 | return _call 133 | } 134 | 135 | type _AsyncProducerMock_Whatever_Call struct { 136 | *mock.Call 137 | } 138 | 139 | func (_mock *AsyncProducerMock) Whatever() (chan bool) { 140 | _mock.mock.T.Helper() 141 | _results := _mock.mock.Called("Whatever", ) 142 | var _r0 chan bool 143 | if _got := _results.Get(0); _got != nil { 144 | _r0 = _got.(chan bool) 145 | } 146 | return _r0 147 | } 148 | 149 | func (_expecter _AsyncProducerMock_Expecter) Whatever() _AsyncProducerMock_Whatever_Call { 150 | return _AsyncProducerMock_Whatever_Call{Call: _expecter.mock.ExpectCall("Whatever", )} 151 | } 152 | 153 | func (_call _AsyncProducerMock_Whatever_Call) Return(_r0 chan bool) _AsyncProducerMock_Whatever_Call { 154 | _call.Call.Return(_r0) 155 | return _call 156 | } 157 | 158 | func (_call _AsyncProducerMock_Whatever_Call) RunReturn(f func() (chan bool)) _AsyncProducerMock_Whatever_Call { 159 | _call.Call.RunReturn(f) 160 | return _call 161 | } 162 | 163 | type BlankMock struct { 164 | mock *mock.Mock 165 | } 166 | 167 | func NewBlankMock(t mock.Testing) *BlankMock { 168 | t.Helper() 169 | return &BlankMock{mock: mock.NewMock(t)} 170 | } 171 | 172 | type _BlankMock_Expecter struct { 173 | mock *mock.Mock 174 | } 175 | 176 | func (_mock *BlankMock) EXPECT() _BlankMock_Expecter { 177 | return _BlankMock_Expecter{mock: _mock.mock} 178 | } 179 | 180 | type _BlankMock_Create_Call struct { 181 | *mock.Call 182 | } 183 | 184 | func (_mock *BlankMock) Create(x interface{}) (error) { 185 | _mock.mock.T.Helper() 186 | _results := _mock.mock.Called("Create", x) 187 | _r0 := _results.Error(0) 188 | return _r0 189 | } 190 | 191 | func (_expecter _BlankMock_Expecter) Create(x match.Arg[interface{}]) _BlankMock_Create_Call { 192 | return _BlankMock_Create_Call{Call: _expecter.mock.ExpectCall("Create", x.Matcher)} 193 | } 194 | 195 | func (_call _BlankMock_Create_Call) Return(_r0 error) _BlankMock_Create_Call { 196 | _call.Call.Return(_r0) 197 | return _call 198 | } 199 | 200 | func (_call _BlankMock_Create_Call) RunReturn(f func(x interface{}) (error)) _BlankMock_Create_Call { 201 | _call.Call.RunReturn(f) 202 | return _call 203 | } 204 | 205 | type ConsulLockMock struct { 206 | mock *mock.Mock 207 | } 208 | 209 | func NewConsulLockMock(t mock.Testing) *ConsulLockMock { 210 | t.Helper() 211 | return &ConsulLockMock{mock: mock.NewMock(t)} 212 | } 213 | 214 | type _ConsulLockMock_Expecter struct { 215 | mock *mock.Mock 216 | } 217 | 218 | func (_mock *ConsulLockMock) EXPECT() _ConsulLockMock_Expecter { 219 | return _ConsulLockMock_Expecter{mock: _mock.mock} 220 | } 221 | 222 | type _ConsulLockMock_Lock_Call struct { 223 | *mock.Call 224 | } 225 | 226 | func (_mock *ConsulLockMock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) { 227 | _mock.mock.T.Helper() 228 | _results := _mock.mock.Called("Lock", _a0) 229 | var _r0 <-chan struct{} 230 | if _got := _results.Get(0); _got != nil { 231 | _r0 = _got.(<-chan struct{}) 232 | } 233 | _r1 := _results.Error(1) 234 | return _r0, _r1 235 | } 236 | 237 | func (_expecter _ConsulLockMock_Expecter) Lock(_a0 match.Arg[<-chan struct{}]) _ConsulLockMock_Lock_Call { 238 | return _ConsulLockMock_Lock_Call{Call: _expecter.mock.ExpectCall("Lock", _a0.Matcher)} 239 | } 240 | 241 | func (_call _ConsulLockMock_Lock_Call) Return(_r0 <-chan struct{}, _r1 error) _ConsulLockMock_Lock_Call { 242 | _call.Call.Return(_r0, _r1) 243 | return _call 244 | } 245 | 246 | func (_call _ConsulLockMock_Lock_Call) RunReturn(f func(<-chan struct{}) (<-chan struct{}, error)) _ConsulLockMock_Lock_Call { 247 | _call.Call.RunReturn(f) 248 | return _call 249 | } 250 | 251 | type _ConsulLockMock_Unlock_Call struct { 252 | *mock.Call 253 | } 254 | 255 | func (_mock *ConsulLockMock) Unlock() (error) { 256 | _mock.mock.T.Helper() 257 | _results := _mock.mock.Called("Unlock", ) 258 | _r0 := _results.Error(0) 259 | return _r0 260 | } 261 | 262 | func (_expecter _ConsulLockMock_Expecter) Unlock() _ConsulLockMock_Unlock_Call { 263 | return _ConsulLockMock_Unlock_Call{Call: _expecter.mock.ExpectCall("Unlock", )} 264 | } 265 | 266 | func (_call _ConsulLockMock_Unlock_Call) Return(_r0 error) _ConsulLockMock_Unlock_Call { 267 | _call.Call.Return(_r0) 268 | return _call 269 | } 270 | 271 | func (_call _ConsulLockMock_Unlock_Call) RunReturn(f func() (error)) _ConsulLockMock_Unlock_Call { 272 | _call.Call.RunReturn(f) 273 | return _call 274 | } 275 | 276 | type ExampleMock struct { 277 | mock *mock.Mock 278 | } 279 | 280 | func NewExampleMock(t mock.Testing) *ExampleMock { 281 | t.Helper() 282 | return &ExampleMock{mock: mock.NewMock(t)} 283 | } 284 | 285 | type _ExampleMock_Expecter struct { 286 | mock *mock.Mock 287 | } 288 | 289 | func (_mock *ExampleMock) EXPECT() _ExampleMock_Expecter { 290 | return _ExampleMock_Expecter{mock: _mock.mock} 291 | } 292 | 293 | type _ExampleMock_A_Call struct { 294 | *mock.Call 295 | } 296 | 297 | func (_mock *ExampleMock) A() (net_http.Flusher) { 298 | _mock.mock.T.Helper() 299 | _results := _mock.mock.Called("A", ) 300 | var _r0 net_http.Flusher 301 | if _got := _results.Get(0); _got != nil { 302 | _r0 = _got.(net_http.Flusher) 303 | } 304 | return _r0 305 | } 306 | 307 | func (_expecter _ExampleMock_Expecter) A() _ExampleMock_A_Call { 308 | return _ExampleMock_A_Call{Call: _expecter.mock.ExpectCall("A", )} 309 | } 310 | 311 | func (_call _ExampleMock_A_Call) Return(_r0 net_http.Flusher) _ExampleMock_A_Call { 312 | _call.Call.Return(_r0) 313 | return _call 314 | } 315 | 316 | func (_call _ExampleMock_A_Call) RunReturn(f func() (net_http.Flusher)) _ExampleMock_A_Call { 317 | _call.Call.RunReturn(f) 318 | return _call 319 | } 320 | 321 | type _ExampleMock_B_Call struct { 322 | *mock.Call 323 | } 324 | 325 | func (_mock *ExampleMock) B(fixtureshttp string) (mockery_http.MyStruct) { 326 | _mock.mock.T.Helper() 327 | _results := _mock.mock.Called("B", fixtureshttp) 328 | _r0 := _results.Get(0).(mockery_http.MyStruct) 329 | return _r0 330 | } 331 | 332 | func (_expecter _ExampleMock_Expecter) B(fixtureshttp match.Arg[string]) _ExampleMock_B_Call { 333 | return _ExampleMock_B_Call{Call: _expecter.mock.ExpectCall("B", fixtureshttp.Matcher)} 334 | } 335 | 336 | func (_call _ExampleMock_B_Call) Return(_r0 mockery_http.MyStruct) _ExampleMock_B_Call { 337 | _call.Call.Return(_r0) 338 | return _call 339 | } 340 | 341 | func (_call _ExampleMock_B_Call) RunReturn(f func(fixtureshttp string) (mockery_http.MyStruct)) _ExampleMock_B_Call { 342 | _call.Call.RunReturn(f) 343 | return _call 344 | } 345 | 346 | type ExpecterTestMock struct { 347 | mock *mock.Mock 348 | } 349 | 350 | func NewExpecterTestMock(t mock.Testing) *ExpecterTestMock { 351 | t.Helper() 352 | return &ExpecterTestMock{mock: mock.NewMock(t)} 353 | } 354 | 355 | type _ExpecterTestMock_Expecter struct { 356 | mock *mock.Mock 357 | } 358 | 359 | func (_mock *ExpecterTestMock) EXPECT() _ExpecterTestMock_Expecter { 360 | return _ExpecterTestMock_Expecter{mock: _mock.mock} 361 | } 362 | 363 | type _ExpecterTestMock_ManyArgsReturns_Call struct { 364 | *mock.Call 365 | } 366 | 367 | func (_mock *ExpecterTestMock) ManyArgsReturns(str string, i int) (strs []string, err error) { 368 | _mock.mock.T.Helper() 369 | _results := _mock.mock.Called("ManyArgsReturns", str, i) 370 | var _r0 []string 371 | if _got := _results.Get(0); _got != nil { 372 | _r0 = _got.([]string) 373 | } 374 | _r1 := _results.Error(1) 375 | return _r0, _r1 376 | } 377 | 378 | func (_expecter _ExpecterTestMock_Expecter) ManyArgsReturns(str match.Arg[string], i match.Arg[int]) _ExpecterTestMock_ManyArgsReturns_Call { 379 | return _ExpecterTestMock_ManyArgsReturns_Call{Call: _expecter.mock.ExpectCall("ManyArgsReturns", str.Matcher, i.Matcher)} 380 | } 381 | 382 | func (_call _ExpecterTestMock_ManyArgsReturns_Call) Return(strs []string, err error) _ExpecterTestMock_ManyArgsReturns_Call { 383 | _call.Call.Return(strs, err) 384 | return _call 385 | } 386 | 387 | func (_call _ExpecterTestMock_ManyArgsReturns_Call) RunReturn(f func(str string, i int) (strs []string, err error)) _ExpecterTestMock_ManyArgsReturns_Call { 388 | _call.Call.RunReturn(f) 389 | return _call 390 | } 391 | 392 | type _ExpecterTestMock_NoArg_Call struct { 393 | *mock.Call 394 | } 395 | 396 | func (_mock *ExpecterTestMock) NoArg() (string) { 397 | _mock.mock.T.Helper() 398 | _results := _mock.mock.Called("NoArg", ) 399 | _r0 := _results.Get(0).(string) 400 | return _r0 401 | } 402 | 403 | func (_expecter _ExpecterTestMock_Expecter) NoArg() _ExpecterTestMock_NoArg_Call { 404 | return _ExpecterTestMock_NoArg_Call{Call: _expecter.mock.ExpectCall("NoArg", )} 405 | } 406 | 407 | func (_call _ExpecterTestMock_NoArg_Call) Return(_r0 string) _ExpecterTestMock_NoArg_Call { 408 | _call.Call.Return(_r0) 409 | return _call 410 | } 411 | 412 | func (_call _ExpecterTestMock_NoArg_Call) RunReturn(f func() (string)) _ExpecterTestMock_NoArg_Call { 413 | _call.Call.RunReturn(f) 414 | return _call 415 | } 416 | 417 | type _ExpecterTestMock_NoReturn_Call struct { 418 | *mock.Call 419 | } 420 | 421 | func (_mock *ExpecterTestMock) NoReturn(str string) () { 422 | _mock.mock.T.Helper() 423 | _mock.mock.Called("NoReturn", str) 424 | } 425 | 426 | func (_expecter _ExpecterTestMock_Expecter) NoReturn(str match.Arg[string]) _ExpecterTestMock_NoReturn_Call { 427 | return _ExpecterTestMock_NoReturn_Call{Call: _expecter.mock.ExpectCall("NoReturn", str.Matcher)} 428 | } 429 | 430 | func (_call _ExpecterTestMock_NoReturn_Call) Return() _ExpecterTestMock_NoReturn_Call { 431 | _call.Call.Return() 432 | return _call 433 | } 434 | 435 | func (_call _ExpecterTestMock_NoReturn_Call) RunReturn(f func(str string) ()) _ExpecterTestMock_NoReturn_Call { 436 | _call.Call.RunReturn(f) 437 | return _call 438 | } 439 | 440 | type _ExpecterTestMock_Variadic_Call struct { 441 | *mock.Call 442 | } 443 | 444 | func (_mock *ExpecterTestMock) Variadic(ints ...int) (error) { 445 | _mock.mock.T.Helper() 446 | _args := []any{mock.SliceToAnySlice(ints)} 447 | _results := _mock.mock.Called("Variadic", _args...) 448 | _r0 := _results.Error(0) 449 | return _r0 450 | } 451 | 452 | func (_expecter _ExpecterTestMock_Expecter) Variadic(ints ...match.Arg[int]) _ExpecterTestMock_Variadic_Call { 453 | _args := append([]mock.Matcher{}, match.ArgsToMatchers(ints)...) 454 | return _ExpecterTestMock_Variadic_Call{Call: _expecter.mock.ExpectCall("Variadic", _args...)} 455 | } 456 | 457 | func (_call _ExpecterTestMock_Variadic_Call) Return(_r0 error) _ExpecterTestMock_Variadic_Call { 458 | _call.Call.Return(_r0) 459 | return _call 460 | } 461 | 462 | func (_call _ExpecterTestMock_Variadic_Call) RunReturn(f func(ints ...int) (error)) _ExpecterTestMock_Variadic_Call { 463 | _call.Call.RunReturn(f) 464 | return _call 465 | } 466 | 467 | type _ExpecterTestMock_VariadicMany_Call struct { 468 | *mock.Call 469 | } 470 | 471 | func (_mock *ExpecterTestMock) VariadicMany(i int, a string, intfs ...interface{}) (error) { 472 | _mock.mock.T.Helper() 473 | _args := []any{i, a, mock.SliceToAnySlice(intfs)} 474 | _results := _mock.mock.Called("VariadicMany", _args...) 475 | _r0 := _results.Error(0) 476 | return _r0 477 | } 478 | 479 | func (_expecter _ExpecterTestMock_Expecter) VariadicMany(i match.Arg[int], a match.Arg[string], intfs ...match.Arg[interface{}]) _ExpecterTestMock_VariadicMany_Call { 480 | _args := append([]mock.Matcher{i.Matcher, a.Matcher}, match.ArgsToMatchers(intfs)...) 481 | return _ExpecterTestMock_VariadicMany_Call{Call: _expecter.mock.ExpectCall("VariadicMany", _args...)} 482 | } 483 | 484 | func (_call _ExpecterTestMock_VariadicMany_Call) Return(_r0 error) _ExpecterTestMock_VariadicMany_Call { 485 | _call.Call.Return(_r0) 486 | return _call 487 | } 488 | 489 | func (_call _ExpecterTestMock_VariadicMany_Call) RunReturn(f func(i int, a string, intfs ...interface{}) (error)) _ExpecterTestMock_VariadicMany_Call { 490 | _call.Call.RunReturn(f) 491 | return _call 492 | } 493 | 494 | type FooerMock struct { 495 | mock *mock.Mock 496 | } 497 | 498 | func NewFooerMock(t mock.Testing) *FooerMock { 499 | t.Helper() 500 | return &FooerMock{mock: mock.NewMock(t)} 501 | } 502 | 503 | type _FooerMock_Expecter struct { 504 | mock *mock.Mock 505 | } 506 | 507 | func (_mock *FooerMock) EXPECT() _FooerMock_Expecter { 508 | return _FooerMock_Expecter{mock: _mock.mock} 509 | } 510 | 511 | type _FooerMock_Bar_Call struct { 512 | *mock.Call 513 | } 514 | 515 | func (_mock *FooerMock) Bar(f func([]int)) () { 516 | _mock.mock.T.Helper() 517 | _mock.mock.Called("Bar", f) 518 | } 519 | 520 | func (_expecter _FooerMock_Expecter) Bar(f match.Arg[func([]int)]) _FooerMock_Bar_Call { 521 | return _FooerMock_Bar_Call{Call: _expecter.mock.ExpectCall("Bar", f.Matcher)} 522 | } 523 | 524 | func (_call _FooerMock_Bar_Call) Return() _FooerMock_Bar_Call { 525 | _call.Call.Return() 526 | return _call 527 | } 528 | 529 | func (_call _FooerMock_Bar_Call) RunReturn(f func(f func([]int)) ()) _FooerMock_Bar_Call { 530 | _call.Call.RunReturn(f) 531 | return _call 532 | } 533 | 534 | type _FooerMock_Baz_Call struct { 535 | *mock.Call 536 | } 537 | 538 | func (_mock *FooerMock) Baz(path string) (func(x string) string) { 539 | _mock.mock.T.Helper() 540 | _results := _mock.mock.Called("Baz", path) 541 | var _r0 func(x string) string 542 | if _got := _results.Get(0); _got != nil { 543 | _r0 = _got.(func(x string) string) 544 | } 545 | return _r0 546 | } 547 | 548 | func (_expecter _FooerMock_Expecter) Baz(path match.Arg[string]) _FooerMock_Baz_Call { 549 | return _FooerMock_Baz_Call{Call: _expecter.mock.ExpectCall("Baz", path.Matcher)} 550 | } 551 | 552 | func (_call _FooerMock_Baz_Call) Return(_r0 func(x string) string) _FooerMock_Baz_Call { 553 | _call.Call.Return(_r0) 554 | return _call 555 | } 556 | 557 | func (_call _FooerMock_Baz_Call) RunReturn(f func(path string) (func(x string) string)) _FooerMock_Baz_Call { 558 | _call.Call.RunReturn(f) 559 | return _call 560 | } 561 | 562 | type _FooerMock_Foo_Call struct { 563 | *mock.Call 564 | } 565 | 566 | func (_mock *FooerMock) Foo(f func(x string) string) (error) { 567 | _mock.mock.T.Helper() 568 | _results := _mock.mock.Called("Foo", f) 569 | _r0 := _results.Error(0) 570 | return _r0 571 | } 572 | 573 | func (_expecter _FooerMock_Expecter) Foo(f match.Arg[func(x string) string]) _FooerMock_Foo_Call { 574 | return _FooerMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", f.Matcher)} 575 | } 576 | 577 | func (_call _FooerMock_Foo_Call) Return(_r0 error) _FooerMock_Foo_Call { 578 | _call.Call.Return(_r0) 579 | return _call 580 | } 581 | 582 | func (_call _FooerMock_Foo_Call) RunReturn(f func(f func(x string) string) (error)) _FooerMock_Foo_Call { 583 | _call.Call.RunReturn(f) 584 | return _call 585 | } 586 | 587 | type FuncArgsCollisionMock struct { 588 | mock *mock.Mock 589 | } 590 | 591 | func NewFuncArgsCollisionMock(t mock.Testing) *FuncArgsCollisionMock { 592 | t.Helper() 593 | return &FuncArgsCollisionMock{mock: mock.NewMock(t)} 594 | } 595 | 596 | type _FuncArgsCollisionMock_Expecter struct { 597 | mock *mock.Mock 598 | } 599 | 600 | func (_mock *FuncArgsCollisionMock) EXPECT() _FuncArgsCollisionMock_Expecter { 601 | return _FuncArgsCollisionMock_Expecter{mock: _mock.mock} 602 | } 603 | 604 | type _FuncArgsCollisionMock_Foo_Call struct { 605 | *mock.Call 606 | } 607 | 608 | func (_mock *FuncArgsCollisionMock) Foo(ret interface{}) (error) { 609 | _mock.mock.T.Helper() 610 | _results := _mock.mock.Called("Foo", ret) 611 | _r0 := _results.Error(0) 612 | return _r0 613 | } 614 | 615 | func (_expecter _FuncArgsCollisionMock_Expecter) Foo(ret match.Arg[interface{}]) _FuncArgsCollisionMock_Foo_Call { 616 | return _FuncArgsCollisionMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", ret.Matcher)} 617 | } 618 | 619 | func (_call _FuncArgsCollisionMock_Foo_Call) Return(_r0 error) _FuncArgsCollisionMock_Foo_Call { 620 | _call.Call.Return(_r0) 621 | return _call 622 | } 623 | 624 | func (_call _FuncArgsCollisionMock_Foo_Call) RunReturn(f func(ret interface{}) (error)) _FuncArgsCollisionMock_Foo_Call { 625 | _call.Call.RunReturn(f) 626 | return _call 627 | } 628 | 629 | type HasConflictingNestedImportsMock struct { 630 | mock *mock.Mock 631 | } 632 | 633 | func NewHasConflictingNestedImportsMock(t mock.Testing) *HasConflictingNestedImportsMock { 634 | t.Helper() 635 | return &HasConflictingNestedImportsMock{mock: mock.NewMock(t)} 636 | } 637 | 638 | type _HasConflictingNestedImportsMock_Expecter struct { 639 | mock *mock.Mock 640 | } 641 | 642 | func (_mock *HasConflictingNestedImportsMock) EXPECT() _HasConflictingNestedImportsMock_Expecter { 643 | return _HasConflictingNestedImportsMock_Expecter{mock: _mock.mock} 644 | } 645 | 646 | type _HasConflictingNestedImportsMock_Get_Call struct { 647 | *mock.Call 648 | } 649 | 650 | func (_mock *HasConflictingNestedImportsMock) Get(path string) (net_http.Response, error) { 651 | _mock.mock.T.Helper() 652 | _results := _mock.mock.Called("Get", path) 653 | _r0 := _results.Get(0).(net_http.Response) 654 | _r1 := _results.Error(1) 655 | return _r0, _r1 656 | } 657 | 658 | func (_expecter _HasConflictingNestedImportsMock_Expecter) Get(path match.Arg[string]) _HasConflictingNestedImportsMock_Get_Call { 659 | return _HasConflictingNestedImportsMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 660 | } 661 | 662 | func (_call _HasConflictingNestedImportsMock_Get_Call) Return(_r0 net_http.Response, _r1 error) _HasConflictingNestedImportsMock_Get_Call { 663 | _call.Call.Return(_r0, _r1) 664 | return _call 665 | } 666 | 667 | func (_call _HasConflictingNestedImportsMock_Get_Call) RunReturn(f func(path string) (net_http.Response, error)) _HasConflictingNestedImportsMock_Get_Call { 668 | _call.Call.RunReturn(f) 669 | return _call 670 | } 671 | 672 | type _HasConflictingNestedImportsMock_Z_Call struct { 673 | *mock.Call 674 | } 675 | 676 | func (_mock *HasConflictingNestedImportsMock) Z() (mockery_http.MyStruct) { 677 | _mock.mock.T.Helper() 678 | _results := _mock.mock.Called("Z", ) 679 | _r0 := _results.Get(0).(mockery_http.MyStruct) 680 | return _r0 681 | } 682 | 683 | func (_expecter _HasConflictingNestedImportsMock_Expecter) Z() _HasConflictingNestedImportsMock_Z_Call { 684 | return _HasConflictingNestedImportsMock_Z_Call{Call: _expecter.mock.ExpectCall("Z", )} 685 | } 686 | 687 | func (_call _HasConflictingNestedImportsMock_Z_Call) Return(_r0 mockery_http.MyStruct) _HasConflictingNestedImportsMock_Z_Call { 688 | _call.Call.Return(_r0) 689 | return _call 690 | } 691 | 692 | func (_call _HasConflictingNestedImportsMock_Z_Call) RunReturn(f func() (mockery_http.MyStruct)) _HasConflictingNestedImportsMock_Z_Call { 693 | _call.Call.RunReturn(f) 694 | return _call 695 | } 696 | 697 | type ImportsSameAsPackageMock struct { 698 | mock *mock.Mock 699 | } 700 | 701 | func NewImportsSameAsPackageMock(t mock.Testing) *ImportsSameAsPackageMock { 702 | t.Helper() 703 | return &ImportsSameAsPackageMock{mock: mock.NewMock(t)} 704 | } 705 | 706 | type _ImportsSameAsPackageMock_Expecter struct { 707 | mock *mock.Mock 708 | } 709 | 710 | func (_mock *ImportsSameAsPackageMock) EXPECT() _ImportsSameAsPackageMock_Expecter { 711 | return _ImportsSameAsPackageMock_Expecter{mock: _mock.mock} 712 | } 713 | 714 | type _ImportsSameAsPackageMock_A_Call struct { 715 | *mock.Call 716 | } 717 | 718 | func (_mock *ImportsSameAsPackageMock) A() (mockery_mockery.B) { 719 | _mock.mock.T.Helper() 720 | _results := _mock.mock.Called("A", ) 721 | _r0 := _results.Get(0).(mockery_mockery.B) 722 | return _r0 723 | } 724 | 725 | func (_expecter _ImportsSameAsPackageMock_Expecter) A() _ImportsSameAsPackageMock_A_Call { 726 | return _ImportsSameAsPackageMock_A_Call{Call: _expecter.mock.ExpectCall("A", )} 727 | } 728 | 729 | func (_call _ImportsSameAsPackageMock_A_Call) Return(_r0 mockery_mockery.B) _ImportsSameAsPackageMock_A_Call { 730 | _call.Call.Return(_r0) 731 | return _call 732 | } 733 | 734 | func (_call _ImportsSameAsPackageMock_A_Call) RunReturn(f func() (mockery_mockery.B)) _ImportsSameAsPackageMock_A_Call { 735 | _call.Call.RunReturn(f) 736 | return _call 737 | } 738 | 739 | type _ImportsSameAsPackageMock_B_Call struct { 740 | *mock.Call 741 | } 742 | 743 | func (_mock *ImportsSameAsPackageMock) B() (KeyManager) { 744 | _mock.mock.T.Helper() 745 | _results := _mock.mock.Called("B", ) 746 | var _r0 KeyManager 747 | if _got := _results.Get(0); _got != nil { 748 | _r0 = _got.(KeyManager) 749 | } 750 | return _r0 751 | } 752 | 753 | func (_expecter _ImportsSameAsPackageMock_Expecter) B() _ImportsSameAsPackageMock_B_Call { 754 | return _ImportsSameAsPackageMock_B_Call{Call: _expecter.mock.ExpectCall("B", )} 755 | } 756 | 757 | func (_call _ImportsSameAsPackageMock_B_Call) Return(_r0 KeyManager) _ImportsSameAsPackageMock_B_Call { 758 | _call.Call.Return(_r0) 759 | return _call 760 | } 761 | 762 | func (_call _ImportsSameAsPackageMock_B_Call) RunReturn(f func() (KeyManager)) _ImportsSameAsPackageMock_B_Call { 763 | _call.Call.RunReturn(f) 764 | return _call 765 | } 766 | 767 | type _ImportsSameAsPackageMock_C_Call struct { 768 | *mock.Call 769 | } 770 | 771 | func (_mock *ImportsSameAsPackageMock) C(_a0 C) () { 772 | _mock.mock.T.Helper() 773 | _mock.mock.Called("C", _a0) 774 | } 775 | 776 | func (_expecter _ImportsSameAsPackageMock_Expecter) C(_a0 match.Arg[C]) _ImportsSameAsPackageMock_C_Call { 777 | return _ImportsSameAsPackageMock_C_Call{Call: _expecter.mock.ExpectCall("C", _a0.Matcher)} 778 | } 779 | 780 | func (_call _ImportsSameAsPackageMock_C_Call) Return() _ImportsSameAsPackageMock_C_Call { 781 | _call.Call.Return() 782 | return _call 783 | } 784 | 785 | func (_call _ImportsSameAsPackageMock_C_Call) RunReturn(f func(C) ()) _ImportsSameAsPackageMock_C_Call { 786 | _call.Call.RunReturn(f) 787 | return _call 788 | } 789 | 790 | type KeyManagerMock struct { 791 | mock *mock.Mock 792 | } 793 | 794 | func NewKeyManagerMock(t mock.Testing) *KeyManagerMock { 795 | t.Helper() 796 | return &KeyManagerMock{mock: mock.NewMock(t)} 797 | } 798 | 799 | type _KeyManagerMock_Expecter struct { 800 | mock *mock.Mock 801 | } 802 | 803 | func (_mock *KeyManagerMock) EXPECT() _KeyManagerMock_Expecter { 804 | return _KeyManagerMock_Expecter{mock: _mock.mock} 805 | } 806 | 807 | type _KeyManagerMock_GetKey_Call struct { 808 | *mock.Call 809 | } 810 | 811 | func (_mock *KeyManagerMock) GetKey(_a0 string, _a1 uint16) ([]byte, *Err) { 812 | _mock.mock.T.Helper() 813 | _results := _mock.mock.Called("GetKey", _a0, _a1) 814 | var _r0 []byte 815 | if _got := _results.Get(0); _got != nil { 816 | _r0 = _got.([]byte) 817 | } 818 | var _r1 *Err 819 | if _got := _results.Get(1); _got != nil { 820 | _r1 = _got.(*Err) 821 | } 822 | return _r0, _r1 823 | } 824 | 825 | func (_expecter _KeyManagerMock_Expecter) GetKey(_a0 match.Arg[string], _a1 match.Arg[uint16]) _KeyManagerMock_GetKey_Call { 826 | return _KeyManagerMock_GetKey_Call{Call: _expecter.mock.ExpectCall("GetKey", _a0.Matcher, _a1.Matcher)} 827 | } 828 | 829 | func (_call _KeyManagerMock_GetKey_Call) Return(_r0 []byte, _r1 *Err) _KeyManagerMock_GetKey_Call { 830 | _call.Call.Return(_r0, _r1) 831 | return _call 832 | } 833 | 834 | func (_call _KeyManagerMock_GetKey_Call) RunReturn(f func(string, uint16) ([]byte, *Err)) _KeyManagerMock_GetKey_Call { 835 | _call.Call.RunReturn(f) 836 | return _call 837 | } 838 | 839 | type MapFuncMock struct { 840 | mock *mock.Mock 841 | } 842 | 843 | func NewMapFuncMock(t mock.Testing) *MapFuncMock { 844 | t.Helper() 845 | return &MapFuncMock{mock: mock.NewMock(t)} 846 | } 847 | 848 | type _MapFuncMock_Expecter struct { 849 | mock *mock.Mock 850 | } 851 | 852 | func (_mock *MapFuncMock) EXPECT() _MapFuncMock_Expecter { 853 | return _MapFuncMock_Expecter{mock: _mock.mock} 854 | } 855 | 856 | type _MapFuncMock_Get_Call struct { 857 | *mock.Call 858 | } 859 | 860 | func (_mock *MapFuncMock) Get(m map[string]func(string) string) (error) { 861 | _mock.mock.T.Helper() 862 | _results := _mock.mock.Called("Get", m) 863 | _r0 := _results.Error(0) 864 | return _r0 865 | } 866 | 867 | func (_expecter _MapFuncMock_Expecter) Get(m match.Arg[map[string]func(string) string]) _MapFuncMock_Get_Call { 868 | return _MapFuncMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", m.Matcher)} 869 | } 870 | 871 | func (_call _MapFuncMock_Get_Call) Return(_r0 error) _MapFuncMock_Get_Call { 872 | _call.Call.Return(_r0) 873 | return _call 874 | } 875 | 876 | func (_call _MapFuncMock_Get_Call) RunReturn(f func(m map[string]func(string) string) (error)) _MapFuncMock_Get_Call { 877 | _call.Call.RunReturn(f) 878 | return _call 879 | } 880 | 881 | type MapToInterfaceMock struct { 882 | mock *mock.Mock 883 | } 884 | 885 | func NewMapToInterfaceMock(t mock.Testing) *MapToInterfaceMock { 886 | t.Helper() 887 | return &MapToInterfaceMock{mock: mock.NewMock(t)} 888 | } 889 | 890 | type _MapToInterfaceMock_Expecter struct { 891 | mock *mock.Mock 892 | } 893 | 894 | func (_mock *MapToInterfaceMock) EXPECT() _MapToInterfaceMock_Expecter { 895 | return _MapToInterfaceMock_Expecter{mock: _mock.mock} 896 | } 897 | 898 | type _MapToInterfaceMock_Foo_Call struct { 899 | *mock.Call 900 | } 901 | 902 | func (_mock *MapToInterfaceMock) Foo(arg1 ...map[string]interface{}) () { 903 | _mock.mock.T.Helper() 904 | _args := []any{mock.SliceToAnySlice(arg1)} 905 | _mock.mock.Called("Foo", _args...) 906 | } 907 | 908 | func (_expecter _MapToInterfaceMock_Expecter) Foo(arg1 ...match.Arg[map[string]interface{}]) _MapToInterfaceMock_Foo_Call { 909 | _args := append([]mock.Matcher{}, match.ArgsToMatchers(arg1)...) 910 | return _MapToInterfaceMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", _args...)} 911 | } 912 | 913 | func (_call _MapToInterfaceMock_Foo_Call) Return() _MapToInterfaceMock_Foo_Call { 914 | _call.Call.Return() 915 | return _call 916 | } 917 | 918 | func (_call _MapToInterfaceMock_Foo_Call) RunReturn(f func(arg1 ...map[string]interface{}) ()) _MapToInterfaceMock_Foo_Call { 919 | _call.Call.RunReturn(f) 920 | return _call 921 | } 922 | 923 | type MyReaderMock struct { 924 | mock *mock.Mock 925 | } 926 | 927 | func NewMyReaderMock(t mock.Testing) *MyReaderMock { 928 | t.Helper() 929 | return &MyReaderMock{mock: mock.NewMock(t)} 930 | } 931 | 932 | type _MyReaderMock_Expecter struct { 933 | mock *mock.Mock 934 | } 935 | 936 | func (_mock *MyReaderMock) EXPECT() _MyReaderMock_Expecter { 937 | return _MyReaderMock_Expecter{mock: _mock.mock} 938 | } 939 | 940 | type _MyReaderMock_Read_Call struct { 941 | *mock.Call 942 | } 943 | 944 | func (_mock *MyReaderMock) Read(p []byte) (n int, err error) { 945 | _mock.mock.T.Helper() 946 | _results := _mock.mock.Called("Read", p) 947 | _r0 := _results.Get(0).(int) 948 | _r1 := _results.Error(1) 949 | return _r0, _r1 950 | } 951 | 952 | func (_expecter _MyReaderMock_Expecter) Read(p match.Arg[[]byte]) _MyReaderMock_Read_Call { 953 | return _MyReaderMock_Read_Call{Call: _expecter.mock.ExpectCall("Read", p.Matcher)} 954 | } 955 | 956 | func (_call _MyReaderMock_Read_Call) Return(n int, err error) _MyReaderMock_Read_Call { 957 | _call.Call.Return(n, err) 958 | return _call 959 | } 960 | 961 | func (_call _MyReaderMock_Read_Call) RunReturn(f func(p []byte) (n int, err error)) _MyReaderMock_Read_Call { 962 | _call.Call.RunReturn(f) 963 | return _call 964 | } 965 | 966 | type RequesterMock struct { 967 | mock *mock.Mock 968 | } 969 | 970 | func NewRequesterMock(t mock.Testing) *RequesterMock { 971 | t.Helper() 972 | return &RequesterMock{mock: mock.NewMock(t)} 973 | } 974 | 975 | type _RequesterMock_Expecter struct { 976 | mock *mock.Mock 977 | } 978 | 979 | func (_mock *RequesterMock) EXPECT() _RequesterMock_Expecter { 980 | return _RequesterMock_Expecter{mock: _mock.mock} 981 | } 982 | 983 | type _RequesterMock_Get_Call struct { 984 | *mock.Call 985 | } 986 | 987 | func (_mock *RequesterMock) Get(path string) (string, error) { 988 | _mock.mock.T.Helper() 989 | _results := _mock.mock.Called("Get", path) 990 | _r0 := _results.Get(0).(string) 991 | _r1 := _results.Error(1) 992 | return _r0, _r1 993 | } 994 | 995 | func (_expecter _RequesterMock_Expecter) Get(path match.Arg[string]) _RequesterMock_Get_Call { 996 | return _RequesterMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 997 | } 998 | 999 | func (_call _RequesterMock_Get_Call) Return(_r0 string, _r1 error) _RequesterMock_Get_Call { 1000 | _call.Call.Return(_r0, _r1) 1001 | return _call 1002 | } 1003 | 1004 | func (_call _RequesterMock_Get_Call) RunReturn(f func(path string) (string, error)) _RequesterMock_Get_Call { 1005 | _call.Call.RunReturn(f) 1006 | return _call 1007 | } 1008 | 1009 | type Requester2Mock struct { 1010 | mock *mock.Mock 1011 | } 1012 | 1013 | func NewRequester2Mock(t mock.Testing) *Requester2Mock { 1014 | t.Helper() 1015 | return &Requester2Mock{mock: mock.NewMock(t)} 1016 | } 1017 | 1018 | type _Requester2Mock_Expecter struct { 1019 | mock *mock.Mock 1020 | } 1021 | 1022 | func (_mock *Requester2Mock) EXPECT() _Requester2Mock_Expecter { 1023 | return _Requester2Mock_Expecter{mock: _mock.mock} 1024 | } 1025 | 1026 | type _Requester2Mock_Get_Call struct { 1027 | *mock.Call 1028 | } 1029 | 1030 | func (_mock *Requester2Mock) Get(path string) (error) { 1031 | _mock.mock.T.Helper() 1032 | _results := _mock.mock.Called("Get", path) 1033 | _r0 := _results.Error(0) 1034 | return _r0 1035 | } 1036 | 1037 | func (_expecter _Requester2Mock_Expecter) Get(path match.Arg[string]) _Requester2Mock_Get_Call { 1038 | return _Requester2Mock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 1039 | } 1040 | 1041 | func (_call _Requester2Mock_Get_Call) Return(_r0 error) _Requester2Mock_Get_Call { 1042 | _call.Call.Return(_r0) 1043 | return _call 1044 | } 1045 | 1046 | func (_call _Requester2Mock_Get_Call) RunReturn(f func(path string) (error)) _Requester2Mock_Get_Call { 1047 | _call.Call.RunReturn(f) 1048 | return _call 1049 | } 1050 | 1051 | type Requester3Mock struct { 1052 | mock *mock.Mock 1053 | } 1054 | 1055 | func NewRequester3Mock(t mock.Testing) *Requester3Mock { 1056 | t.Helper() 1057 | return &Requester3Mock{mock: mock.NewMock(t)} 1058 | } 1059 | 1060 | type _Requester3Mock_Expecter struct { 1061 | mock *mock.Mock 1062 | } 1063 | 1064 | func (_mock *Requester3Mock) EXPECT() _Requester3Mock_Expecter { 1065 | return _Requester3Mock_Expecter{mock: _mock.mock} 1066 | } 1067 | 1068 | type _Requester3Mock_Get_Call struct { 1069 | *mock.Call 1070 | } 1071 | 1072 | func (_mock *Requester3Mock) Get() (error) { 1073 | _mock.mock.T.Helper() 1074 | _results := _mock.mock.Called("Get", ) 1075 | _r0 := _results.Error(0) 1076 | return _r0 1077 | } 1078 | 1079 | func (_expecter _Requester3Mock_Expecter) Get() _Requester3Mock_Get_Call { 1080 | return _Requester3Mock_Get_Call{Call: _expecter.mock.ExpectCall("Get", )} 1081 | } 1082 | 1083 | func (_call _Requester3Mock_Get_Call) Return(_r0 error) _Requester3Mock_Get_Call { 1084 | _call.Call.Return(_r0) 1085 | return _call 1086 | } 1087 | 1088 | func (_call _Requester3Mock_Get_Call) RunReturn(f func() (error)) _Requester3Mock_Get_Call { 1089 | _call.Call.RunReturn(f) 1090 | return _call 1091 | } 1092 | 1093 | type Requester4Mock struct { 1094 | mock *mock.Mock 1095 | } 1096 | 1097 | func NewRequester4Mock(t mock.Testing) *Requester4Mock { 1098 | t.Helper() 1099 | return &Requester4Mock{mock: mock.NewMock(t)} 1100 | } 1101 | 1102 | type _Requester4Mock_Expecter struct { 1103 | mock *mock.Mock 1104 | } 1105 | 1106 | func (_mock *Requester4Mock) EXPECT() _Requester4Mock_Expecter { 1107 | return _Requester4Mock_Expecter{mock: _mock.mock} 1108 | } 1109 | 1110 | type _Requester4Mock_Get_Call struct { 1111 | *mock.Call 1112 | } 1113 | 1114 | func (_mock *Requester4Mock) Get() () { 1115 | _mock.mock.T.Helper() 1116 | _mock.mock.Called("Get", ) 1117 | } 1118 | 1119 | func (_expecter _Requester4Mock_Expecter) Get() _Requester4Mock_Get_Call { 1120 | return _Requester4Mock_Get_Call{Call: _expecter.mock.ExpectCall("Get", )} 1121 | } 1122 | 1123 | func (_call _Requester4Mock_Get_Call) Return() _Requester4Mock_Get_Call { 1124 | _call.Call.Return() 1125 | return _call 1126 | } 1127 | 1128 | func (_call _Requester4Mock_Get_Call) RunReturn(f func() ()) _Requester4Mock_Get_Call { 1129 | _call.Call.RunReturn(f) 1130 | return _call 1131 | } 1132 | 1133 | type RequesterArgSameAsImportMock struct { 1134 | mock *mock.Mock 1135 | } 1136 | 1137 | func NewRequesterArgSameAsImportMock(t mock.Testing) *RequesterArgSameAsImportMock { 1138 | t.Helper() 1139 | return &RequesterArgSameAsImportMock{mock: mock.NewMock(t)} 1140 | } 1141 | 1142 | type _RequesterArgSameAsImportMock_Expecter struct { 1143 | mock *mock.Mock 1144 | } 1145 | 1146 | func (_mock *RequesterArgSameAsImportMock) EXPECT() _RequesterArgSameAsImportMock_Expecter { 1147 | return _RequesterArgSameAsImportMock_Expecter{mock: _mock.mock} 1148 | } 1149 | 1150 | type _RequesterArgSameAsImportMock_Get_Call struct { 1151 | *mock.Call 1152 | } 1153 | 1154 | func (_mock *RequesterArgSameAsImportMock) Get(_a0 string) (*json.RawMessage) { 1155 | _mock.mock.T.Helper() 1156 | _results := _mock.mock.Called("Get", _a0) 1157 | var _r0 *json.RawMessage 1158 | if _got := _results.Get(0); _got != nil { 1159 | _r0 = _got.(*json.RawMessage) 1160 | } 1161 | return _r0 1162 | } 1163 | 1164 | func (_expecter _RequesterArgSameAsImportMock_Expecter) Get(_a0 match.Arg[string]) _RequesterArgSameAsImportMock_Get_Call { 1165 | return _RequesterArgSameAsImportMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", _a0.Matcher)} 1166 | } 1167 | 1168 | func (_call _RequesterArgSameAsImportMock_Get_Call) Return(_r0 *json.RawMessage) _RequesterArgSameAsImportMock_Get_Call { 1169 | _call.Call.Return(_r0) 1170 | return _call 1171 | } 1172 | 1173 | func (_call _RequesterArgSameAsImportMock_Get_Call) RunReturn(f func(json string) (*json.RawMessage)) _RequesterArgSameAsImportMock_Get_Call { 1174 | _call.Call.RunReturn(f) 1175 | return _call 1176 | } 1177 | 1178 | type RequesterArgSameAsNamedImportMock struct { 1179 | mock *mock.Mock 1180 | } 1181 | 1182 | func NewRequesterArgSameAsNamedImportMock(t mock.Testing) *RequesterArgSameAsNamedImportMock { 1183 | t.Helper() 1184 | return &RequesterArgSameAsNamedImportMock{mock: mock.NewMock(t)} 1185 | } 1186 | 1187 | type _RequesterArgSameAsNamedImportMock_Expecter struct { 1188 | mock *mock.Mock 1189 | } 1190 | 1191 | func (_mock *RequesterArgSameAsNamedImportMock) EXPECT() _RequesterArgSameAsNamedImportMock_Expecter { 1192 | return _RequesterArgSameAsNamedImportMock_Expecter{mock: _mock.mock} 1193 | } 1194 | 1195 | type _RequesterArgSameAsNamedImportMock_Get_Call struct { 1196 | *mock.Call 1197 | } 1198 | 1199 | func (_mock *RequesterArgSameAsNamedImportMock) Get(_a0 string) (*json.RawMessage) { 1200 | _mock.mock.T.Helper() 1201 | _results := _mock.mock.Called("Get", _a0) 1202 | var _r0 *json.RawMessage 1203 | if _got := _results.Get(0); _got != nil { 1204 | _r0 = _got.(*json.RawMessage) 1205 | } 1206 | return _r0 1207 | } 1208 | 1209 | func (_expecter _RequesterArgSameAsNamedImportMock_Expecter) Get(_a0 match.Arg[string]) _RequesterArgSameAsNamedImportMock_Get_Call { 1210 | return _RequesterArgSameAsNamedImportMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", _a0.Matcher)} 1211 | } 1212 | 1213 | func (_call _RequesterArgSameAsNamedImportMock_Get_Call) Return(_r0 *json.RawMessage) _RequesterArgSameAsNamedImportMock_Get_Call { 1214 | _call.Call.Return(_r0) 1215 | return _call 1216 | } 1217 | 1218 | func (_call _RequesterArgSameAsNamedImportMock_Get_Call) RunReturn(f func(json string) (*json.RawMessage)) _RequesterArgSameAsNamedImportMock_Get_Call { 1219 | _call.Call.RunReturn(f) 1220 | return _call 1221 | } 1222 | 1223 | type RequesterArgSameAsPkgMock struct { 1224 | mock *mock.Mock 1225 | } 1226 | 1227 | func NewRequesterArgSameAsPkgMock(t mock.Testing) *RequesterArgSameAsPkgMock { 1228 | t.Helper() 1229 | return &RequesterArgSameAsPkgMock{mock: mock.NewMock(t)} 1230 | } 1231 | 1232 | type _RequesterArgSameAsPkgMock_Expecter struct { 1233 | mock *mock.Mock 1234 | } 1235 | 1236 | func (_mock *RequesterArgSameAsPkgMock) EXPECT() _RequesterArgSameAsPkgMock_Expecter { 1237 | return _RequesterArgSameAsPkgMock_Expecter{mock: _mock.mock} 1238 | } 1239 | 1240 | type _RequesterArgSameAsPkgMock_Get_Call struct { 1241 | *mock.Call 1242 | } 1243 | 1244 | func (_mock *RequesterArgSameAsPkgMock) Get(test string) () { 1245 | _mock.mock.T.Helper() 1246 | _mock.mock.Called("Get", test) 1247 | } 1248 | 1249 | func (_expecter _RequesterArgSameAsPkgMock_Expecter) Get(test match.Arg[string]) _RequesterArgSameAsPkgMock_Get_Call { 1250 | return _RequesterArgSameAsPkgMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", test.Matcher)} 1251 | } 1252 | 1253 | func (_call _RequesterArgSameAsPkgMock_Get_Call) Return() _RequesterArgSameAsPkgMock_Get_Call { 1254 | _call.Call.Return() 1255 | return _call 1256 | } 1257 | 1258 | func (_call _RequesterArgSameAsPkgMock_Get_Call) RunReturn(f func(test string) ()) _RequesterArgSameAsPkgMock_Get_Call { 1259 | _call.Call.RunReturn(f) 1260 | return _call 1261 | } 1262 | 1263 | type RequesterArrayMock struct { 1264 | mock *mock.Mock 1265 | } 1266 | 1267 | func NewRequesterArrayMock(t mock.Testing) *RequesterArrayMock { 1268 | t.Helper() 1269 | return &RequesterArrayMock{mock: mock.NewMock(t)} 1270 | } 1271 | 1272 | type _RequesterArrayMock_Expecter struct { 1273 | mock *mock.Mock 1274 | } 1275 | 1276 | func (_mock *RequesterArrayMock) EXPECT() _RequesterArrayMock_Expecter { 1277 | return _RequesterArrayMock_Expecter{mock: _mock.mock} 1278 | } 1279 | 1280 | type _RequesterArrayMock_Get_Call struct { 1281 | *mock.Call 1282 | } 1283 | 1284 | func (_mock *RequesterArrayMock) Get(path string) ([2]string, error) { 1285 | _mock.mock.T.Helper() 1286 | _results := _mock.mock.Called("Get", path) 1287 | var _r0 [2]string 1288 | if _got := _results.Get(0); _got != nil { 1289 | _r0 = _got.([2]string) 1290 | } 1291 | _r1 := _results.Error(1) 1292 | return _r0, _r1 1293 | } 1294 | 1295 | func (_expecter _RequesterArrayMock_Expecter) Get(path match.Arg[string]) _RequesterArrayMock_Get_Call { 1296 | return _RequesterArrayMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 1297 | } 1298 | 1299 | func (_call _RequesterArrayMock_Get_Call) Return(_r0 [2]string, _r1 error) _RequesterArrayMock_Get_Call { 1300 | _call.Call.Return(_r0, _r1) 1301 | return _call 1302 | } 1303 | 1304 | func (_call _RequesterArrayMock_Get_Call) RunReturn(f func(path string) ([2]string, error)) _RequesterArrayMock_Get_Call { 1305 | _call.Call.RunReturn(f) 1306 | return _call 1307 | } 1308 | 1309 | type RequesterElidedMock struct { 1310 | mock *mock.Mock 1311 | } 1312 | 1313 | func NewRequesterElidedMock(t mock.Testing) *RequesterElidedMock { 1314 | t.Helper() 1315 | return &RequesterElidedMock{mock: mock.NewMock(t)} 1316 | } 1317 | 1318 | type _RequesterElidedMock_Expecter struct { 1319 | mock *mock.Mock 1320 | } 1321 | 1322 | func (_mock *RequesterElidedMock) EXPECT() _RequesterElidedMock_Expecter { 1323 | return _RequesterElidedMock_Expecter{mock: _mock.mock} 1324 | } 1325 | 1326 | type _RequesterElidedMock_Get_Call struct { 1327 | *mock.Call 1328 | } 1329 | 1330 | func (_mock *RequesterElidedMock) Get(path string, url string) (error) { 1331 | _mock.mock.T.Helper() 1332 | _results := _mock.mock.Called("Get", path, url) 1333 | _r0 := _results.Error(0) 1334 | return _r0 1335 | } 1336 | 1337 | func (_expecter _RequesterElidedMock_Expecter) Get(path match.Arg[string], url match.Arg[string]) _RequesterElidedMock_Get_Call { 1338 | return _RequesterElidedMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher, url.Matcher)} 1339 | } 1340 | 1341 | func (_call _RequesterElidedMock_Get_Call) Return(_r0 error) _RequesterElidedMock_Get_Call { 1342 | _call.Call.Return(_r0) 1343 | return _call 1344 | } 1345 | 1346 | func (_call _RequesterElidedMock_Get_Call) RunReturn(f func(path string, url string) (error)) _RequesterElidedMock_Get_Call { 1347 | _call.Call.RunReturn(f) 1348 | return _call 1349 | } 1350 | 1351 | type RequesterIfaceMock struct { 1352 | mock *mock.Mock 1353 | } 1354 | 1355 | func NewRequesterIfaceMock(t mock.Testing) *RequesterIfaceMock { 1356 | t.Helper() 1357 | return &RequesterIfaceMock{mock: mock.NewMock(t)} 1358 | } 1359 | 1360 | type _RequesterIfaceMock_Expecter struct { 1361 | mock *mock.Mock 1362 | } 1363 | 1364 | func (_mock *RequesterIfaceMock) EXPECT() _RequesterIfaceMock_Expecter { 1365 | return _RequesterIfaceMock_Expecter{mock: _mock.mock} 1366 | } 1367 | 1368 | type _RequesterIfaceMock_Get_Call struct { 1369 | *mock.Call 1370 | } 1371 | 1372 | func (_mock *RequesterIfaceMock) Get() (io.Reader) { 1373 | _mock.mock.T.Helper() 1374 | _results := _mock.mock.Called("Get", ) 1375 | var _r0 io.Reader 1376 | if _got := _results.Get(0); _got != nil { 1377 | _r0 = _got.(io.Reader) 1378 | } 1379 | return _r0 1380 | } 1381 | 1382 | func (_expecter _RequesterIfaceMock_Expecter) Get() _RequesterIfaceMock_Get_Call { 1383 | return _RequesterIfaceMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", )} 1384 | } 1385 | 1386 | func (_call _RequesterIfaceMock_Get_Call) Return(_r0 io.Reader) _RequesterIfaceMock_Get_Call { 1387 | _call.Call.Return(_r0) 1388 | return _call 1389 | } 1390 | 1391 | func (_call _RequesterIfaceMock_Get_Call) RunReturn(f func() (io.Reader)) _RequesterIfaceMock_Get_Call { 1392 | _call.Call.RunReturn(f) 1393 | return _call 1394 | } 1395 | 1396 | type RequesterNSMock struct { 1397 | mock *mock.Mock 1398 | } 1399 | 1400 | func NewRequesterNSMock(t mock.Testing) *RequesterNSMock { 1401 | t.Helper() 1402 | return &RequesterNSMock{mock: mock.NewMock(t)} 1403 | } 1404 | 1405 | type _RequesterNSMock_Expecter struct { 1406 | mock *mock.Mock 1407 | } 1408 | 1409 | func (_mock *RequesterNSMock) EXPECT() _RequesterNSMock_Expecter { 1410 | return _RequesterNSMock_Expecter{mock: _mock.mock} 1411 | } 1412 | 1413 | type _RequesterNSMock_Get_Call struct { 1414 | *mock.Call 1415 | } 1416 | 1417 | func (_mock *RequesterNSMock) Get(path string) (net_http.Response, error) { 1418 | _mock.mock.T.Helper() 1419 | _results := _mock.mock.Called("Get", path) 1420 | _r0 := _results.Get(0).(net_http.Response) 1421 | _r1 := _results.Error(1) 1422 | return _r0, _r1 1423 | } 1424 | 1425 | func (_expecter _RequesterNSMock_Expecter) Get(path match.Arg[string]) _RequesterNSMock_Get_Call { 1426 | return _RequesterNSMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 1427 | } 1428 | 1429 | func (_call _RequesterNSMock_Get_Call) Return(_r0 net_http.Response, _r1 error) _RequesterNSMock_Get_Call { 1430 | _call.Call.Return(_r0, _r1) 1431 | return _call 1432 | } 1433 | 1434 | func (_call _RequesterNSMock_Get_Call) RunReturn(f func(path string) (net_http.Response, error)) _RequesterNSMock_Get_Call { 1435 | _call.Call.RunReturn(f) 1436 | return _call 1437 | } 1438 | 1439 | type RequesterPtrMock struct { 1440 | mock *mock.Mock 1441 | } 1442 | 1443 | func NewRequesterPtrMock(t mock.Testing) *RequesterPtrMock { 1444 | t.Helper() 1445 | return &RequesterPtrMock{mock: mock.NewMock(t)} 1446 | } 1447 | 1448 | type _RequesterPtrMock_Expecter struct { 1449 | mock *mock.Mock 1450 | } 1451 | 1452 | func (_mock *RequesterPtrMock) EXPECT() _RequesterPtrMock_Expecter { 1453 | return _RequesterPtrMock_Expecter{mock: _mock.mock} 1454 | } 1455 | 1456 | type _RequesterPtrMock_Get_Call struct { 1457 | *mock.Call 1458 | } 1459 | 1460 | func (_mock *RequesterPtrMock) Get(path string) (*string, error) { 1461 | _mock.mock.T.Helper() 1462 | _results := _mock.mock.Called("Get", path) 1463 | var _r0 *string 1464 | if _got := _results.Get(0); _got != nil { 1465 | _r0 = _got.(*string) 1466 | } 1467 | _r1 := _results.Error(1) 1468 | return _r0, _r1 1469 | } 1470 | 1471 | func (_expecter _RequesterPtrMock_Expecter) Get(path match.Arg[string]) _RequesterPtrMock_Get_Call { 1472 | return _RequesterPtrMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 1473 | } 1474 | 1475 | func (_call _RequesterPtrMock_Get_Call) Return(_r0 *string, _r1 error) _RequesterPtrMock_Get_Call { 1476 | _call.Call.Return(_r0, _r1) 1477 | return _call 1478 | } 1479 | 1480 | func (_call _RequesterPtrMock_Get_Call) RunReturn(f func(path string) (*string, error)) _RequesterPtrMock_Get_Call { 1481 | _call.Call.RunReturn(f) 1482 | return _call 1483 | } 1484 | 1485 | type RequesterReturnElidedMock struct { 1486 | mock *mock.Mock 1487 | } 1488 | 1489 | func NewRequesterReturnElidedMock(t mock.Testing) *RequesterReturnElidedMock { 1490 | t.Helper() 1491 | return &RequesterReturnElidedMock{mock: mock.NewMock(t)} 1492 | } 1493 | 1494 | type _RequesterReturnElidedMock_Expecter struct { 1495 | mock *mock.Mock 1496 | } 1497 | 1498 | func (_mock *RequesterReturnElidedMock) EXPECT() _RequesterReturnElidedMock_Expecter { 1499 | return _RequesterReturnElidedMock_Expecter{mock: _mock.mock} 1500 | } 1501 | 1502 | type _RequesterReturnElidedMock_Get_Call struct { 1503 | *mock.Call 1504 | } 1505 | 1506 | func (_mock *RequesterReturnElidedMock) Get(path string) (a int, b int, c int, err error) { 1507 | _mock.mock.T.Helper() 1508 | _results := _mock.mock.Called("Get", path) 1509 | _r0 := _results.Get(0).(int) 1510 | _r1 := _results.Get(1).(int) 1511 | _r2 := _results.Get(2).(int) 1512 | _r3 := _results.Error(3) 1513 | return _r0, _r1, _r2, _r3 1514 | } 1515 | 1516 | func (_expecter _RequesterReturnElidedMock_Expecter) Get(path match.Arg[string]) _RequesterReturnElidedMock_Get_Call { 1517 | return _RequesterReturnElidedMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 1518 | } 1519 | 1520 | func (_call _RequesterReturnElidedMock_Get_Call) Return(a int, b int, c int, err error) _RequesterReturnElidedMock_Get_Call { 1521 | _call.Call.Return(a, b, c, err) 1522 | return _call 1523 | } 1524 | 1525 | func (_call _RequesterReturnElidedMock_Get_Call) RunReturn(f func(path string) (a int, b int, c int, err error)) _RequesterReturnElidedMock_Get_Call { 1526 | _call.Call.RunReturn(f) 1527 | return _call 1528 | } 1529 | 1530 | type RequesterSliceMock struct { 1531 | mock *mock.Mock 1532 | } 1533 | 1534 | func NewRequesterSliceMock(t mock.Testing) *RequesterSliceMock { 1535 | t.Helper() 1536 | return &RequesterSliceMock{mock: mock.NewMock(t)} 1537 | } 1538 | 1539 | type _RequesterSliceMock_Expecter struct { 1540 | mock *mock.Mock 1541 | } 1542 | 1543 | func (_mock *RequesterSliceMock) EXPECT() _RequesterSliceMock_Expecter { 1544 | return _RequesterSliceMock_Expecter{mock: _mock.mock} 1545 | } 1546 | 1547 | type _RequesterSliceMock_Get_Call struct { 1548 | *mock.Call 1549 | } 1550 | 1551 | func (_mock *RequesterSliceMock) Get(path string) ([]string, error) { 1552 | _mock.mock.T.Helper() 1553 | _results := _mock.mock.Called("Get", path) 1554 | var _r0 []string 1555 | if _got := _results.Get(0); _got != nil { 1556 | _r0 = _got.([]string) 1557 | } 1558 | _r1 := _results.Error(1) 1559 | return _r0, _r1 1560 | } 1561 | 1562 | func (_expecter _RequesterSliceMock_Expecter) Get(path match.Arg[string]) _RequesterSliceMock_Get_Call { 1563 | return _RequesterSliceMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", path.Matcher)} 1564 | } 1565 | 1566 | func (_call _RequesterSliceMock_Get_Call) Return(_r0 []string, _r1 error) _RequesterSliceMock_Get_Call { 1567 | _call.Call.Return(_r0, _r1) 1568 | return _call 1569 | } 1570 | 1571 | func (_call _RequesterSliceMock_Get_Call) RunReturn(f func(path string) ([]string, error)) _RequesterSliceMock_Get_Call { 1572 | _call.Call.RunReturn(f) 1573 | return _call 1574 | } 1575 | 1576 | type RequesterVariadicMock struct { 1577 | mock *mock.Mock 1578 | } 1579 | 1580 | func NewRequesterVariadicMock(t mock.Testing) *RequesterVariadicMock { 1581 | t.Helper() 1582 | return &RequesterVariadicMock{mock: mock.NewMock(t)} 1583 | } 1584 | 1585 | type _RequesterVariadicMock_Expecter struct { 1586 | mock *mock.Mock 1587 | } 1588 | 1589 | func (_mock *RequesterVariadicMock) EXPECT() _RequesterVariadicMock_Expecter { 1590 | return _RequesterVariadicMock_Expecter{mock: _mock.mock} 1591 | } 1592 | 1593 | type _RequesterVariadicMock_Get_Call struct { 1594 | *mock.Call 1595 | } 1596 | 1597 | func (_mock *RequesterVariadicMock) Get(values ...string) (bool) { 1598 | _mock.mock.T.Helper() 1599 | _args := []any{mock.SliceToAnySlice(values)} 1600 | _results := _mock.mock.Called("Get", _args...) 1601 | _r0 := _results.Get(0).(bool) 1602 | return _r0 1603 | } 1604 | 1605 | func (_expecter _RequesterVariadicMock_Expecter) Get(values ...match.Arg[string]) _RequesterVariadicMock_Get_Call { 1606 | _args := append([]mock.Matcher{}, match.ArgsToMatchers(values)...) 1607 | return _RequesterVariadicMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", _args...)} 1608 | } 1609 | 1610 | func (_call _RequesterVariadicMock_Get_Call) Return(_r0 bool) _RequesterVariadicMock_Get_Call { 1611 | _call.Call.Return(_r0) 1612 | return _call 1613 | } 1614 | 1615 | func (_call _RequesterVariadicMock_Get_Call) RunReturn(f func(values ...string) (bool)) _RequesterVariadicMock_Get_Call { 1616 | _call.Call.RunReturn(f) 1617 | return _call 1618 | } 1619 | 1620 | type _RequesterVariadicMock_MultiWriteToFile_Call struct { 1621 | *mock.Call 1622 | } 1623 | 1624 | func (_mock *RequesterVariadicMock) MultiWriteToFile(filename string, w ...io.Writer) (string) { 1625 | _mock.mock.T.Helper() 1626 | _args := []any{filename, mock.SliceToAnySlice(w)} 1627 | _results := _mock.mock.Called("MultiWriteToFile", _args...) 1628 | _r0 := _results.Get(0).(string) 1629 | return _r0 1630 | } 1631 | 1632 | func (_expecter _RequesterVariadicMock_Expecter) MultiWriteToFile(filename match.Arg[string], w ...match.Arg[io.Writer]) _RequesterVariadicMock_MultiWriteToFile_Call { 1633 | _args := append([]mock.Matcher{filename.Matcher}, match.ArgsToMatchers(w)...) 1634 | return _RequesterVariadicMock_MultiWriteToFile_Call{Call: _expecter.mock.ExpectCall("MultiWriteToFile", _args...)} 1635 | } 1636 | 1637 | func (_call _RequesterVariadicMock_MultiWriteToFile_Call) Return(_r0 string) _RequesterVariadicMock_MultiWriteToFile_Call { 1638 | _call.Call.Return(_r0) 1639 | return _call 1640 | } 1641 | 1642 | func (_call _RequesterVariadicMock_MultiWriteToFile_Call) RunReturn(f func(filename string, w ...io.Writer) (string)) _RequesterVariadicMock_MultiWriteToFile_Call { 1643 | _call.Call.RunReturn(f) 1644 | return _call 1645 | } 1646 | 1647 | type _RequesterVariadicMock_OneInterface_Call struct { 1648 | *mock.Call 1649 | } 1650 | 1651 | func (_mock *RequesterVariadicMock) OneInterface(a ...interface{}) (bool) { 1652 | _mock.mock.T.Helper() 1653 | _args := []any{mock.SliceToAnySlice(a)} 1654 | _results := _mock.mock.Called("OneInterface", _args...) 1655 | _r0 := _results.Get(0).(bool) 1656 | return _r0 1657 | } 1658 | 1659 | func (_expecter _RequesterVariadicMock_Expecter) OneInterface(a ...match.Arg[interface{}]) _RequesterVariadicMock_OneInterface_Call { 1660 | _args := append([]mock.Matcher{}, match.ArgsToMatchers(a)...) 1661 | return _RequesterVariadicMock_OneInterface_Call{Call: _expecter.mock.ExpectCall("OneInterface", _args...)} 1662 | } 1663 | 1664 | func (_call _RequesterVariadicMock_OneInterface_Call) Return(_r0 bool) _RequesterVariadicMock_OneInterface_Call { 1665 | _call.Call.Return(_r0) 1666 | return _call 1667 | } 1668 | 1669 | func (_call _RequesterVariadicMock_OneInterface_Call) RunReturn(f func(a ...interface{}) (bool)) _RequesterVariadicMock_OneInterface_Call { 1670 | _call.Call.RunReturn(f) 1671 | return _call 1672 | } 1673 | 1674 | type _RequesterVariadicMock_Sprintf_Call struct { 1675 | *mock.Call 1676 | } 1677 | 1678 | func (_mock *RequesterVariadicMock) Sprintf(format string, a ...interface{}) (string) { 1679 | _mock.mock.T.Helper() 1680 | _args := []any{format, mock.SliceToAnySlice(a)} 1681 | _results := _mock.mock.Called("Sprintf", _args...) 1682 | _r0 := _results.Get(0).(string) 1683 | return _r0 1684 | } 1685 | 1686 | func (_expecter _RequesterVariadicMock_Expecter) Sprintf(format match.Arg[string], a ...match.Arg[interface{}]) _RequesterVariadicMock_Sprintf_Call { 1687 | _args := append([]mock.Matcher{format.Matcher}, match.ArgsToMatchers(a)...) 1688 | return _RequesterVariadicMock_Sprintf_Call{Call: _expecter.mock.ExpectCall("Sprintf", _args...)} 1689 | } 1690 | 1691 | func (_call _RequesterVariadicMock_Sprintf_Call) Return(_r0 string) _RequesterVariadicMock_Sprintf_Call { 1692 | _call.Call.Return(_r0) 1693 | return _call 1694 | } 1695 | 1696 | func (_call _RequesterVariadicMock_Sprintf_Call) RunReturn(f func(format string, a ...interface{}) (string)) _RequesterVariadicMock_Sprintf_Call { 1697 | _call.Call.RunReturn(f) 1698 | return _call 1699 | } 1700 | 1701 | type SendFuncMock struct { 1702 | mock *mock.Mock 1703 | } 1704 | 1705 | func NewSendFuncMock(t mock.Testing) *SendFuncMock { 1706 | t.Helper() 1707 | return &SendFuncMock{mock: mock.NewMock(t)} 1708 | } 1709 | 1710 | type _SendFuncMock_Expecter struct { 1711 | mock *mock.Mock 1712 | } 1713 | 1714 | func (_mock *SendFuncMock) EXPECT() _SendFuncMock_Expecter { 1715 | return _SendFuncMock_Expecter{mock: _mock.mock} 1716 | } 1717 | 1718 | type _SendFuncMock_Execute_Call struct { 1719 | *mock.Call 1720 | } 1721 | 1722 | func (_mock *SendFuncMock) Execute(ctx context.Context, data string) (int, error) { 1723 | _mock.mock.T.Helper() 1724 | _results := _mock.mock.Called("Execute", ctx, data) 1725 | _r0 := _results.Get(0).(int) 1726 | _r1 := _results.Error(1) 1727 | return _r0, _r1 1728 | } 1729 | 1730 | func (_expecter _SendFuncMock_Expecter) Execute(ctx match.Arg[context.Context], data match.Arg[string]) _SendFuncMock_Execute_Call { 1731 | return _SendFuncMock_Execute_Call{Call: _expecter.mock.ExpectCall("Execute", ctx.Matcher, data.Matcher)} 1732 | } 1733 | 1734 | func (_call _SendFuncMock_Execute_Call) Return(_r0 int, _r1 error) _SendFuncMock_Execute_Call { 1735 | _call.Call.Return(_r0, _r1) 1736 | return _call 1737 | } 1738 | 1739 | func (_call _SendFuncMock_Execute_Call) RunReturn(f func(ctx context.Context, data string) (int, error)) _SendFuncMock_Execute_Call { 1740 | _call.Call.RunReturn(f) 1741 | return _call 1742 | } 1743 | 1744 | type SiblingMock struct { 1745 | mock *mock.Mock 1746 | } 1747 | 1748 | func NewSiblingMock(t mock.Testing) *SiblingMock { 1749 | t.Helper() 1750 | return &SiblingMock{mock: mock.NewMock(t)} 1751 | } 1752 | 1753 | type _SiblingMock_Expecter struct { 1754 | mock *mock.Mock 1755 | } 1756 | 1757 | func (_mock *SiblingMock) EXPECT() _SiblingMock_Expecter { 1758 | return _SiblingMock_Expecter{mock: _mock.mock} 1759 | } 1760 | 1761 | type _SiblingMock_DoSomething_Call struct { 1762 | *mock.Call 1763 | } 1764 | 1765 | func (_mock *SiblingMock) DoSomething() () { 1766 | _mock.mock.T.Helper() 1767 | _mock.mock.Called("DoSomething", ) 1768 | } 1769 | 1770 | func (_expecter _SiblingMock_Expecter) DoSomething() _SiblingMock_DoSomething_Call { 1771 | return _SiblingMock_DoSomething_Call{Call: _expecter.mock.ExpectCall("DoSomething", )} 1772 | } 1773 | 1774 | func (_call _SiblingMock_DoSomething_Call) Return() _SiblingMock_DoSomething_Call { 1775 | _call.Call.Return() 1776 | return _call 1777 | } 1778 | 1779 | func (_call _SiblingMock_DoSomething_Call) RunReturn(f func() ()) _SiblingMock_DoSomething_Call { 1780 | _call.Call.RunReturn(f) 1781 | return _call 1782 | } 1783 | 1784 | type UnsafeInterfaceMock struct { 1785 | mock *mock.Mock 1786 | } 1787 | 1788 | func NewUnsafeInterfaceMock(t mock.Testing) *UnsafeInterfaceMock { 1789 | t.Helper() 1790 | return &UnsafeInterfaceMock{mock: mock.NewMock(t)} 1791 | } 1792 | 1793 | type _UnsafeInterfaceMock_Expecter struct { 1794 | mock *mock.Mock 1795 | } 1796 | 1797 | func (_mock *UnsafeInterfaceMock) EXPECT() _UnsafeInterfaceMock_Expecter { 1798 | return _UnsafeInterfaceMock_Expecter{mock: _mock.mock} 1799 | } 1800 | 1801 | type _UnsafeInterfaceMock_Do_Call struct { 1802 | *mock.Call 1803 | } 1804 | 1805 | func (_mock *UnsafeInterfaceMock) Do(ptr *unsafe.Pointer) () { 1806 | _mock.mock.T.Helper() 1807 | _mock.mock.Called("Do", ptr) 1808 | } 1809 | 1810 | func (_expecter _UnsafeInterfaceMock_Expecter) Do(ptr match.Arg[*unsafe.Pointer]) _UnsafeInterfaceMock_Do_Call { 1811 | return _UnsafeInterfaceMock_Do_Call{Call: _expecter.mock.ExpectCall("Do", ptr.Matcher)} 1812 | } 1813 | 1814 | func (_call _UnsafeInterfaceMock_Do_Call) Return() _UnsafeInterfaceMock_Do_Call { 1815 | _call.Call.Return() 1816 | return _call 1817 | } 1818 | 1819 | func (_call _UnsafeInterfaceMock_Do_Call) RunReturn(f func(ptr *unsafe.Pointer) ()) _UnsafeInterfaceMock_Do_Call { 1820 | _call.Call.RunReturn(f) 1821 | return _call 1822 | } 1823 | 1824 | type UsesOtherPkgIfaceMock struct { 1825 | mock *mock.Mock 1826 | } 1827 | 1828 | func NewUsesOtherPkgIfaceMock(t mock.Testing) *UsesOtherPkgIfaceMock { 1829 | t.Helper() 1830 | return &UsesOtherPkgIfaceMock{mock: mock.NewMock(t)} 1831 | } 1832 | 1833 | type _UsesOtherPkgIfaceMock_Expecter struct { 1834 | mock *mock.Mock 1835 | } 1836 | 1837 | func (_mock *UsesOtherPkgIfaceMock) EXPECT() _UsesOtherPkgIfaceMock_Expecter { 1838 | return _UsesOtherPkgIfaceMock_Expecter{mock: _mock.mock} 1839 | } 1840 | 1841 | type _UsesOtherPkgIfaceMock_DoSomethingElse_Call struct { 1842 | *mock.Call 1843 | } 1844 | 1845 | func (_mock *UsesOtherPkgIfaceMock) DoSomethingElse(obj Sibling) () { 1846 | _mock.mock.T.Helper() 1847 | _mock.mock.Called("DoSomethingElse", obj) 1848 | } 1849 | 1850 | func (_expecter _UsesOtherPkgIfaceMock_Expecter) DoSomethingElse(obj match.Arg[Sibling]) _UsesOtherPkgIfaceMock_DoSomethingElse_Call { 1851 | return _UsesOtherPkgIfaceMock_DoSomethingElse_Call{Call: _expecter.mock.ExpectCall("DoSomethingElse", obj.Matcher)} 1852 | } 1853 | 1854 | func (_call _UsesOtherPkgIfaceMock_DoSomethingElse_Call) Return() _UsesOtherPkgIfaceMock_DoSomethingElse_Call { 1855 | _call.Call.Return() 1856 | return _call 1857 | } 1858 | 1859 | func (_call _UsesOtherPkgIfaceMock_DoSomethingElse_Call) RunReturn(f func(obj Sibling) ()) _UsesOtherPkgIfaceMock_DoSomethingElse_Call { 1860 | _call.Call.RunReturn(f) 1861 | return _call 1862 | } 1863 | 1864 | type Requester_unexportedMock struct { 1865 | mock *mock.Mock 1866 | } 1867 | 1868 | func NewRequester_unexportedMock(t mock.Testing) *Requester_unexportedMock { 1869 | t.Helper() 1870 | return &Requester_unexportedMock{mock: mock.NewMock(t)} 1871 | } 1872 | 1873 | type _Requester_unexportedMock_Expecter struct { 1874 | mock *mock.Mock 1875 | } 1876 | 1877 | func (_mock *Requester_unexportedMock) EXPECT() _Requester_unexportedMock_Expecter { 1878 | return _Requester_unexportedMock_Expecter{mock: _mock.mock} 1879 | } 1880 | 1881 | type _Requester_unexportedMock_Get_Call struct { 1882 | *mock.Call 1883 | } 1884 | 1885 | func (_mock *Requester_unexportedMock) Get() () { 1886 | _mock.mock.T.Helper() 1887 | _mock.mock.Called("Get", ) 1888 | } 1889 | 1890 | func (_expecter _Requester_unexportedMock_Expecter) Get() _Requester_unexportedMock_Get_Call { 1891 | return _Requester_unexportedMock_Get_Call{Call: _expecter.mock.ExpectCall("Get", )} 1892 | } 1893 | 1894 | func (_call _Requester_unexportedMock_Get_Call) Return() _Requester_unexportedMock_Get_Call { 1895 | _call.Call.Return() 1896 | return _call 1897 | } 1898 | 1899 | func (_call _Requester_unexportedMock_Get_Call) RunReturn(f func() ()) _Requester_unexportedMock_Get_Call { 1900 | _call.Call.RunReturn(f) 1901 | return _call 1902 | } 1903 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Requester interface { 4 | Get(path string) (string, error) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester2.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Requester2 interface { 4 | Get(path string) error 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester3.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Requester3 interface { 4 | Get() error 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester4.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type Requester4 interface { 4 | Get() 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_arg_same_as_import.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "encoding/json" 4 | 5 | type RequesterArgSameAsImport interface { 6 | Get(json string) *json.RawMessage 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_arg_same_as_named_import.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "encoding/json" 4 | 5 | type RequesterArgSameAsNamedImport interface { 6 | Get(json string) *json.RawMessage 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_arg_same_as_pkg.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type RequesterArgSameAsPkg interface { 4 | Get(test string) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_array.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type RequesterArray interface { 4 | Get(path string) ([2]string, error) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_elided.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type RequesterElided interface { 4 | Get(path, url string) error 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_iface.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "io" 4 | 5 | type RequesterIface interface { 6 | Get() io.Reader 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_ns.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "net/http" 4 | 5 | type RequesterNS interface { 6 | Get(path string) (http.Response, error) 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_ptr.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type RequesterPtr interface { 4 | Get(path string) (*string, error) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_ret_elided.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type RequesterReturnElided interface { 4 | Get(path string) (a, b, c int, err error) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_slice.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type RequesterSlice interface { 4 | Get(path string) ([]string, error) 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_unexported.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type requester_unexported interface { 4 | Get() 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/requester_variadic.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "io" 4 | 5 | type RequesterVariadic interface { 6 | // cases: only variadic argument, w/ and w/out interface type 7 | Get(values ...string) bool 8 | OneInterface(a ...interface{}) bool 9 | 10 | // cases: normal argument + variadic argument, w/ and w/o interface type 11 | Sprintf(format string, a ...interface{}) string 12 | MultiWriteToFile(filename string, w ...io.Writer) string 13 | } 14 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/same_name_imports.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import ( 4 | "net/http" 5 | 6 | my_http "github.com/subtle-byte/mockigo/internal/fixtures/mockery/http" 7 | ) 8 | 9 | // Example is an example 10 | type Example interface { 11 | A() http.Flusher 12 | B(fixtureshttp string) my_http.MyStruct 13 | } 14 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/struct_value.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | type B struct{} 4 | 5 | type A interface { 6 | Call() (B, error) 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/mockery/unsafe.go: -------------------------------------------------------------------------------- 1 | package mockery 2 | 3 | import "unsafe" 4 | 5 | type UnsafeInterface interface { 6 | Do(ptr *unsafe.Pointer) 7 | } 8 | -------------------------------------------------------------------------------- /internal/fixtures/our/foo_bar.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | import "time" 4 | 5 | type FooBar interface { 6 | Foo(a int) int 7 | Bar(t time.Duration) 8 | } 9 | 10 | type BarFoo interface { 11 | Foo(int, string) int 12 | Bar(int) string 13 | } 14 | -------------------------------------------------------------------------------- /internal/fixtures/our/generic.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | import someinterface "github.com/subtle-byte/mockigo/internal/fixtures/our/some-interface" 4 | 5 | type GenericInterface[T any, B someinterface.SomeInterface, G ~int | float32] interface { 6 | SomeMethod(B) T 7 | } 8 | 9 | type GenericFunc[Y someinterface.SomeInterface] func() Y 10 | 11 | type GenericComparable[T comparable] func() T 12 | -------------------------------------------------------------------------------- /internal/fixtures/our/mocks_test.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate mockigo 4 | 5 | package fixtures 6 | 7 | import html_template "html/template" 8 | import match "github.com/subtle-byte/mockigo/match" 9 | import mock "github.com/subtle-byte/mockigo/mock" 10 | import someinterface "github.com/subtle-byte/mockigo/internal/fixtures/our/some-interface" 11 | import text_template "text/template" 12 | import time "time" 13 | 14 | var _ = match.Any[int] 15 | 16 | type BarFooMock struct { 17 | mock *mock.Mock 18 | } 19 | 20 | func NewBarFooMock(t mock.Testing) *BarFooMock { 21 | t.Helper() 22 | return &BarFooMock{mock: mock.NewMock(t)} 23 | } 24 | 25 | type _BarFooMock_Expecter struct { 26 | mock *mock.Mock 27 | } 28 | 29 | func (_mock *BarFooMock) EXPECT() _BarFooMock_Expecter { 30 | return _BarFooMock_Expecter{mock: _mock.mock} 31 | } 32 | 33 | type _BarFooMock_Bar_Call struct { 34 | *mock.Call 35 | } 36 | 37 | func (_mock *BarFooMock) Bar(_a0 int) (string) { 38 | _mock.mock.T.Helper() 39 | _results := _mock.mock.Called("Bar", _a0) 40 | _r0 := _results.Get(0).(string) 41 | return _r0 42 | } 43 | 44 | func (_expecter _BarFooMock_Expecter) Bar(_a0 match.Arg[int]) _BarFooMock_Bar_Call { 45 | return _BarFooMock_Bar_Call{Call: _expecter.mock.ExpectCall("Bar", _a0.Matcher)} 46 | } 47 | 48 | func (_call _BarFooMock_Bar_Call) Return(_r0 string) _BarFooMock_Bar_Call { 49 | _call.Call.Return(_r0) 50 | return _call 51 | } 52 | 53 | func (_call _BarFooMock_Bar_Call) RunReturn(f func(int) (string)) _BarFooMock_Bar_Call { 54 | _call.Call.RunReturn(f) 55 | return _call 56 | } 57 | 58 | type _BarFooMock_Foo_Call struct { 59 | *mock.Call 60 | } 61 | 62 | func (_mock *BarFooMock) Foo(_a0 int, _a1 string) (int) { 63 | _mock.mock.T.Helper() 64 | _results := _mock.mock.Called("Foo", _a0, _a1) 65 | _r0 := _results.Get(0).(int) 66 | return _r0 67 | } 68 | 69 | func (_expecter _BarFooMock_Expecter) Foo(_a0 match.Arg[int], _a1 match.Arg[string]) _BarFooMock_Foo_Call { 70 | return _BarFooMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", _a0.Matcher, _a1.Matcher)} 71 | } 72 | 73 | func (_call _BarFooMock_Foo_Call) Return(_r0 int) _BarFooMock_Foo_Call { 74 | _call.Call.Return(_r0) 75 | return _call 76 | } 77 | 78 | func (_call _BarFooMock_Foo_Call) RunReturn(f func(int, string) (int)) _BarFooMock_Foo_Call { 79 | _call.Call.RunReturn(f) 80 | return _call 81 | } 82 | 83 | type FooBarMock struct { 84 | mock *mock.Mock 85 | } 86 | 87 | func NewFooBarMock(t mock.Testing) *FooBarMock { 88 | t.Helper() 89 | return &FooBarMock{mock: mock.NewMock(t)} 90 | } 91 | 92 | type _FooBarMock_Expecter struct { 93 | mock *mock.Mock 94 | } 95 | 96 | func (_mock *FooBarMock) EXPECT() _FooBarMock_Expecter { 97 | return _FooBarMock_Expecter{mock: _mock.mock} 98 | } 99 | 100 | type _FooBarMock_Bar_Call struct { 101 | *mock.Call 102 | } 103 | 104 | func (_mock *FooBarMock) Bar(t time.Duration) () { 105 | _mock.mock.T.Helper() 106 | _mock.mock.Called("Bar", t) 107 | } 108 | 109 | func (_expecter _FooBarMock_Expecter) Bar(t match.Arg[time.Duration]) _FooBarMock_Bar_Call { 110 | return _FooBarMock_Bar_Call{Call: _expecter.mock.ExpectCall("Bar", t.Matcher)} 111 | } 112 | 113 | func (_call _FooBarMock_Bar_Call) Return() _FooBarMock_Bar_Call { 114 | _call.Call.Return() 115 | return _call 116 | } 117 | 118 | func (_call _FooBarMock_Bar_Call) RunReturn(f func(t time.Duration) ()) _FooBarMock_Bar_Call { 119 | _call.Call.RunReturn(f) 120 | return _call 121 | } 122 | 123 | type _FooBarMock_Foo_Call struct { 124 | *mock.Call 125 | } 126 | 127 | func (_mock *FooBarMock) Foo(a int) (int) { 128 | _mock.mock.T.Helper() 129 | _results := _mock.mock.Called("Foo", a) 130 | _r0 := _results.Get(0).(int) 131 | return _r0 132 | } 133 | 134 | func (_expecter _FooBarMock_Expecter) Foo(a match.Arg[int]) _FooBarMock_Foo_Call { 135 | return _FooBarMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", a.Matcher)} 136 | } 137 | 138 | func (_call _FooBarMock_Foo_Call) Return(_r0 int) _FooBarMock_Foo_Call { 139 | _call.Call.Return(_r0) 140 | return _call 141 | } 142 | 143 | func (_call _FooBarMock_Foo_Call) RunReturn(f func(a int) (int)) _FooBarMock_Foo_Call { 144 | _call.Call.RunReturn(f) 145 | return _call 146 | } 147 | 148 | type GenericComparableMock[T comparable] struct { 149 | mock *mock.Mock 150 | } 151 | 152 | func NewGenericComparableMock[T comparable](t mock.Testing) *GenericComparableMock[T] { 153 | t.Helper() 154 | return &GenericComparableMock[T]{mock: mock.NewMock(t)} 155 | } 156 | 157 | type _GenericComparableMock_Expecter[T comparable] struct { 158 | mock *mock.Mock 159 | } 160 | 161 | func (_mock *GenericComparableMock[T]) EXPECT() _GenericComparableMock_Expecter[T] { 162 | return _GenericComparableMock_Expecter[T]{mock: _mock.mock} 163 | } 164 | 165 | type _GenericComparableMock_Execute_Call[T comparable] struct { 166 | *mock.Call 167 | } 168 | 169 | func (_mock *GenericComparableMock[T]) Execute() (T) { 170 | _mock.mock.T.Helper() 171 | _results := _mock.mock.Called("Execute", ) 172 | _r0 := _results.Get(0).(T) 173 | return _r0 174 | } 175 | 176 | func (_expecter _GenericComparableMock_Expecter[T]) Execute() _GenericComparableMock_Execute_Call[T] { 177 | return _GenericComparableMock_Execute_Call[T]{Call: _expecter.mock.ExpectCall("Execute", )} 178 | } 179 | 180 | func (_call _GenericComparableMock_Execute_Call[T]) Return(_r0 T) _GenericComparableMock_Execute_Call[T] { 181 | _call.Call.Return(_r0) 182 | return _call 183 | } 184 | 185 | func (_call _GenericComparableMock_Execute_Call[T]) RunReturn(f func() (T)) _GenericComparableMock_Execute_Call[T] { 186 | _call.Call.RunReturn(f) 187 | return _call 188 | } 189 | 190 | type GenericFuncMock[Y someinterface.SomeInterface] struct { 191 | mock *mock.Mock 192 | } 193 | 194 | func NewGenericFuncMock[Y someinterface.SomeInterface](t mock.Testing) *GenericFuncMock[Y] { 195 | t.Helper() 196 | return &GenericFuncMock[Y]{mock: mock.NewMock(t)} 197 | } 198 | 199 | type _GenericFuncMock_Expecter[Y someinterface.SomeInterface] struct { 200 | mock *mock.Mock 201 | } 202 | 203 | func (_mock *GenericFuncMock[Y]) EXPECT() _GenericFuncMock_Expecter[Y] { 204 | return _GenericFuncMock_Expecter[Y]{mock: _mock.mock} 205 | } 206 | 207 | type _GenericFuncMock_Execute_Call[Y someinterface.SomeInterface] struct { 208 | *mock.Call 209 | } 210 | 211 | func (_mock *GenericFuncMock[Y]) Execute() (Y) { 212 | _mock.mock.T.Helper() 213 | _results := _mock.mock.Called("Execute", ) 214 | _r0 := _results.Get(0).(Y) 215 | return _r0 216 | } 217 | 218 | func (_expecter _GenericFuncMock_Expecter[Y]) Execute() _GenericFuncMock_Execute_Call[Y] { 219 | return _GenericFuncMock_Execute_Call[Y]{Call: _expecter.mock.ExpectCall("Execute", )} 220 | } 221 | 222 | func (_call _GenericFuncMock_Execute_Call[Y]) Return(_r0 Y) _GenericFuncMock_Execute_Call[Y] { 223 | _call.Call.Return(_r0) 224 | return _call 225 | } 226 | 227 | func (_call _GenericFuncMock_Execute_Call[Y]) RunReturn(f func() (Y)) _GenericFuncMock_Execute_Call[Y] { 228 | _call.Call.RunReturn(f) 229 | return _call 230 | } 231 | 232 | type GenericInterfaceMock[T any, B someinterface.SomeInterface, G ~int | float32] struct { 233 | mock *mock.Mock 234 | } 235 | 236 | func NewGenericInterfaceMock[T any, B someinterface.SomeInterface, G ~int | float32](t mock.Testing) *GenericInterfaceMock[T, B, G] { 237 | t.Helper() 238 | return &GenericInterfaceMock[T, B, G]{mock: mock.NewMock(t)} 239 | } 240 | 241 | type _GenericInterfaceMock_Expecter[T any, B someinterface.SomeInterface, G ~int | float32] struct { 242 | mock *mock.Mock 243 | } 244 | 245 | func (_mock *GenericInterfaceMock[T, B, G]) EXPECT() _GenericInterfaceMock_Expecter[T, B, G] { 246 | return _GenericInterfaceMock_Expecter[T, B, G]{mock: _mock.mock} 247 | } 248 | 249 | type _GenericInterfaceMock_SomeMethod_Call[T any, B someinterface.SomeInterface, G ~int | float32] struct { 250 | *mock.Call 251 | } 252 | 253 | func (_mock *GenericInterfaceMock[T, B, G]) SomeMethod(_a0 B) (T) { 254 | _mock.mock.T.Helper() 255 | _results := _mock.mock.Called("SomeMethod", _a0) 256 | _r0 := _results.Get(0).(T) 257 | return _r0 258 | } 259 | 260 | func (_expecter _GenericInterfaceMock_Expecter[T, B, G]) SomeMethod(_a0 match.Arg[B]) _GenericInterfaceMock_SomeMethod_Call[T, B, G] { 261 | return _GenericInterfaceMock_SomeMethod_Call[T, B, G]{Call: _expecter.mock.ExpectCall("SomeMethod", _a0.Matcher)} 262 | } 263 | 264 | func (_call _GenericInterfaceMock_SomeMethod_Call[T, B, G]) Return(_r0 T) _GenericInterfaceMock_SomeMethod_Call[T, B, G] { 265 | _call.Call.Return(_r0) 266 | return _call 267 | } 268 | 269 | func (_call _GenericInterfaceMock_SomeMethod_Call[T, B, G]) RunReturn(f func(B) (T)) _GenericInterfaceMock_SomeMethod_Call[T, B, G] { 270 | _call.Call.RunReturn(f) 271 | return _call 272 | } 273 | 274 | type SimpleInterfaceMock struct { 275 | mock *mock.Mock 276 | } 277 | 278 | func NewSimpleInterfaceMock(t mock.Testing) *SimpleInterfaceMock { 279 | t.Helper() 280 | return &SimpleInterfaceMock{mock: mock.NewMock(t)} 281 | } 282 | 283 | type _SimpleInterfaceMock_Expecter struct { 284 | mock *mock.Mock 285 | } 286 | 287 | func (_mock *SimpleInterfaceMock) EXPECT() _SimpleInterfaceMock_Expecter { 288 | return _SimpleInterfaceMock_Expecter{mock: _mock.mock} 289 | } 290 | 291 | type _SimpleInterfaceMock_Bar_Call struct { 292 | *mock.Call 293 | } 294 | 295 | func (_mock *SimpleInterfaceMock) Bar(i int) (int) { 296 | _mock.mock.T.Helper() 297 | _results := _mock.mock.Called("Bar", i) 298 | _r0 := _results.Get(0).(int) 299 | return _r0 300 | } 301 | 302 | func (_expecter _SimpleInterfaceMock_Expecter) Bar(i match.Arg[int]) _SimpleInterfaceMock_Bar_Call { 303 | return _SimpleInterfaceMock_Bar_Call{Call: _expecter.mock.ExpectCall("Bar", i.Matcher)} 304 | } 305 | 306 | func (_call _SimpleInterfaceMock_Bar_Call) Return(_r0 int) _SimpleInterfaceMock_Bar_Call { 307 | _call.Call.Return(_r0) 308 | return _call 309 | } 310 | 311 | func (_call _SimpleInterfaceMock_Bar_Call) RunReturn(f func(i int) (int)) _SimpleInterfaceMock_Bar_Call { 312 | _call.Call.RunReturn(f) 313 | return _call 314 | } 315 | 316 | type SomeInterfaceMock struct { 317 | mock *mock.Mock 318 | } 319 | 320 | func NewSomeInterfaceMock(t mock.Testing) *SomeInterfaceMock { 321 | t.Helper() 322 | return &SomeInterfaceMock{mock: mock.NewMock(t)} 323 | } 324 | 325 | type _SomeInterfaceMock_Expecter struct { 326 | mock *mock.Mock 327 | } 328 | 329 | func (_mock *SomeInterfaceMock) EXPECT() _SomeInterfaceMock_Expecter { 330 | return _SomeInterfaceMock_Expecter{mock: _mock.mock} 331 | } 332 | 333 | type _SomeInterfaceMock_Foo_Call struct { 334 | *mock.Call 335 | } 336 | 337 | func (_mock *SomeInterfaceMock) Foo(i text_template.Template) (html_template.Template) { 338 | _mock.mock.T.Helper() 339 | _results := _mock.mock.Called("Foo", i) 340 | _r0 := _results.Get(0).(html_template.Template) 341 | return _r0 342 | } 343 | 344 | func (_expecter _SomeInterfaceMock_Expecter) Foo(i match.Arg[text_template.Template]) _SomeInterfaceMock_Foo_Call { 345 | return _SomeInterfaceMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", i.Matcher)} 346 | } 347 | 348 | func (_call _SomeInterfaceMock_Foo_Call) Return(_r0 html_template.Template) _SomeInterfaceMock_Foo_Call { 349 | _call.Call.Return(_r0) 350 | return _call 351 | } 352 | 353 | func (_call _SomeInterfaceMock_Foo_Call) RunReturn(f func(i text_template.Template) (html_template.Template)) _SomeInterfaceMock_Foo_Call { 354 | _call.Call.RunReturn(f) 355 | return _call 356 | } 357 | 358 | type VariadicMock struct { 359 | mock *mock.Mock 360 | } 361 | 362 | func NewVariadicMock(t mock.Testing) *VariadicMock { 363 | t.Helper() 364 | return &VariadicMock{mock: mock.NewMock(t)} 365 | } 366 | 367 | type _VariadicMock_Expecter struct { 368 | mock *mock.Mock 369 | } 370 | 371 | func (_mock *VariadicMock) EXPECT() _VariadicMock_Expecter { 372 | return _VariadicMock_Expecter{mock: _mock.mock} 373 | } 374 | 375 | type _VariadicMock_SomeMethod_Call struct { 376 | *mock.Call 377 | } 378 | 379 | func (_mock *VariadicMock) SomeMethod(a int, b ...string) (bool) { 380 | _mock.mock.T.Helper() 381 | _args := []any{a, mock.SliceToAnySlice(b)} 382 | _results := _mock.mock.Called("SomeMethod", _args...) 383 | _r0 := _results.Get(0).(bool) 384 | return _r0 385 | } 386 | 387 | func (_expecter _VariadicMock_Expecter) SomeMethod(a match.Arg[int], b ...match.Arg[string]) _VariadicMock_SomeMethod_Call { 388 | _args := append([]mock.Matcher{a.Matcher}, match.ArgsToMatchers(b)...) 389 | return _VariadicMock_SomeMethod_Call{Call: _expecter.mock.ExpectCall("SomeMethod", _args...)} 390 | } 391 | 392 | func (_call _VariadicMock_SomeMethod_Call) Return(_r0 bool) _VariadicMock_SomeMethod_Call { 393 | _call.Call.Return(_r0) 394 | return _call 395 | } 396 | 397 | func (_call _VariadicMock_SomeMethod_Call) RunReturn(f func(a int, b ...string) (bool)) _VariadicMock_SomeMethod_Call { 398 | _call.Call.RunReturn(f) 399 | return _call 400 | } 401 | -------------------------------------------------------------------------------- /internal/fixtures/our/simple.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | type SimpleInterface interface { 4 | Bar(i int) int 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/our/some-interface/some_interface.go: -------------------------------------------------------------------------------- 1 | package some_interface 2 | 3 | type SomeInterface interface { 4 | SomeMethod() int 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/our/tester_test.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | import ( 4 | html_template "html/template" 5 | "strconv" 6 | "testing" 7 | text_template "text/template" 8 | "time" 9 | 10 | "github.com/stretchr/testify/assert" 11 | "github.com/stretchr/testify/require" 12 | "github.com/subtle-byte/mockigo/match" 13 | "github.com/subtle-byte/mockigo/mock" 14 | ) 15 | 16 | func TestSimpleInterface(t *testing.T) { 17 | simple := NewSimpleInterfaceMock(t) 18 | 19 | mock.InOrder( 20 | simple.EXPECT(). 21 | Bar(match.MatchedBy(func(i int) bool { 22 | return i > 5 23 | })). 24 | RunReturn(func(i int) int { 25 | return i - 5 26 | }). 27 | Times(1, 1), 28 | simple.EXPECT(). 29 | Bar(match.Any[int]()). 30 | Return(0), 31 | ) 32 | require.Equal(t, 3, simple.Bar(8)) 33 | require.Equal(t, 0, simple.Bar(8)) 34 | require.Equal(t, 0, simple.Bar(2)) 35 | } 36 | 37 | func TestSomeInterface(t *testing.T) { 38 | someInterface := NewSomeInterfaceMock(t) 39 | 40 | var textTemplate text_template.Template = text_template.Template{} 41 | var htmlTemplate html_template.Template = html_template.Template{} 42 | 43 | someInterface.EXPECT(). 44 | Foo(match.Eq(textTemplate)). 45 | Return(htmlTemplate) 46 | 47 | var returnedHtmlTemplate html_template.Template = someInterface.Foo(textTemplate) 48 | 49 | require.Equal(t, htmlTemplate, returnedHtmlTemplate) 50 | } 51 | 52 | func TestFooBar(t *testing.T) { 53 | fb := NewFooBarMock(t) 54 | mock.InOrder( 55 | fb.EXPECT().Foo(match.Eq(7)).Return(8), 56 | fb.EXPECT().Bar(match.Eq(time.Second)), 57 | ) 58 | assert.Equal(t, 8, fb.Foo(7)) 59 | fb.Bar(time.Second) 60 | } 61 | 62 | func TestBarFoo(t *testing.T) { 63 | m := NewBarFooMock(t) 64 | mock.InOrder( 65 | m.EXPECT().Foo(match.Any[int](), match.Eq("hello")).Return(45), 66 | m.EXPECT().Bar(match.Any[int]()).RunReturn(func(n int) string { 67 | return strconv.Itoa(n) 68 | }), 69 | ) 70 | assert.Equal(t, 45, m.Foo(100, "hello")) 71 | assert.Equal(t, "200", m.Bar(200)) 72 | } 73 | -------------------------------------------------------------------------------- /internal/fixtures/our/variadic.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | type Variadic interface { 4 | SomeMethod(a int, b ...string) bool 5 | } 6 | -------------------------------------------------------------------------------- /internal/fixtures/our/with_same_pkg_name.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | import ( 4 | h "html/template" 5 | t "text/template" 6 | ) 7 | 8 | type SomeInterface interface { 9 | Foo(i t.Template) h.Template 10 | } 11 | -------------------------------------------------------------------------------- /internal/generator/generator.go: -------------------------------------------------------------------------------- 1 | package generator 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "go/types" 7 | "log" 8 | "sort" 9 | "strconv" 10 | "strings" 11 | 12 | "github.com/subtle-byte/mockigo/internal/generator/path_trie" 13 | "github.com/subtle-byte/mockigo/internal/util" 14 | "golang.org/x/tools/go/packages" 15 | ) 16 | 17 | type Config struct { 18 | TargetPkgDirPath string 19 | Targets Targets 20 | OutPkgName func(inspectedPkgName string) string 21 | OutFilePath string 22 | OutPublic bool 23 | GoGenCmd string 24 | } 25 | 26 | type Targets struct { 27 | Include bool 28 | Exceptions map[string]struct{} 29 | } 30 | 31 | func Generate(cfg Config) error { 32 | pkgs, err := packages.Load(&packages.Config{ 33 | Mode: packages.NeedName | packages.NeedFiles | 34 | packages.NeedTypes | packages.NeedTypesInfo, 35 | Dir: cfg.TargetPkgDirPath, 36 | Tests: false, 37 | BuildFlags: nil, // TODO? 38 | }, ".") 39 | if err != nil { 40 | return fmt.Errorf("load packages: %w", err) 41 | } 42 | if len(pkgs) == 1 && len(pkgs[0].GoFiles) == 0 { 43 | log.Printf("WARN: no packages found\n") 44 | return nil 45 | } 46 | for _, pkg := range pkgs { 47 | goFiles := pkg.GoFiles 48 | if len(goFiles) == 0 { 49 | continue 50 | } 51 | err = generateForPackage(pkg.Types, cfg) 52 | if err != nil { 53 | return fmt.Errorf("generate for package %s: %w", pkg.PkgPath, err) 54 | } 55 | } 56 | return nil 57 | } 58 | 59 | // targetDesc identifies either interface or function. 60 | type targetDesc struct { 61 | Name string 62 | TypeParams *types.TypeParamList 63 | Methods []*types.Func 64 | } 65 | 66 | func findTargetByIdent(pkg *types.Package, ident string) *targetDesc { 67 | obj := pkg.Scope().Lookup(ident) 68 | typeNameObj, ok := obj.(*types.TypeName) 69 | if !ok { 70 | return nil 71 | } 72 | var typeParams *types.TypeParamList 73 | if namedType, ok := obj.Type().(*types.Named); ok { 74 | typeParams = namedType.TypeParams() 75 | } 76 | methods := []*types.Func(nil) 77 | switch underlying := typeNameObj.Type().Underlying().(type) { 78 | case *types.Interface: 79 | for i := 0; i < underlying.NumMethods(); i++ { 80 | methods = append(methods, underlying.Method(i)) 81 | } 82 | case *types.Signature: 83 | methods = []*types.Func{types.NewFunc(0, pkg, "Execute", underlying)} 84 | default: 85 | return nil 86 | } 87 | return &targetDesc{ 88 | Name: ident, 89 | TypeParams: typeParams, 90 | Methods: methods, 91 | } 92 | } 93 | 94 | func generateForPackage(pkg *types.Package, cfg Config) error { 95 | buf := &bytes.Buffer{} 96 | w := &writer{buf: buf} 97 | 98 | w.Println("// Code generated by mockigo. DO NOT EDIT.") 99 | w.Println() 100 | if cfg.GoGenCmd != "" { 101 | w.Println("//go:generate " + cfg.GoGenCmd) 102 | w.Println() 103 | } 104 | mocksPkg := cfg.OutPkgName(pkg.Name()) 105 | w.Println("package " + mocksPkg) 106 | 107 | targets := []targetDesc(nil) 108 | 109 | for _, ident := range pkg.Scope().Names() { 110 | _, isException := cfg.Targets.Exceptions[ident] 111 | delete(cfg.Targets.Exceptions, ident) 112 | if isException == cfg.Targets.Include { 113 | continue 114 | } 115 | target := findTargetByIdent(pkg, ident) 116 | if target == nil { 117 | if isException { 118 | return fmt.Errorf("target %q is not interface or function", ident) 119 | } 120 | continue 121 | } 122 | targets = append(targets, *target) 123 | } 124 | if len(cfg.Targets.Exceptions) > 0 { 125 | target := "" 126 | for ident := range cfg.Targets.Exceptions { 127 | target = ident 128 | break 129 | } 130 | return fmt.Errorf("target %q is not found", target) 131 | } 132 | 133 | if len(targets) == 0 { 134 | return nil 135 | } 136 | 137 | generatingToSameDir, err := util.FileInDir(cfg.TargetPkgDirPath, cfg.OutFilePath) 138 | if err != nil { 139 | return err 140 | } 141 | importNames, pkgToImportName := generateImports(w, targets, pkg, !generatingToSameDir || mocksPkg != pkg.Name()) 142 | w.Println() 143 | w.Println("var _ = match.Any[int]") 144 | 145 | for _, target := range targets { 146 | generateForInterface(w, target, cfg.OutPublic, pkgToImportName, importNames) 147 | } 148 | 149 | if w.err != nil { 150 | return fmt.Errorf("writing file: %w", w.err) 151 | } 152 | return writeToFile(w.buf.Bytes(), cfg.OutFilePath) 153 | } 154 | 155 | func generateImports( 156 | w *writer, targets []targetDesc, pkgOfTargets *types.Package, importPkgOfTargets bool, 157 | ) (importNames map[string]struct{}, pkgToImportName func(pkg *types.Package) string) { 158 | trie := path_trie.New() 159 | 160 | trie.LoadPath(path_trie.Path{"mock"}, "github.com/subtle-byte/mockigo/mock") 161 | trie.LoadPath(path_trie.Path{"match"}, "github.com/subtle-byte/mockigo/match") 162 | 163 | maxConsecutiveUnderscores := 0 164 | walkingPkgQualifier := func(pkg *types.Package) string { 165 | maxConsecutiveUnderscores = util.CountMaxConsecutiveUnderscores(pkg.Path(), maxConsecutiveUnderscores) 166 | splittedPath := strings.Split(pkg.Path(), "/") 167 | for i := range splittedPath { 168 | splittedPath[i] = strings.ReplaceAll(splittedPath[i], "-", "") 169 | } 170 | trie.LoadPath(splittedPath, pkg.Path()) 171 | return "" 172 | } 173 | 174 | for _, target := range targets { 175 | for _, method := range target.Methods { 176 | signature := method.Type().(*types.Signature) 177 | for _, tuple := range [2]*types.Tuple{signature.Params(), signature.Results()} { 178 | for i := 0; i < tuple.Len(); i++ { 179 | types.TypeString(tuple.At(i).Type(), walkingPkgQualifier) 180 | } 181 | } 182 | } 183 | if target.TypeParams != nil { 184 | for i := 0; i < target.TypeParams.Len(); i++ { 185 | types.TypeString(target.TypeParams.At(i).Constraint(), walkingPkgQualifier) 186 | } 187 | } 188 | } 189 | 190 | importPathToName := map[string]string{} 191 | importNames = map[string]struct{}{} 192 | 193 | for _, reducedPath := range trie.ReducedPaths() { 194 | importPath := reducedPath.Meta.(string) 195 | if importPath == pkgOfTargets.Path() && !importPkgOfTargets { 196 | continue 197 | } 198 | name := strings.Join(reducedPath.Rest, strings.Repeat("_", maxConsecutiveUnderscores+1)) 199 | importNames[name] = struct{}{} 200 | importPathToName[importPath] = name 201 | } 202 | 203 | sortedImports := make([]string, 0, len(importPathToName)) 204 | for path, name := range importPathToName { 205 | sortedImports = append(sortedImports, fmt.Sprintf("import %s %q", name, path)) 206 | } 207 | sort.Strings(sortedImports) 208 | w.Println() 209 | for _, aImport := range sortedImports { 210 | w.Println(aImport) 211 | } 212 | 213 | pkgToImportName = func(pkg *types.Package) string { 214 | if pkg.Path() == pkgOfTargets.Path() && !importPkgOfTargets { 215 | return "" 216 | } 217 | name, ok := importPathToName[pkg.Path()] 218 | if !ok { 219 | return "" 220 | } 221 | return name 222 | } 223 | 224 | return 225 | } 226 | 227 | func genericFormats(typeParams *types.TypeParamList, pkgToImportName func(pkg *types.Package) string) (onTarget, inReceiver string) { 228 | if typeParams == nil { 229 | return "", "" 230 | } 231 | identAndType := make([]string, typeParams.Len()) 232 | idents := make([]string, typeParams.Len()) 233 | for i := 0; i < typeParams.Len(); i++ { 234 | tp := typeParams.At(i) 235 | ident := tp.Obj().Name() 236 | typeStr := types.TypeString(tp.Constraint(), pkgToImportName) 237 | identAndType[i] = ident + " " + typeStr 238 | idents[i] = ident 239 | } 240 | onTarget = "[" + strings.Join(identAndType, ", ") + "]" 241 | inReceiver = "[" + strings.Join(idents, ", ") + "]" 242 | return 243 | } 244 | 245 | func generateForInterface(w *writer, target targetDesc, public bool, pkgToImportName func(pkg *types.Package) string, forbiddenIdents map[string]struct{}) { 246 | typeParamsOnTarget, typeParamsInReceiver := genericFormats(target.TypeParams, pkgToImportName) 247 | 248 | w.Println() 249 | mockName := util.SetCaseForFirstLetter(target.Name, true) + "Mock" 250 | w.Println("type ", mockName, typeParamsOnTarget, " struct {\n\tmock *mock.Mock\n}") 251 | w.Println() 252 | w.Println("func ", util.SetCaseForFirstLetter("New"+mockName, public), typeParamsOnTarget, "(t mock.Testing) *", mockName, typeParamsInReceiver, " {") 253 | w.Println("\tt.Helper()") 254 | w.Println("\treturn &", mockName, typeParamsInReceiver, "{mock: mock.NewMock(t)}") 255 | w.Println("}") 256 | w.Println() 257 | expecterName := "_" + mockName + "_Expecter" 258 | w.Println("type ", expecterName, typeParamsOnTarget, " struct {\n\tmock *mock.Mock\n}") 259 | expecterName += typeParamsInReceiver 260 | w.Println() 261 | w.Println("func (_mock *", mockName, typeParamsInReceiver, ") EXPECT() ", expecterName, " {") 262 | w.Println("\t return ", expecterName, "{mock: _mock.mock}") 263 | w.Println("}") 264 | 265 | for _, method := range target.Methods { 266 | generateForMethod(w, mockName, typeParamsOnTarget, typeParamsInReceiver, expecterName, method, pkgToImportName, forbiddenIdents) 267 | } 268 | } 269 | 270 | func isNilable(aType types.Type) bool { 271 | if underlying, ok := aType.(*types.Named); ok { 272 | aType = underlying.Underlying() 273 | } 274 | switch aType.(type) { 275 | case *types.Pointer, *types.Array, *types.Slice, *types.Map, *types.Chan, *types.Signature, *types.Interface: 276 | return true 277 | default: 278 | return false 279 | } 280 | } 281 | 282 | func generateForMethod(w *writer, mockName, typeParamsOnTarget, typeParamsInReceiver, expecterName string, method *types.Func, pkgToImportName func(pkg *types.Package) string, forbiddenNames map[string]struct{}) { 283 | signature := method.Type().(*types.Signature) 284 | variadic := signature.Variadic() 285 | 286 | inFormats := NewTupleFormatter(signature.Params(), variadic, pkgToImportName).Format("_a", forbiddenNames) 287 | outFormats := NewTupleFormatter(signature.Results(), false, pkgToImportName).Format("_r", forbiddenNames) 288 | 289 | callStruct := "_" + mockName + "_" + method.Name() + "_Call" 290 | w.Println() 291 | w.Println("type ", callStruct, typeParamsOnTarget, " struct {\n\t*mock.Call\n}") 292 | callStruct += typeParamsInReceiver 293 | w.Println("\nfunc (_mock *", mockName, typeParamsInReceiver, ") ", method.Name(), "(", inFormats.NamedParams, ") (", outFormats.RawParams, ") {") 294 | w.Println("\t_mock.mock.T.Helper()") 295 | w.Print(inFormats.VariadicArgsEval) 296 | results := "_results := " 297 | if signature.Results().Len() == 0 { 298 | results = "" 299 | } 300 | if !variadic { 301 | w.Println("\t", results, "_mock.mock.Called(\"", method.Name(), "\", ", inFormats.Args, ")") 302 | } else { 303 | w.Println("\t", results, "_mock.mock.Called(\"", method.Name(), "\", ", inFormats.VariadicArgs, ")") 304 | } 305 | if signature.Results().Len() != 0 { 306 | returnArgs := []string(nil) 307 | for i := 0; i < signature.Results().Len(); i++ { 308 | resultVar := signature.Results().At(i) 309 | varName := "_r" + strconv.Itoa(i) 310 | returnArgs = append(returnArgs, varName) 311 | typeStr := types.TypeString(resultVar.Type(), pkgToImportName) 312 | if typeStr == "error" { 313 | w.Println("\t", varName, " := _results.Error(", strconv.Itoa(i), ")") 314 | } else if !isNilable(resultVar.Type()) { 315 | w.Println("\t", varName, " := _results.Get(", strconv.Itoa(i), ").(", typeStr, ")") 316 | } else { 317 | w.Println("\tvar ", varName, " ", typeStr) 318 | w.Println("\tif _got := _results.Get(", strconv.Itoa(i), "); _got != nil {") 319 | w.Println("\t\t", varName, " = _got.(", typeStr, ")") 320 | w.Println("\t}") 321 | } 322 | } 323 | if len(returnArgs) != 0 { 324 | w.Println("\treturn ", strings.Join(returnArgs, ", ")) 325 | } 326 | } 327 | w.Println("}") 328 | 329 | w.Println() 330 | w.Println("func (_expecter ", expecterName, ") ", method.Name(), "(", inFormats.NamedArgedParams, ") ", callStruct, " {") 331 | w.Print(inFormats.VariadicArgsMatchersEval) 332 | if !variadic { 333 | w.Println("\treturn ", callStruct, `{Call: _expecter.mock.ExpectCall("`, method.Name(), `", `, inFormats.ArgsMatchers, ")}") 334 | } else { 335 | w.Println("\treturn ", callStruct, `{Call: _expecter.mock.ExpectCall("`, method.Name(), `", `, inFormats.VariadicArgs, ")}") 336 | } 337 | w.Println("}") 338 | 339 | w.Println() 340 | w.Println("func (_call ", callStruct, ") Return(", outFormats.NamedParams, ") ", callStruct, " {") 341 | w.Println("\t_call.Call.Return(", outFormats.Args, ")") 342 | w.Println("\treturn _call") 343 | w.Println("}") 344 | 345 | w.Println("") 346 | runReturnFuncType := "func(" + inFormats.RawParams + ") (" + outFormats.RawParams + ")" 347 | w.Println("func (_call ", callStruct, ") RunReturn(f ", runReturnFuncType, ") ", callStruct, " {") 348 | w.Println("\t_call.Call.RunReturn(f)") 349 | w.Println("\treturn _call") 350 | w.Println("}") 351 | } 352 | -------------------------------------------------------------------------------- /internal/generator/generator_test.go: -------------------------------------------------------------------------------- 1 | package generator 2 | 3 | import ( 4 | "path/filepath" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestGenerator(t *testing.T) { 11 | toAbs := func(rel string) string { 12 | abs, err := filepath.Abs(rel) 13 | require.NoError(t, err) 14 | return abs 15 | } 16 | targets := Targets{ 17 | Include: true, 18 | Exceptions: map[string]struct{}{"Filtered": {}}, 19 | } 20 | err := Generate(Config{ 21 | TargetPkgDirPath: toAbs("testdata"), 22 | Targets: targets, 23 | OutFilePath: toAbs("testdata/mocks.go"), 24 | OutPkgName: func(inspectedPkgName string) string { 25 | return inspectedPkgName + "_test" 26 | }, 27 | OutPublic: true, 28 | GoGenCmd: "some command", 29 | }) 30 | require.NoError(t, err) 31 | } 32 | -------------------------------------------------------------------------------- /internal/generator/path_trie/path_trie.go: -------------------------------------------------------------------------------- 1 | package path_trie 2 | 3 | type Path []string 4 | 5 | type PathDir struct { 6 | children map[string]PathDir 7 | pathStartMeta interface{} 8 | } 9 | 10 | func New() PathDir { 11 | return PathDir{children: map[string]PathDir{}} 12 | } 13 | 14 | var pathStartFlagMeta = struct{}{} // for the case meta is not provided to LoadPath 15 | 16 | func (dir *PathDir) LoadPath(path Path, meta interface{}) { 17 | if len(path) == 0 { 18 | if meta == nil { 19 | meta = pathStartFlagMeta 20 | } 21 | dir.pathStartMeta = meta 22 | return 23 | } 24 | lastIndex := len(path) - 1 25 | child, ok := dir.children[path[lastIndex]] 26 | if !ok { 27 | child = New() 28 | } 29 | child.LoadPath(path[:lastIndex], meta) 30 | dir.children[path[lastIndex]] = child 31 | } 32 | 33 | type ReducedPath struct { 34 | Rest Path 35 | Meta interface{} 36 | } 37 | 38 | func (dir PathDir) ReducedPaths() []ReducedPath { 39 | paths := []ReducedPath(nil) 40 | if dir.pathStartMeta != nil { 41 | meta := dir.pathStartMeta 42 | if meta == pathStartFlagMeta { 43 | meta = nil 44 | } 45 | paths = append(paths, ReducedPath{ 46 | Rest: nil, 47 | Meta: meta, 48 | }) 49 | } 50 | for childName, childDir := range dir.children { 51 | childPaths := childDir.ReducedPaths() 52 | // if len(childPaths) == 0 { 53 | // panic("impossible") 54 | // } 55 | if len(childPaths) == 1 { 56 | paths = append(paths, ReducedPath{ 57 | Rest: Path{childName}, 58 | Meta: childPaths[0].Meta, 59 | }) 60 | continue 61 | } 62 | for _, childPath := range childPaths { 63 | paths = append(paths, ReducedPath{ 64 | Rest: append(childPath.Rest, childName), 65 | Meta: childPath.Meta, 66 | }) 67 | } 68 | } 69 | return paths 70 | } 71 | -------------------------------------------------------------------------------- /internal/generator/path_trie/path_trie_test.go: -------------------------------------------------------------------------------- 1 | package path_trie 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func Test(t *testing.T) { 11 | assert := assert.New(t) 12 | trie := New() 13 | trie.LoadPath(strings.Split("github.com/aa/aa/cc", "/"), 6) 14 | trie.LoadPath(strings.Split("github.com/aa/cc", "/"), 2) 15 | trie.LoadPath(strings.Split("github.com/aa", "/"), nil) 16 | reducedPaths := trie.ReducedPaths() 17 | assert.Len(reducedPaths, 3) 18 | assert.Contains(reducedPaths, ReducedPath{ 19 | Rest: strings.Split("aa/aa/cc", "/"), Meta: 6, 20 | }) 21 | assert.Contains(reducedPaths, ReducedPath{ 22 | Rest: strings.Split("github.com/aa/cc", "/"), Meta: 2, 23 | }) 24 | assert.Contains(reducedPaths, ReducedPath{ 25 | Rest: strings.Split("aa", "/"), Meta: nil, 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /internal/generator/testdata/base.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import "time" 4 | 5 | type Nilable interface{} 6 | 7 | type SimpleInterface interface { 8 | Foo(time.Time) (Nilable, error) 9 | } 10 | 11 | type GenericInterface[T any] interface { 12 | Foo(a int, b ...T) T 13 | } 14 | 15 | type Func func() 16 | 17 | type NotInterface struct{} 18 | 19 | var Var int 20 | 21 | type NotExported interface{} 22 | 23 | type Filtered interface{} 24 | -------------------------------------------------------------------------------- /internal/generator/testdata/mocks.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockigo. DO NOT EDIT. 2 | 3 | //go:generate some command 4 | 5 | package data_test 6 | 7 | import match "github.com/subtle-byte/mockigo/match" 8 | import mock "github.com/subtle-byte/mockigo/mock" 9 | import testdata "github.com/subtle-byte/mockigo/internal/generator/testdata" 10 | import time "time" 11 | 12 | var _ = match.Any[int] 13 | 14 | type FuncMock struct { 15 | mock *mock.Mock 16 | } 17 | 18 | func NewFuncMock(t mock.Testing) *FuncMock { 19 | t.Helper() 20 | return &FuncMock{mock: mock.NewMock(t)} 21 | } 22 | 23 | type _FuncMock_Expecter struct { 24 | mock *mock.Mock 25 | } 26 | 27 | func (_mock *FuncMock) EXPECT() _FuncMock_Expecter { 28 | return _FuncMock_Expecter{mock: _mock.mock} 29 | } 30 | 31 | type _FuncMock_Execute_Call struct { 32 | *mock.Call 33 | } 34 | 35 | func (_mock *FuncMock) Execute() () { 36 | _mock.mock.T.Helper() 37 | _mock.mock.Called("Execute", ) 38 | } 39 | 40 | func (_expecter _FuncMock_Expecter) Execute() _FuncMock_Execute_Call { 41 | return _FuncMock_Execute_Call{Call: _expecter.mock.ExpectCall("Execute", )} 42 | } 43 | 44 | func (_call _FuncMock_Execute_Call) Return() _FuncMock_Execute_Call { 45 | _call.Call.Return() 46 | return _call 47 | } 48 | 49 | func (_call _FuncMock_Execute_Call) RunReturn(f func() ()) _FuncMock_Execute_Call { 50 | _call.Call.RunReturn(f) 51 | return _call 52 | } 53 | 54 | type GenericInterfaceMock[T any] struct { 55 | mock *mock.Mock 56 | } 57 | 58 | func NewGenericInterfaceMock[T any](t mock.Testing) *GenericInterfaceMock[T] { 59 | t.Helper() 60 | return &GenericInterfaceMock[T]{mock: mock.NewMock(t)} 61 | } 62 | 63 | type _GenericInterfaceMock_Expecter[T any] struct { 64 | mock *mock.Mock 65 | } 66 | 67 | func (_mock *GenericInterfaceMock[T]) EXPECT() _GenericInterfaceMock_Expecter[T] { 68 | return _GenericInterfaceMock_Expecter[T]{mock: _mock.mock} 69 | } 70 | 71 | type _GenericInterfaceMock_Foo_Call[T any] struct { 72 | *mock.Call 73 | } 74 | 75 | func (_mock *GenericInterfaceMock[T]) Foo(a int, b ...T) (T) { 76 | _mock.mock.T.Helper() 77 | _args := []any{a, mock.SliceToAnySlice(b)} 78 | _results := _mock.mock.Called("Foo", _args...) 79 | _r0 := _results.Get(0).(T) 80 | return _r0 81 | } 82 | 83 | func (_expecter _GenericInterfaceMock_Expecter[T]) Foo(a match.Arg[int], b ...match.Arg[T]) _GenericInterfaceMock_Foo_Call[T] { 84 | _args := append([]mock.Matcher{a.Matcher}, match.ArgsToMatchers(b)...) 85 | return _GenericInterfaceMock_Foo_Call[T]{Call: _expecter.mock.ExpectCall("Foo", _args...)} 86 | } 87 | 88 | func (_call _GenericInterfaceMock_Foo_Call[T]) Return(_r0 T) _GenericInterfaceMock_Foo_Call[T] { 89 | _call.Call.Return(_r0) 90 | return _call 91 | } 92 | 93 | func (_call _GenericInterfaceMock_Foo_Call[T]) RunReturn(f func(a int, b ...T) (T)) _GenericInterfaceMock_Foo_Call[T] { 94 | _call.Call.RunReturn(f) 95 | return _call 96 | } 97 | 98 | type NilableMock struct { 99 | mock *mock.Mock 100 | } 101 | 102 | func NewNilableMock(t mock.Testing) *NilableMock { 103 | t.Helper() 104 | return &NilableMock{mock: mock.NewMock(t)} 105 | } 106 | 107 | type _NilableMock_Expecter struct { 108 | mock *mock.Mock 109 | } 110 | 111 | func (_mock *NilableMock) EXPECT() _NilableMock_Expecter { 112 | return _NilableMock_Expecter{mock: _mock.mock} 113 | } 114 | 115 | type NotExportedMock struct { 116 | mock *mock.Mock 117 | } 118 | 119 | func NewNotExportedMock(t mock.Testing) *NotExportedMock { 120 | t.Helper() 121 | return &NotExportedMock{mock: mock.NewMock(t)} 122 | } 123 | 124 | type _NotExportedMock_Expecter struct { 125 | mock *mock.Mock 126 | } 127 | 128 | func (_mock *NotExportedMock) EXPECT() _NotExportedMock_Expecter { 129 | return _NotExportedMock_Expecter{mock: _mock.mock} 130 | } 131 | 132 | type SimpleInterfaceMock struct { 133 | mock *mock.Mock 134 | } 135 | 136 | func NewSimpleInterfaceMock(t mock.Testing) *SimpleInterfaceMock { 137 | t.Helper() 138 | return &SimpleInterfaceMock{mock: mock.NewMock(t)} 139 | } 140 | 141 | type _SimpleInterfaceMock_Expecter struct { 142 | mock *mock.Mock 143 | } 144 | 145 | func (_mock *SimpleInterfaceMock) EXPECT() _SimpleInterfaceMock_Expecter { 146 | return _SimpleInterfaceMock_Expecter{mock: _mock.mock} 147 | } 148 | 149 | type _SimpleInterfaceMock_Foo_Call struct { 150 | *mock.Call 151 | } 152 | 153 | func (_mock *SimpleInterfaceMock) Foo(_a0 time.Time) (testdata.Nilable, error) { 154 | _mock.mock.T.Helper() 155 | _results := _mock.mock.Called("Foo", _a0) 156 | var _r0 testdata.Nilable 157 | if _got := _results.Get(0); _got != nil { 158 | _r0 = _got.(testdata.Nilable) 159 | } 160 | _r1 := _results.Error(1) 161 | return _r0, _r1 162 | } 163 | 164 | func (_expecter _SimpleInterfaceMock_Expecter) Foo(_a0 match.Arg[time.Time]) _SimpleInterfaceMock_Foo_Call { 165 | return _SimpleInterfaceMock_Foo_Call{Call: _expecter.mock.ExpectCall("Foo", _a0.Matcher)} 166 | } 167 | 168 | func (_call _SimpleInterfaceMock_Foo_Call) Return(_r0 testdata.Nilable, _r1 error) _SimpleInterfaceMock_Foo_Call { 169 | _call.Call.Return(_r0, _r1) 170 | return _call 171 | } 172 | 173 | func (_call _SimpleInterfaceMock_Foo_Call) RunReturn(f func(time.Time) (testdata.Nilable, error)) _SimpleInterfaceMock_Foo_Call { 174 | _call.Call.RunReturn(f) 175 | return _call 176 | } 177 | -------------------------------------------------------------------------------- /internal/generator/tuple_formatter.go: -------------------------------------------------------------------------------- 1 | package generator 2 | 3 | import ( 4 | "fmt" 5 | "go/types" 6 | "strings" 7 | ) 8 | 9 | type TupleFormatter struct { 10 | rawNames []string 11 | types []string 12 | isVariadic bool 13 | } 14 | 15 | func NewTupleFormatter(tuple *types.Tuple, isVariadic bool, pkgQualifier func(pkg *types.Package) string) *TupleFormatter { 16 | tf := &TupleFormatter{} 17 | tf.isVariadic = isVariadic 18 | tf.rawNames = make([]string, tuple.Len()) 19 | tf.types = make([]string, tuple.Len()) 20 | for i := 0; i < tuple.Len(); i++ { 21 | tf.rawNames[i] = tuple.At(i).Name() 22 | tf.types[i] = types.TypeString(tuple.At(i).Type(), pkgQualifier) 23 | } 24 | if isVariadic { 25 | variadic := &tf.types[tuple.Len()-1] 26 | *variadic = strings.Replace(*variadic, "[]", "...", 1) 27 | } 28 | return tf 29 | } 30 | 31 | type TupleFormats struct { 32 | Args string 33 | ArgsMatchers string 34 | RawParams string 35 | NamedParams string 36 | NamedArgedParams string 37 | VariadicArgs string 38 | VariadicArgsEval string 39 | VariadicArgsMatchersEval string 40 | } 41 | 42 | func (tf TupleFormatter) Format(prefixForUnnamed string, forbiddenNames map[string]struct{}) TupleFormats { 43 | tupleLen := len(tf.rawNames) 44 | f := TupleFormats{} 45 | 46 | names := make([]string, tupleLen) 47 | for i := 0; i < tupleLen; i++ { 48 | name := tf.rawNames[i] 49 | if _, isForbidden := forbiddenNames[name]; isForbidden || name == "" || name == "_" { 50 | name = fmt.Sprintf("%s%v", prefixForUnnamed, i) 51 | } 52 | names[i] = name 53 | } 54 | 55 | f.Args = strings.Join(names, ", ") 56 | if tf.isVariadic { 57 | f.Args += "..." 58 | } 59 | 60 | sb := strings.Builder{} 61 | for i := 0; i < tupleLen; i++ { 62 | name := names[i] 63 | if i != tupleLen-1 { 64 | sb.WriteString(name) 65 | sb.WriteString(".Matcher, ") 66 | } else { 67 | if !tf.isVariadic { 68 | sb.WriteString(name) 69 | sb.WriteString(".Matcher") 70 | } else { 71 | sb.WriteString("match.ArgsToInterfaces(") 72 | sb.WriteString(name) 73 | sb.WriteString(")...") 74 | } 75 | break 76 | } 77 | } 78 | f.ArgsMatchers = sb.String() 79 | 80 | sb.Reset() 81 | for i := 0; i < tupleLen; i++ { 82 | rawName := tf.rawNames[i] 83 | sb.WriteString(rawName) 84 | if rawName != "" { 85 | sb.WriteString(" ") 86 | } 87 | sb.WriteString(tf.types[i]) 88 | if i != tupleLen-1 { 89 | sb.WriteString(", ") 90 | } 91 | } 92 | f.RawParams = sb.String() 93 | 94 | sb.Reset() 95 | for i := 0; i < tupleLen; i++ { 96 | sb.WriteString(names[i]) 97 | sb.WriteString(" ") 98 | sb.WriteString(tf.types[i]) 99 | if i != tupleLen-1 { 100 | sb.WriteString(", ") 101 | } 102 | } 103 | f.NamedParams = sb.String() 104 | 105 | sb.Reset() 106 | for i := 0; i < tupleLen-1; i++ { 107 | sb.WriteString(names[i]) 108 | sb.WriteString(" match.Arg[") 109 | sb.WriteString(tf.types[i]) 110 | sb.WriteString("]") 111 | sb.WriteString(", ") 112 | } 113 | if tupleLen > 0 { 114 | i := tupleLen - 1 115 | sb.WriteString(names[i]) 116 | if !tf.isVariadic { 117 | sb.WriteString(" match.Arg[") 118 | sb.WriteString(tf.types[i]) 119 | sb.WriteString("]") 120 | } else { 121 | sb.WriteString(" ...match.Arg[") 122 | sb.WriteString(tf.types[i][3:]) 123 | sb.WriteString("]") 124 | } 125 | } 126 | f.NamedArgedParams = sb.String() 127 | 128 | if tf.isVariadic { 129 | f.VariadicArgs = "_args..." 130 | 131 | sb.Reset() 132 | sb.WriteString("\t_args := append([]mock.Matcher{") 133 | for i := 0; i < tupleLen-1; i++ { 134 | name := names[i] 135 | sb.WriteString(name) 136 | sb.WriteString(".Matcher") 137 | if i != tupleLen-2 { 138 | sb.WriteString(", ") 139 | } 140 | } 141 | sb.WriteString("}, match.ArgsToMatchers(") 142 | sb.WriteString(names[tupleLen-1]) 143 | sb.WriteString(")...)\n") 144 | f.VariadicArgsMatchersEval = sb.String() 145 | 146 | sb.Reset() 147 | sb.WriteString("\t_args := []any{") 148 | for i := 0; i < tupleLen-1; i++ { 149 | name := names[i] 150 | sb.WriteString(name) 151 | sb.WriteString(", ") 152 | } 153 | sb.WriteString("mock.SliceToAnySlice(" + names[tupleLen-1] + ")}\n") 154 | f.VariadicArgsEval = sb.String() 155 | } 156 | 157 | return f 158 | } 159 | -------------------------------------------------------------------------------- /internal/generator/tuple_formatter_test.go: -------------------------------------------------------------------------------- 1 | package generator 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestListFormatsNamedNotVariadic(t *testing.T) { 10 | formats := TupleFormatter{ 11 | rawNames: []string{"a", "_", "bc"}, 12 | types: []string{"int", "rune", "[]*string"}, 13 | isVariadic: false, 14 | }.Format("prefix_", map[string]struct{}{}) 15 | assert.Equal(t, TupleFormats{ 16 | Args: "a, prefix_1, bc", 17 | ArgsMatchers: "a.Matcher, prefix_1.Matcher, bc.Matcher", 18 | RawParams: "a int, _ rune, bc []*string", 19 | NamedParams: "a int, prefix_1 rune, bc []*string", 20 | NamedArgedParams: "a match.Arg[int], prefix_1 match.Arg[rune], bc match.Arg[[]*string]", 21 | VariadicArgs: "", 22 | VariadicArgsEval: "", 23 | VariadicArgsMatchersEval: "", 24 | }, formats) 25 | } 26 | 27 | func TestListFormatsNotNamedVariadic(t *testing.T) { 28 | formats := TupleFormatter{ 29 | rawNames: []string{"", "", ""}, 30 | types: []string{"int", "rune", "...*string"}, 31 | isVariadic: true, 32 | }.Format("prefix_", map[string]struct{}{}) 33 | assert.Equal(t, TupleFormats{ 34 | Args: "prefix_0, prefix_1, prefix_2...", 35 | ArgsMatchers: "prefix_0.Matcher, prefix_1.Matcher, match.ArgsToInterfaces(prefix_2)...", 36 | RawParams: "int, rune, ...*string", 37 | NamedParams: "prefix_0 int, prefix_1 rune, prefix_2 ...*string", 38 | NamedArgedParams: "prefix_0 match.Arg[int], prefix_1 match.Arg[rune], prefix_2 ...match.Arg[*string]", 39 | VariadicArgs: "_args...", 40 | VariadicArgsEval: "\t_args := []any{prefix_0, prefix_1, mock.SliceToAnySlice(prefix_2)}\n", 41 | VariadicArgsMatchersEval: "\t_args := append([]mock.Matcher{prefix_0.Matcher, prefix_1.Matcher}, match.ArgsToMatchers(prefix_2)...)\n", 42 | }, formats) 43 | } 44 | -------------------------------------------------------------------------------- /internal/generator/writer.go: -------------------------------------------------------------------------------- 1 | package generator 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "path/filepath" 8 | ) 9 | 10 | type writer struct { 11 | buf *bytes.Buffer 12 | err error 13 | } 14 | 15 | func (w *writer) Print(args ...string) { 16 | for _, arg := range args { 17 | _, err := w.buf.WriteString(arg) 18 | if err != nil && w.err == nil { 19 | w.err = err 20 | } 21 | } 22 | } 23 | 24 | func (w *writer) Println(args ...string) { 25 | w.Print(args...) 26 | _, err := w.buf.WriteString("\n") 27 | if err != nil && w.err == nil { 28 | w.err = err 29 | } 30 | } 31 | 32 | func writeToFile(buf []byte, filePath string) error { 33 | mockDir := filepath.Dir(filePath) 34 | err := os.MkdirAll(mockDir, 0o777) 35 | if err != nil { 36 | return fmt.Errorf("create dirs to mock (mock dir = %s): %w", mockDir, err) 37 | } 38 | 39 | f, err := os.Create(filePath) 40 | if err != nil { 41 | return fmt.Errorf("create mock file %q: %w", filePath, err) 42 | } 43 | defer f.Close() 44 | 45 | _, err = f.Write(buf) 46 | if err != nil { 47 | return fmt.Errorf("write into mock file %q: %w", filePath, err) 48 | } 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /internal/util/file_in_dir.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "path/filepath" 6 | ) 7 | 8 | func FileInDir(dirPath, filePath string) (bool, error) { 9 | absFilePath, err := filepath.Abs(filePath) 10 | if err != nil { 11 | return false, fmt.Errorf("get absolute path of %q: %w", filePath, err) 12 | } 13 | absDirPath, err := filepath.Abs(dirPath) 14 | if err != nil { 15 | return false, fmt.Errorf("get absolute path of %q: %w", absDirPath, err) 16 | } 17 | return filepath.Dir(absFilePath) == absDirPath, nil 18 | } 19 | -------------------------------------------------------------------------------- /internal/util/file_in_dir_test.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestSameDir(t *testing.T) { 10 | in, err := FileInDir("..", "file.go") 11 | assert.NoError(t, err) 12 | assert.Equal(t, false, in) 13 | 14 | in, err = FileInDir(".", "./file.go") 15 | assert.NoError(t, err) 16 | assert.Equal(t, true, in) 17 | } 18 | -------------------------------------------------------------------------------- /internal/util/map_slice.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | func MapSlice[I any, R any](in []I, f func(I) R) []R { 4 | res := make([]R, len(in)) 5 | for i, v := range in { 6 | res[i] = f(v) 7 | } 8 | return res 9 | } 10 | 11 | func SliceToSet[T comparable](sl []T) map[T]struct{} { 12 | res := make(map[T]struct{}, len(sl)) 13 | for _, v := range sl { 14 | res[v] = struct{}{} 15 | } 16 | return res 17 | } 18 | -------------------------------------------------------------------------------- /internal/util/map_slice_test.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "strconv" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestMapSlice(t *testing.T) { 11 | s := MapSlice([]int{12, 28}, func(n int) string { 12 | return strconv.Itoa(n) 13 | }) 14 | require.Equal(t, []string{"12", "28"}, s) 15 | } 16 | 17 | func TestSliceToSet(t *testing.T) { 18 | set := SliceToSet([]int{12, 28}) 19 | require.Equal(t, map[int]struct{}{12: struct{}{}, 28: struct{}{}}, set) 20 | } 21 | -------------------------------------------------------------------------------- /internal/util/string_util.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "strings" 4 | 5 | func SetCaseForFirstLetter(s string, upper bool) string { 6 | if len(s) == 0 { 7 | return s 8 | } 9 | // TODO improve for unicode 10 | setter := strings.ToLower 11 | if upper { 12 | setter = strings.ToUpper 13 | } 14 | return setter(s[:1]) + s[1:] 15 | } 16 | 17 | func CountMaxConsecutiveUnderscores(s string, initMax int) int { 18 | max := initMax 19 | cur := 0 20 | anyNotUnderscoreRune := "#" 21 | for _, r := range s + anyNotUnderscoreRune { 22 | if r == '_' { 23 | cur++ 24 | } else { 25 | if max < cur { 26 | max = cur 27 | } 28 | cur = 0 29 | } 30 | } 31 | return max 32 | } 33 | -------------------------------------------------------------------------------- /internal/util/string_util_test.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestSetCaseForFirstLetter(t *testing.T) { 10 | assert := assert.New(t) 11 | assert.Equal(SetCaseForFirstLetter("", true), "") 12 | assert.Equal(SetCaseForFirstLetter("", false), "") 13 | assert.Equal(SetCaseForFirstLetter("game", true), "Game") 14 | assert.Equal(SetCaseForFirstLetter("Game", true), "Game") 15 | assert.Equal(SetCaseForFirstLetter("game", false), "game") 16 | assert.Equal(SetCaseForFirstLetter("Game", false), "game") 17 | } 18 | 19 | func TestCountMaxConsecutiveUnderscores(t *testing.T) { 20 | assert := assert.New(t) 21 | assert.Equal(CountMaxConsecutiveUnderscores("skjfiudf", 0), 0) 22 | assert.Equal(CountMaxConsecutiveUnderscores("skjf_iudf__", 0), 2) 23 | assert.Equal(CountMaxConsecutiveUnderscores("skjf___iudf_", 0), 3) 24 | assert.Equal(CountMaxConsecutiveUnderscores("skjf_iudf_", 5), 5) 25 | } 26 | -------------------------------------------------------------------------------- /match/match.go: -------------------------------------------------------------------------------- 1 | package match 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/subtle-byte/mockigo/internal/util" 7 | "github.com/subtle-byte/mockigo/mock" 8 | ) 9 | 10 | type Arg[T any] struct { 11 | Matcher mock.Matcher 12 | } 13 | 14 | // ArgsToMatchers is useful in mock objects while working with variadic arguments 15 | func ArgsToMatchers[T any](args []Arg[T]) []mock.Matcher { 16 | return util.MapSlice(args, func(arg Arg[T]) mock.Matcher { 17 | return arg.Matcher 18 | }) 19 | } 20 | 21 | func Eq[T any](expectedArg T) Arg[T] { 22 | return Arg[T]{mock.Eq(expectedArg)} 23 | } 24 | 25 | func Any[T any]() Arg[T] { 26 | return Arg[T]{mock.Any()} 27 | } 28 | 29 | func Not[T any](arg Arg[T]) Arg[T] { 30 | return Arg[T]{func(x interface{}) bool { 31 | return !arg.Matcher(x) 32 | }} 33 | } 34 | 35 | func MatchedBy[T any](matcher func(T) bool) Arg[T] { 36 | return Arg[T]{func(x interface{}) bool { 37 | t, ok := x.(T) 38 | if !ok { 39 | return false 40 | } 41 | return matcher(t) 42 | }} 43 | } 44 | 45 | func AnyCtx() Arg[context.Context] { 46 | return Any[context.Context]() 47 | } 48 | -------------------------------------------------------------------------------- /match/match_test.go: -------------------------------------------------------------------------------- 1 | package match 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func TestAll(t *testing.T) { 10 | eq := Eq(7) 11 | any := Any[int]() 12 | f := func(i int) bool { return i > 5 } 13 | matcherBy := MatchedBy(f) 14 | not := Not(eq) 15 | matchers := ArgsToMatchers([]Arg[int]{ 16 | {Matcher: eq.Matcher}, 17 | {Matcher: any.Matcher}, 18 | {Matcher: matcherBy.Matcher}, 19 | {Matcher: not.Matcher}, 20 | }) 21 | require.Len(t, matchers, 4) 22 | require.Equal(t, true, matchers[0](7)) 23 | require.Equal(t, false, matchers[0](8)) 24 | require.Equal(t, true, matchers[1](7)) 25 | require.Equal(t, true, matchers[2](10)) 26 | require.Equal(t, false, matchers[2](2)) 27 | require.Equal(t, false, matchers[2]("hello")) 28 | require.Equal(t, true, matchers[3](6)) 29 | require.Equal(t, false, matchers[3](7)) 30 | require.Equal(t, true, matchers[3](9)) 31 | } 32 | -------------------------------------------------------------------------------- /mock/call.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "strings" 7 | 8 | "github.com/k0kubun/pp/v3" 9 | ) 10 | 11 | type Call struct { 12 | t Testing 13 | method string 14 | argsMatchers []Matcher 15 | prevCalls []*Call 16 | nextCalled []*Call 17 | minCalls, maxCalls int 18 | actualCallsNum int 19 | action func([]interface{}) []interface{} 20 | origin string 21 | } 22 | 23 | // CallHolder is implemented by Call and also by any types that embed Call (e.g. by generated typed Call) 24 | type CallHolder interface { 25 | GetCall() *Call 26 | } 27 | 28 | var _ CallHolder = (*Call)(nil) 29 | 30 | // GetCall implements CallHolder interface, just returns the receiver c 31 | func (c *Call) GetCall() *Call { 32 | return c 33 | } 34 | 35 | const infCalls = 1e8 // close enough to infinity 36 | 37 | func newCall(t Testing, method string, origin string, argsMatchers ...Matcher) *Call { 38 | t.Helper() 39 | return &Call{ 40 | t: t, 41 | method: method, 42 | argsMatchers: argsMatchers, 43 | prevCalls: nil, 44 | minCalls: 1, 45 | maxCalls: infCalls, 46 | actualCallsNum: 0, 47 | action: func(i []interface{}) []interface{} { return nil }, 48 | origin: origin, 49 | } 50 | } 51 | 52 | // Times set how many times the call should be called. 53 | // Use -1 for max to identify infinity. 54 | func (c *Call) Times(min, max int) *Call { 55 | if max == -1 { 56 | max = infCalls 57 | } 58 | c.minCalls, c.maxCalls = min, max 59 | return c 60 | } 61 | 62 | func (c *Call) CalledTimes() int { 63 | return c.actualCallsNum 64 | } 65 | 66 | // Returns true if the minimum number of calls have been made. 67 | func (c *Call) satisfied() bool { 68 | return c.actualCallsNum >= c.minCalls 69 | } 70 | 71 | func (c *Call) callingNext(next *Call) { 72 | c.nextCalled = append(c.nextCalled, next) 73 | } 74 | 75 | func (c *Call) call(args []interface{}) []interface{} { 76 | c.actualCallsNum++ 77 | for _, prevCall := range c.prevCalls { 78 | prevCall.callingNext(c) 79 | } 80 | return c.action(args) 81 | } 82 | 83 | // After sets that the call c can be called only after the prevCall is called its min times. 84 | // 85 | // After the prevCall is called the call c cannot be called. 86 | func (c *Call) After(prevCall CallHolder) *Call { 87 | c.prevCalls = append(c.prevCalls, prevCall.GetCall()) 88 | return c 89 | } 90 | 91 | func InOrder(calls ...CallHolder) { 92 | for i := 1; i < len(calls); i++ { 93 | calls[i].GetCall().After(calls[i-1]) 94 | } 95 | } 96 | 97 | // If yes, returns nil. If no, returns error with message explaining why it does not match. 98 | func (c *Call) matches(args []interface{}) error { 99 | if len(args) != len(c.argsMatchers) { 100 | return fmt.Errorf("expected call %s expects %d arguments, got %d", 101 | c.origin, len(c.argsMatchers), len(args)) 102 | } 103 | 104 | for i, matcher := range c.argsMatchers { 105 | if !matcher(args[i]) { 106 | pp := pp.New() 107 | pp.SetColoringEnabled(false) 108 | return fmt.Errorf( 109 | "expected call %s doesn't match %v argument, got:\n\t%v", 110 | c.origin, ordinal(i+1), strings.ReplaceAll(pp.Sprint(args[i]), "\n", "\n\t"), 111 | ) 112 | } 113 | } 114 | 115 | for _, prevCall := range c.prevCalls { 116 | if !prevCall.satisfied() { 117 | return fmt.Errorf("expected call %s should be called after call %v", 118 | c.origin, prevCall.origin) 119 | } 120 | } 121 | 122 | if len(c.nextCalled) != 0 { 123 | return fmt.Errorf("some expected calls planned to be after expected call %s have already been called", c.origin) 124 | } 125 | 126 | if c.actualCallsNum >= c.maxCalls { 127 | return fmt.Errorf("expected call %s has already been called the max number of times", c.origin) 128 | } 129 | 130 | return nil 131 | } 132 | 133 | func (c *Call) Return(rets ...interface{}) *Call { 134 | c.action = func([]interface{}) []interface{} { 135 | return rets 136 | } 137 | return c 138 | } 139 | 140 | func (c *Call) RunReturn(f interface{}) *Call { 141 | c.t.Helper() 142 | v := reflect.ValueOf(f) 143 | if ft := v.Type(); len(c.argsMatchers) != ft.NumIn() { 144 | c.t.Fatalf("Wrong number of arguments in RunReturn func for call %v: got %d, want %d", 145 | c.origin, len(c.argsMatchers), ft.NumIn()) 146 | } 147 | c.action = func(args []interface{}) []interface{} { 148 | c.t.Helper() 149 | vArgs := make([]reflect.Value, len(args)) 150 | for i := 0; i < len(args); i++ { 151 | vArgs[i] = reflect.ValueOf(args[i]) 152 | } 153 | vRets := v.Call(vArgs) 154 | rets := make([]interface{}, len(vRets)) 155 | for i, ret := range vRets { 156 | rets[i] = ret.Interface() 157 | } 158 | return rets 159 | } 160 | return c 161 | } 162 | -------------------------------------------------------------------------------- /mock/callset.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "fmt" 7 | ) 8 | 9 | type callSet struct { 10 | calls map[callSetKey][]*Call 11 | } 12 | 13 | type callSetKey struct { 14 | method string 15 | } 16 | 17 | func newCallSet() *callSet { 18 | return &callSet{make(map[callSetKey][]*Call)} 19 | } 20 | 21 | // Add adds a new expected call 22 | func (cs callSet) Add(call *Call) { 23 | key := callSetKey{call.method} 24 | cs.calls[key] = append(cs.calls[key], call) 25 | } 26 | 27 | func (cs callSet) FindMatch(method string, args []interface{}) (*Call, error) { 28 | key := callSetKey{method} 29 | methodCalls := cs.calls[key] 30 | var callsErrors bytes.Buffer 31 | for _, call := range methodCalls { 32 | err := call.matches(args) 33 | if err != nil { 34 | _, _ = fmt.Fprintf(&callsErrors, "\n%v", err) 35 | } else { 36 | return call, nil 37 | } 38 | } 39 | if len(methodCalls) == 0 { 40 | _, _ = fmt.Fprintf(&callsErrors, " there are no expected calls of the method %q", method) 41 | } 42 | return nil, errors.New(callsErrors.String()) 43 | } 44 | 45 | // Unsatisfied returns the Calls that was not called but must be called 46 | func (cs callSet) Unsatisfied() []*Call { 47 | unsatisfied := []*Call(nil) 48 | for _, methodCalls := range cs.calls { 49 | for _, call := range methodCalls { 50 | if !call.satisfied() { 51 | unsatisfied = append(unsatisfied, call) 52 | } 53 | } 54 | } 55 | return unsatisfied 56 | } 57 | -------------------------------------------------------------------------------- /mock/match.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | type Matcher func(x interface{}) bool 8 | 9 | func Any() Matcher { 10 | return func(interface{}) bool { 11 | return true 12 | } 13 | } 14 | 15 | func Eq(x interface{}) Matcher { 16 | return func(y interface{}) bool { 17 | return reflect.DeepEqual(x, y) 18 | } 19 | } 20 | 21 | func Not(m Matcher) Matcher { 22 | return func(x interface{}) bool { 23 | return !m(x) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mock/mock.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "sync" 7 | ) 8 | 9 | type Testing interface { 10 | Errorf(format string, args ...any) 11 | Fatalf(format string, args ...any) 12 | Helper() 13 | Cleanup(func()) 14 | Failed() bool 15 | } 16 | 17 | type Mock struct { 18 | T Testing 19 | mu sync.Mutex 20 | expectedCalls *callSet 21 | getCaller func(skip int) (pc uintptr, file string, line int, ok bool) 22 | } 23 | 24 | func NewMock(t Testing) *Mock { 25 | t.Helper() 26 | mock := &Mock{ 27 | T: t, 28 | expectedCalls: newCallSet(), 29 | getCaller: runtime.Caller, 30 | } 31 | t.Cleanup(func() { 32 | mock.T.Helper() 33 | mock.finish() 34 | }) 35 | return mock 36 | } 37 | 38 | func (mock *Mock) finish() { 39 | if mock.T.Failed() { 40 | return 41 | } 42 | mock.T.Helper() 43 | mock.mu.Lock() 44 | defer mock.mu.Unlock() 45 | unsatisfied := mock.expectedCalls.Unsatisfied() 46 | for _, call := range unsatisfied { 47 | mock.T.Errorf("clean up phase: missing call(s) to expected call %v", call.origin) 48 | } 49 | } 50 | 51 | func (mock *Mock) callerInfo(skip int) string { 52 | _, file, line, ok := mock.getCaller(skip + 1) 53 | if ok { 54 | return fmt.Sprintf("%s:%d", file, line) 55 | } 56 | return "unknown file" 57 | } 58 | 59 | func (mock *Mock) ExpectCall(method string, args ...Matcher) *Call { 60 | mock.T.Helper() 61 | call := newCall(mock.T, method, mock.callerInfo(2), args...) 62 | mock.mu.Lock() 63 | defer mock.mu.Unlock() 64 | mock.expectedCalls.Add(call) 65 | return call 66 | } 67 | 68 | func (mock *Mock) Called(method string, args ...interface{}) Rets { 69 | mock.T.Helper() 70 | 71 | var call *Call 72 | func() { 73 | mock.T.Helper() 74 | mock.mu.Lock() 75 | defer mock.mu.Unlock() 76 | 77 | expected, err := mock.expectedCalls.FindMatch(method, args) 78 | if err != nil { 79 | mock.T.Fatalf("Unexpected call of method %q because:%s", method, err) 80 | } 81 | 82 | call = expected 83 | }() 84 | 85 | var rets = call.call(args) 86 | return Rets{ 87 | rets: rets, 88 | call: call, 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /mock/mock_test.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "os" 5 | "strconv" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func newMock(t *testing.T) *Mock { 12 | t.Helper() 13 | m := NewMock(t) 14 | caller := m.getCaller 15 | m.getCaller = func(skip int) (pc uintptr, file string, line int, ok bool) { 16 | return caller(skip) // No need +1 because we want to use Mock outside some mock object 17 | } 18 | return m 19 | } 20 | 21 | func Example_simple() { 22 | runWithT(func(t *t) { 23 | m := newMockWithT(t) 24 | m.ExpectCall("Foo", Eq("hello")) 25 | m.Called("Foo", "hello") 26 | m.Called("Foo", "bye") 27 | }) 28 | //Output: 29 | // runWithT:4: Unexpected call of method "Foo" because: 30 | // expected call runWithT:2 doesn't match 1st argument, got: 31 | // "bye" 32 | } 33 | 34 | func TestMock_withReturn(t *testing.T) { 35 | m := newMock(t) 36 | m.ExpectCall("Foo", Eq("hello")).Return(43) 37 | ret := m.Called("Foo", "hello") 38 | ret0 := ret.Get(0).(int) 39 | require.Equal(t, 43, ret0) 40 | } 41 | 42 | func TestMock_withRunReturn(t *testing.T) { 43 | m := newMock(t) 44 | m.ExpectCall("Foo", Eq("hello")).RunReturn(func(s string) int { 45 | return 43 46 | }) 47 | ret := m.Called("Foo", "hello") 48 | ret0 := ret.Get(0).(int) 49 | require.Equal(t, 43, ret0) 50 | } 51 | 52 | func Example_withTimes() { 53 | runWithT(func(t *t) { 54 | m := newMockWithT(t) 55 | m.ExpectCall("BarBar").Times(0, 2) 56 | barbar2 := m.ExpectCall("BarBar2").Times(0, 2) 57 | m.Called("BarBar2") 58 | require.Equal(t, 1, barbar2.CalledTimes()) 59 | m.ExpectCall("Bar").Times(1, -1) 60 | m.Called("Bar") 61 | m.Called("Bar") 62 | m.Called("Bar") 63 | m.ExpectCall("Foo", Eq("hello")).Times(1, -100) 64 | m.Called("Foo", "hello") 65 | }) 66 | //Output: 67 | // runWithT:11: Unexpected call of method "Foo" because: 68 | // expected call runWithT:10 has already been called the max number of times 69 | } 70 | 71 | func Example_withAfter() { 72 | runWithT(func(t *t) { 73 | m := newMockWithT(t) 74 | fooCall := m.ExpectCall("Foo") 75 | m.ExpectCall("Bar").After(fooCall) 76 | m.Called("Bar") 77 | }) 78 | //Output: 79 | // runWithT:4: Unexpected call of method "Bar" because: 80 | // expected call runWithT:3 should be called after call runWithT:2 81 | } 82 | 83 | func Example_withAfterCallingPrev() { 84 | runWithT(func(t *t) { 85 | m := newMockWithT(t) 86 | fooCall := m.ExpectCall("Foo") 87 | m.ExpectCall("Bar").After(fooCall) 88 | m.Called("Foo") 89 | m.Called("Bar") 90 | m.Called("Foo") 91 | }) 92 | //Output: 93 | // runWithT:6: Unexpected call of method "Foo" because: 94 | // some expected calls planned to be after expected call runWithT:2 have already been called 95 | } 96 | 97 | func Example_withInOrder() { 98 | runWithT(func(t *t) { 99 | m := newMockWithT(t) 100 | InOrder( 101 | m.ExpectCall("Foo"), 102 | m.ExpectCall("Bar"), 103 | ) 104 | m.Called("Bar") 105 | }) 106 | //Output: 107 | // runWithT:6: Unexpected call of method "Bar" because: 108 | // expected call runWithT:4 should be called after call runWithT:3 109 | } 110 | 111 | func TestMock_withMatchers(t *testing.T) { 112 | m := newMock(t) 113 | m.ExpectCall("Foo", Any(), Eq("hello"), Not(Eq(0))) 114 | m.Called("Foo", 100, "hello", 1) 115 | } 116 | 117 | func TestMock_withMany(t *testing.T) { 118 | m := newMock(t) 119 | InOrder( 120 | m.ExpectCall("Foo", Any(), Eq("hello")).Return(45), 121 | m.ExpectCall("Bar", Any()).RunReturn(func(n int) string { 122 | return strconv.Itoa(n) 123 | }), 124 | ) 125 | fooRet := m.Called("Foo", 100, "hello").Get(0).(int) // == 45 126 | barRet := m.Called("Bar", 200).Get(0).(string) // == "200" 127 | 128 | require.Equal(t, 45, fooRet) 129 | require.Equal(t, "200", barRet) 130 | } 131 | 132 | func Example_unusedMethods() { 133 | runWithT(func(t *t) { 134 | m := newMockWithT(t) 135 | m.ExpectCall("Foo") 136 | }) 137 | //Output: 138 | // runWithT:1: clean up phase: missing call(s) to expected call runWithT:2 139 | } 140 | 141 | func Example_noReturn() { 142 | runWithT(func(t *t) { 143 | m := newMockWithT(t) 144 | m.ExpectCall("Foo") 145 | rets := m.Called("Foo") 146 | rets.Get(1) 147 | }) 148 | //Output: 149 | // runWithT:4: Call runWithT:2 does not have 2nd return value 150 | } 151 | 152 | func Example_errReturn() { 153 | runWithT(func(t *t) { 154 | m := newMockWithT(t) 155 | m.ExpectCall("Foo").Return(os.ErrClosed, nil, 7) 156 | rets := m.Called("Foo") 157 | e := rets.Error(0) 158 | require.Equal(t, os.ErrClosed, e) 159 | e = rets.Error(1) 160 | require.True(t, e == nil) 161 | rets.Error(2) 162 | }) 163 | //Output: 164 | // runWithT:8: Call runWithT:2 does not have 3rd return value of the error type 165 | } 166 | 167 | func Test_unknownFile(t *testing.T) { 168 | m := newMock(t) 169 | m.getCaller = func(skip int) (pc uintptr, file string, line int, ok bool) { 170 | return 0, "", 0, false 171 | } 172 | info := m.callerInfo(1) 173 | require.Equal(t, "unknown file", info) 174 | } 175 | 176 | func Example_wrongNumberOfArguments() { 177 | runWithT(func(t *t) { 178 | m := newMockWithT(t) 179 | m.ExpectCall("Foo") 180 | m.Called("Foo", 3, 4) 181 | }) 182 | //Output: 183 | // runWithT:3: Unexpected call of method "Foo" because: 184 | // expected call runWithT:2 expects 0 arguments, got 2 185 | } 186 | 187 | func Example_wrongNumberOfRunReturnArguments() { 188 | runWithT(func(t *t) { 189 | m := newMockWithT(t) 190 | m.ExpectCall("Foo").RunReturn(func(int) {}) 191 | }) 192 | //Output: 193 | // runWithT:2: Wrong number of arguments in RunReturn func for call runWithT:2: got 0, want 1 194 | } 195 | 196 | func Example_unexpectedMethod() { 197 | runWithT(func(t *t) { 198 | m := newMockWithT(t) 199 | m.Called("Foo") 200 | }) 201 | //Output: 202 | // runWithT:2: Unexpected call of method "Foo" because: there are no expected calls of the method "Foo" 203 | } 204 | -------------------------------------------------------------------------------- /mock/ordinal.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import "strconv" 4 | 5 | func ordinal(n int) string { 6 | if n >= 11 && n <= 20 { 7 | return strconv.Itoa(n) + "th" 8 | } 9 | switch n % 10 { 10 | case 1: 11 | return strconv.Itoa(n) + "st" 12 | case 2: 13 | return strconv.Itoa(n) + "nd" 14 | case 3: 15 | return strconv.Itoa(n) + "rd" 16 | default: 17 | return strconv.Itoa(n) + "th" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mock/ordinal_test.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func Example_ordinal() { 8 | for i := 1; i < 10; i++ { 9 | fmt.Print(ordinal(i) + " ") 10 | } 11 | fmt.Println(ordinal(10)) 12 | for i := 11; i < 20; i++ { 13 | fmt.Print(ordinal(i) + " ") 14 | } 15 | fmt.Println(ordinal(20)) 16 | for i := 21; i < 30; i++ { 17 | fmt.Print(ordinal(i) + " ") 18 | } 19 | fmt.Println(ordinal(30)) 20 | for i := 101; i < 110; i++ { 21 | fmt.Print(ordinal(i) + " ") 22 | } 23 | fmt.Println(ordinal(110)) 24 | // Output: 25 | // 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 26 | // 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 27 | // 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 28 | // 101st 102nd 103rd 104th 105th 106th 107th 108th 109th 110th 29 | } 30 | -------------------------------------------------------------------------------- /mock/rets.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | type Rets struct { 4 | rets []interface{} 5 | call *Call 6 | } 7 | 8 | func (r Rets) Len() int { 9 | return len(r.rets) 10 | } 11 | 12 | func (r Rets) Get(i int) interface{} { 13 | r.call.t.Helper() 14 | if i >= r.Len() { 15 | r.call.t.Fatalf("Call %v does not have %v return value", r.call.origin, ordinal(i+1)) 16 | } 17 | return r.rets[i] 18 | } 19 | 20 | func (r Rets) Error(i int) error { 21 | r.call.t.Helper() 22 | ret := r.Get(i) 23 | if ret == nil { 24 | return nil 25 | } 26 | e, ok := ret.(error) 27 | if !ok { 28 | r.call.t.Fatalf("Call %v does not have %v return value of the error type", r.call.origin, ordinal(i+1)) 29 | } 30 | return e 31 | } 32 | -------------------------------------------------------------------------------- /mock/slice_to_any_slice.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | // SliceToAnySlice is useful in mock objects while working with variadic arguments 4 | func SliceToAnySlice[T any](sl []T) []any { 5 | r := make([]any, len(sl)) 6 | for i, v := range sl { 7 | r[i] = any(v) 8 | } 9 | return r 10 | } 11 | -------------------------------------------------------------------------------- /mock/t_test.go: -------------------------------------------------------------------------------- 1 | package mock 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "strings" 7 | ) 8 | 9 | // t is implementation of Testing for the test cases where fail is expected 10 | type t struct { 11 | failed bool 12 | cleanupFunc func() 13 | cleaningUp bool 14 | cleanupSetterFuncName string 15 | helperFuncNames map[string]bool 16 | file string 17 | line int 18 | } 19 | 20 | var _ Testing = (*t)(nil) 21 | 22 | func runWithT(f func(t *t)) { 23 | _, file, line, ok := runtime.Caller(1) 24 | if !ok { 25 | panic("cannot get caller") 26 | } 27 | t := &t{ 28 | helperFuncNames: make(map[string]bool), 29 | file: file, 30 | line: line, 31 | } 32 | defer func() { 33 | if r := recover(); r != nil { 34 | if msg, ok := r.(string); !ok || msg != "test-failed" { 35 | panic(r) 36 | } 37 | } 38 | t.cleaningUp = true 39 | t.cleanupFunc() 40 | }() 41 | f(t) 42 | } 43 | 44 | func newMockWithT(t *t) *Mock { 45 | t.Helper() 46 | m := NewMock(t) 47 | m.getCaller = func(skip int) (pc uintptr, file string, line int, ok bool) { 48 | return t.caller(skip) 49 | } 50 | return m 51 | } 52 | 53 | func (t *t) callerName(skip int) string { 54 | pc, _, _, ok := runtime.Caller(skip + 1) 55 | if !ok { 56 | panic("cannot get caller") 57 | } 58 | frame, _ := runtime.CallersFrames([]uintptr{pc}).Next() 59 | return frame.Function 60 | } 61 | func (t *t) caller(skip int) (pc uintptr, file string, line int, ok bool) { 62 | pc, file, line, ok = runtime.Caller(skip + 1) 63 | if !ok { 64 | panic("cannot get caller") 65 | } 66 | 67 | if file == t.file { 68 | file = "runWithT" 69 | line -= t.line // to the line number be relative to the runWithT line 70 | } else { 71 | // Remove abs path prefix 72 | file = file[strings.LastIndex(file, "mockigo"):] 73 | } 74 | 75 | return 76 | } 77 | func (t *t) notHelperCallerName(skip int) string { 78 | if t.cleaningUp { 79 | return t.cleanupSetterFuncName 80 | } 81 | 82 | for t.helperFuncNames[t.callerName(skip+1)] { 83 | skip++ 84 | } 85 | _, file, line, _ := t.caller(skip + 1) 86 | return fmt.Sprintf("%s:%d", file, line) 87 | } 88 | 89 | // FailNow is used by require.Equal 90 | func (t *t) FailNow() { 91 | t.failed = true 92 | panic("test-failed") 93 | } 94 | func (t *t) Errorf(format string, args ...any) { 95 | t.failed = true 96 | fmt.Print(t.notHelperCallerName(1)+": ", fmt.Sprintf(format, args...)) 97 | } 98 | func (t *t) Fatalf(format string, args ...any) { 99 | t.Helper() 100 | t.Errorf(format, args...) 101 | t.FailNow() 102 | } 103 | func (t *t) Helper() { 104 | t.helperFuncNames[t.callerName(1)] = true 105 | } 106 | func (t *t) Cleanup(f func()) { 107 | t.cleanupFunc = f 108 | t.cleanupSetterFuncName = t.notHelperCallerName(1) 109 | } 110 | func (t *t) Failed() bool { return t.failed } 111 | --------------------------------------------------------------------------------