Ejemplo n.º 1
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")
	}
}
Ejemplo n.º 2
0
func TestMe(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	l := net.MOCK().NewListener()
	c := net.MOCK().NewConn()
	e := fmt.Errorf("goodbye")

	net.MOCK().SetController(ctrl)

	gomock.InOrder(
		net.EXPECT().Listen("tcp", ":8080").Return(l, nil),
		l.EXPECT().Accept().Return(c, nil),
		c.EXPECT().Close(),
		l.EXPECT().Accept().Return(nil, e),
		l.EXPECT().Close(),
	)

	if RunMe() != e {
		t.Errorf("expected mock net")
	}
}