-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedupe mocking peer methods during code generation when configured wi…
…th multiple cloning methods
- Loading branch information
Showing
5 changed files
with
321 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package bar | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
type fooBar struct { | ||
name string | ||
} | ||
|
||
//go:generate mockcompose -n fooBarMock -c fooBar -real FooBar,this -real BarFoo,this:. | ||
|
||
func (f *fooBar) FooBar() string { | ||
if f.order()%2 == 0 { | ||
fmt.Printf("ordinal order\n") | ||
|
||
return fmt.Sprintf("%s: %s%s", f.name, f.Foo(), f.Bar()) | ||
} | ||
|
||
fmt.Printf("reverse order\n") | ||
return fmt.Sprintf("%s: %s%s", f.name, f.Bar(), f.Foo()) | ||
} | ||
|
||
func (f *fooBar) BarFoo() string { | ||
if order()%2 == 0 { | ||
fmt.Printf("ordinal order\n") | ||
|
||
return fmt.Sprintf("%s: %s%s", f.name, f.Bar(), f.Foo()) | ||
} | ||
|
||
fmt.Printf("reverse order\n") | ||
return fmt.Sprintf("%s: %s%s", f.name, f.Foo(), f.Bar()) | ||
} | ||
|
||
func (f *fooBar) Foo() string { | ||
return "Foo" | ||
} | ||
|
||
func (f *fooBar) Bar() string { | ||
return "Bar" | ||
} | ||
|
||
func (f *fooBar) order() int { | ||
rand.Seed(time.Now().UnixNano()) | ||
return rand.Int() | ||
} | ||
|
||
func order() int { | ||
rand.Seed(time.Now().UnixNano()) | ||
return rand.Int() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package bar | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFooBar(t *testing.T) { | ||
assert := require.New(t) | ||
|
||
fb := &fooBarMock{ | ||
fooBar: fooBar{name: "TestFooBar"}, | ||
} | ||
|
||
fb.On("order").Return(1).Once() | ||
fb.On("order").Return(2).Once() | ||
|
||
fb.mock_fooBarMock_BarFoo_bar.On("order").Return(2).Once() | ||
fb.mock_fooBarMock_BarFoo_bar.On("order").Return(1).Once() | ||
|
||
fb.On("Foo").Return("FooMocked") | ||
fb.On("Bar").Return("BarMocked") | ||
|
||
s1 := fb.FooBar() | ||
assert.Equal("TestFooBar: BarMockedFooMocked", s1) | ||
s2 := fb.BarFoo() | ||
assert.Equal(s1, s2) | ||
|
||
s1 = fb.FooBar() | ||
assert.Equal("TestFooBar: FooMockedBarMocked", s1) | ||
s2 = fb.BarFoo() | ||
assert.Equal(s1, s2) | ||
} |
Oops, something went wrong.