Ejemplo n.º 1
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.º 2
0
// New creates a new service with default middleware
func New(cfg Config) Service {
	if cfg.Transport == nil {
		cfg.Transport = transport.DefaultTransport()
	}

	srv := server.NewServer(cfg.Name)
	srv.SetMiddleware(DefaultServerMiddleware())

	return &svc{
		srv:    srv,
		config: cfg,
	}
}
Ejemplo n.º 3
0
func (suite *clientServerSuite) SetupTest() {
	suite.server = server.NewServer(testServiceName)
	suite.server.SetMiddleware(DefaultServerMiddleware())
	suite.server.Start(suite.trans)
}