File: overridable_controller_test.go

package info (click to toggle)
golang-go.uber-mock 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: sh: 37; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 801 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
	}
}