示例#1
0
func TestMe(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	t1 := time.Time{}

	time.MOCK().SetController(ctrl)
	time.EXPECT().Now().Return(t1)
	t1.EXPECT().String().Return("wibble")

	if RunMe() != "Time: wibble" {
		t.Errorf("expected mock time")
	}
}
示例#2
0
func TestMe(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	l := net.MOCK().NewListener()
	c := net.MOCK().NewConn()

	addr := ":8080"

	net.MOCK().SetController(ctrl)
	http.MOCK().SetController(ctrl)

	gomock.InOrder(
		net.EXPECT().Listen("tcp", addr).Return(l, nil),
		time.EXPECT().Sleep(2*time.Second),
	)

	if RunMe(addr) != nil {
		t.Errorf("didn't expect error")
	}
}