Ejemplo n.º 1
0
func TestClientSuite_MockTransport(t *testing.T) {
	suite.Run(t, &clientSuite{
		TransF: func() transport.Transport {
			return mock.NewTransport()
		},
	})
}
Ejemplo n.º 2
0
func TestServerSuite_MockTransport(t *testing.T) {
	suite.Run(t, &serverSuite{
		TransF: func() transport.Transport {
			return mock.NewTransport()
		},
	})
}
Ejemplo n.º 3
0
func (suite *parentRequestIdMiddlewareSuite) SetupTest() {
	suite.trans = mock.NewTransport()
	suite.srv = server.NewServer(testServiceName)
	suite.srv.AddMiddleware(Middleware())

	suite.srv.AddEndpoints(
		server.Endpoint{
			Name:     "foo",
			Request:  &testproto.DummyRequest{},
			Response: &testproto.DummyResponse{},
			Handler: func(req mercury.Request) (mercury.Response, error) {

				// Assert first call has correct origin
				suite.Assert().Equal(testOriginServiceName, OriginServiceFor(req))
				suite.Assert().Equal("e2etest", OriginEndpointFor(req))

				// Assert first call has updated to the current service
				suite.Assert().Equal(testServiceName, CurrentServiceFor(req))
				suite.Assert().Equal("foo", CurrentEndpointFor(req))

				cl := client.NewClient().
					SetTransport(suite.trans).
					SetMiddleware([]client.ClientMiddleware{Middleware()}).
					Add(
						client.Call{
							Uid:      "call",
							Service:  testServiceName,
							Endpoint: "foo-2",
							Body:     &testproto.DummyRequest{},
							Response: &testproto.DummyResponse{},
							Context:  req,
						}).
					Execute()
				return cl.Response("call"), cl.Errors().Combined()
			}},
		server.Endpoint{
			Name:     "foo-2",
			Request:  &testproto.DummyRequest{},
			Response: &testproto.DummyResponse{},
			Handler: func(req mercury.Request) (mercury.Response, error) {

				// Assert origin headers were set correctly as previous service
				suite.Assert().Equal(testServiceName, OriginServiceFor(req))
				suite.Assert().Equal("foo", OriginEndpointFor(req))

				// And that our current service's headers were set
				suite.Assert().Equal(testServiceName, CurrentServiceFor(req))
				suite.Assert().Equal("foo-2", CurrentEndpointFor(req))

				return req.Response(&testproto.DummyResponse{
					Pong: ParentRequestIdFor(req)}), nil
			}})
	suite.srv.Start(suite.trans)
}
Ejemplo n.º 4
0
func init() {
	SetDefaultTransport(mock.NewTransport())
}