Skip to content

Commit

Permalink
vektra#648: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kozmod committed Jun 27, 2023
1 parent 2a69b15 commit 15a4f69
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ packages:
filename: "{{.InterfaceName}}_mock.go"
mockname: "Mock{{.InterfaceName}}"
outpkg: "{{.PackageName}}"
inpackage: True
inpackage: True
github.com/vektra/mockery/v2/pkg/fixtures/method_args/same_name_arg_and_type:
config:
all: True
dir: "{{.InterfaceDir}}"
mockname: "{{.InterfaceName}}Mock"
outpkg: "{{.PackageName}}"
filename: "mock_{{.InterfaceName}}_test.go"
inpackage: True
keeptree: False
18 changes: 18 additions & 0 deletions pkg/fixtures/method_args/same_name_arg_and_type/entity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package same_name_arg_and_type

type (
interfaceA interface {
// SomeMethod - contains args with the same names of the type and arg
DoB(interfaceB interfaceB) interfaceB
DoB0(interfaceB interfaceB0) interfaceB0
DoB0v2(interfaceB0 interfaceB0) interfaceB0
}

interfaceB interface {
GetData() int
}

interfaceB0 interface {
DoB0(interfaceB0 interfaceB0) interfaceB0
}
)
70 changes: 70 additions & 0 deletions pkg/fixtures/method_args/same_name_arg_and_type/entity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package same_name_arg_and_type

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

type testStruct struct {
interfaceA interfaceA
}

func (s *testStruct) ExecDoB() interfaceB {
var in interfaceB = nil
return s.interfaceA.DoB(in)
}

func (s *testStruct) ExecDoB0() interfaceB0 {
var in interfaceB0 = nil
return s.interfaceA.DoB0(in)
}

func (s *testStruct) ExecDoB0v2() interfaceB0 {
var in interfaceB0 = nil
return s.interfaceA.DoB0v2(in)
}

func Test(t *testing.T) {
t.Run("ExecDoB", func(t *testing.T) {
mockInterfaceB := new(interfaceBMock)
mockInterfaceA := new(interfaceAMock)
mockInterfaceA.On("DoB", mock.Anything).Return(mockInterfaceB)

s := testStruct{
interfaceA: mockInterfaceA,
}
res := s.ExecDoB()
assert.Equal(t, mockInterfaceB, res)

mockInterfaceA.AssertExpectations(t)
})
t.Run("ExecDoB0", func(t *testing.T) {
mockInterfaceB0 := new(interfaceB0Mock)
mockInterfaceA := new(interfaceAMock)
mockInterfaceA.On("DoB0", mock.Anything).Return(mockInterfaceB0)

s := testStruct{
interfaceA: mockInterfaceA,
}
res := s.ExecDoB0()
assert.Equal(t, mockInterfaceB0, res)

mockInterfaceA.AssertExpectations(t)
})
t.Run("ExecDoB0v2", func(t *testing.T) {
mockInterfaceB0 := new(interfaceB0Mock)
mockInterfaceA := new(interfaceAMock)
mockInterfaceA.On("DoB0v2", mock.Anything).Return(mockInterfaceB0)

s := testStruct{
interfaceA: mockInterfaceA,
}
res := s.ExecDoB0v2()
assert.Equal(t, mockInterfaceB0, res)

mockInterfaceA.AssertExpectations(t)
})

}

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

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

0 comments on commit 15a4f69

Please sign in to comment.