-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement OverridableController to allow for mock overrides (#22)
This is an initial implementation of the proposal outlined in this issue, golang/mock#685
- Loading branch information
Showing
5 changed files
with
98 additions
and
2 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
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,34 @@ | ||
package gomock_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestEcho_NoOverride(t *testing.T) { | ||
ctrl := gomock.NewController(t, gomock.WithOverridableExpectations()) | ||
mockIndex := NewMockFoo(ctrl) | ||
|
||
mockIndex.EXPECT().Bar(gomock.Any()).Return("foo") | ||
res := mockIndex.Bar("input") | ||
|
||
if res != "foo" { | ||
t.Fatalf("expected response to equal 'foo', got %s", res) | ||
} | ||
} | ||
|
||
func TestEcho_WithOverride_BaseCase(t *testing.T) { | ||
ctrl := gomock.NewController(t, gomock.WithOverridableExpectations()) | ||
mockIndex := NewMockFoo(ctrl) | ||
|
||
// initial expectation set | ||
mockIndex.EXPECT().Bar(gomock.Any()).Return("foo") | ||
// override | ||
mockIndex.EXPECT().Bar(gomock.Any()).Return("bar") | ||
res := mockIndex.Bar("input") | ||
|
||
if res != "bar" { | ||
t.Fatalf("expected response to equal 'bar', got %s", res) | ||
} | ||
} |