Skip to content

Commit

Permalink
Add test that asserts mocks on variadic return functions are behaving…
Browse files Browse the repository at this point in the history
… correctly
  • Loading branch information
LandonTClipp committed Jan 12, 2024
1 parent a032aa0 commit d119c66
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ with-expecter: True
mockname: "{{.InterfaceName}}"
filename: "{{.MockName}}.go"
outpkg: mocks

packages:
github.com/vektra/mockery/v2/pkg:
interfaces:
Expand All @@ -29,11 +30,11 @@ packages:
unroll-variadic: False
- mockname: Expecter
unroll-variadic: True
RequesterReturnElided:
VariadicNoReturnInterface:
config:
with-expecter: True
unroll-variadic: False
RequesterReturnElided:
github.com/vektra/mockery/v2/pkg/fixtures/recursive_generation:
config:
recursive: True
Expand Down
4 changes: 4 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ tasks:
- "**/*.go"
cmds:
- go fmt ./...

mocks:
desc: generate new mocks from scratch
deps: [mocks.remove, mocks.generate]

mocks.remove:
desc: remove all mock files
Expand Down
76 changes: 0 additions & 76 deletions mocks/github.com/vektra/mockery/v2/pkg/fixtures/VariadicExtra.go

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/fixtures/test/variadic_return_func_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package test

import (
"testing"

"github.com/stretchr/testify/assert"
mocks "github.com/vektra/mockery/v2/mocks/github.com/vektra/mockery/v2/pkg/fixtures"
)

func TestVariadicReturnFunc(t *testing.T) {
m := mocks.NewVariadicReturnFunc(t)
m.EXPECT().SampleMethod("").Return(func(s string, l []int, a ...any) {
assert.Equal(t, "foo", s)
assert.Equal(t, []int{1, 2, 3}, l)
assert.Equal(t, []any{"one", "two", "three"}, a)
})
m.SampleMethod("")("foo", []int{1, 2, 3}, "one", "two", "three")
}
3 changes: 0 additions & 3 deletions pkg/fixtures/variadic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ type Variadic interface {
VariadicFunction(str string, vFunc VariadicFunction) error
}

type VariadicExtra interface {
SampleMethod(str string) func(str string, arr []int, a ...interface{})
}
5 changes: 5 additions & 0 deletions pkg/fixtures/variadic_return_func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test

type VariadicReturnFunc interface {
SampleMethod(str string) func(str string, arr []int, a ...interface{})
}

0 comments on commit d119c66

Please sign in to comment.