-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wrapper interface for gomock.Call
Currently when type-safe return values are used, one can't use `InOrder` neither `After` with them as they expect `*gomock.Call` as parameters. This introduces a new interface called `WrapperCall` to support usage for this methods when typed flag is used. This interface helps to have compile-time error/warnings instead of runtime errors with a reflection based solution. Fixes (#70)
- Loading branch information
1 parent
837f20a
commit 0d99752
Showing
7 changed files
with
184 additions
and
14 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,4 @@ | ||
# `InOrder` and `*gomock.Call.After()` with typed generated code | ||
|
||
From #70, this tests that `InOrder` and `*gomock.Call.After` work with code | ||
generated usign the `typed` flag. |
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,15 @@ | ||
package inorder | ||
|
||
|
||
//go:generate mockgen -package inorder -source=inorder.go -destination=mock.go -typed | ||
type Animal interface { | ||
GetNoise() string | ||
Feed(string) error | ||
} | ||
|
||
func Interact(a Animal, food string) (string, error) { | ||
if err := a.Feed(food); err != nil { | ||
return "", err | ||
} | ||
return a.GetNoise(), nil | ||
} |
26 changes: 26 additions & 0 deletions
26
mockgen/internal/tests/typed_after_in_order/inorder_test.go
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,26 @@ | ||
package inorder | ||
|
||
import ( | ||
"testing" | ||
"fmt" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestInteract(t * testing.T) { | ||
ctrl := gomock.NewController(t) | ||
|
||
mockAnimal := NewMockAnimal(ctrl) | ||
gomock.InOrder( | ||
mockAnimal.EXPECT().Feed("burguir").DoAndReturn(func(s string) error { | ||
if s != "chocolate" { | ||
return nil | ||
} | ||
return fmt.Errorf("Dogs can't eat chocolate!") | ||
}), | ||
mockAnimal.EXPECT().GetNoise().Return("Woof!"), | ||
) | ||
_, err := Interact(mockAnimal, "burguir") | ||
if err != nil { | ||
t.Fatalf("sad") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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