Example #1
0
func (r *ConsulAdapter) Register(service *bridge.Service) error {
	registration := new(consulapi.AgentServiceRegistration)
	registration.ID = service.ID
	registration.Name = service.Name
	registration.Port = service.Port
	registration.Tags = service.Tags
	registration.Address = service.IP
	registration.Checks = r.buildChecks(service)
	return r.client.Agent().ServiceRegister(registration)
}
	})

	JustBeforeEach(func() {
		registrationRunner = locket.NewRegistrationRunner(logger, registration, client, 5*time.Second, clock)
	})

	Context("when the service is invalid", func() {
		JustBeforeEach(func() {
			registrationProcess = ifrit.Background(registrationRunner)
		})

		Context("when the service has a value in the Checks list", func() {
			BeforeEach(func() {
				registration.Checks = []*api.AgentServiceCheck{
					&api.AgentServiceCheck{
						TTL: "1m",
					},
				}
			})

			It("returns a validation error", func() {
				Eventually(registrationProcess.Wait()).Should(Receive(MatchError("Support for multiple service checks not implemented")))
			})

			It("does not become ready", func() {
				Consistently(registrationProcess.Ready()).Should(Not(BeClosed()))
			})

			It("does not try to register the service", func() {
				Consistently(agent.ServiceRegisterCallCount).Should(Equal(0))
			})