Example #1
0
func create(se *api.SessionEntry, noChecks bool, client consuladapter.Client) (string, string, error) {
	session := client.Session()
	agent := client.Agent()

	nodeName, err := agent.NodeName()
	if err != nil {
		return "", "", err
	}

	nodeSessions, _, err := session.Node(nodeName, nil)
	if err != nil {
		return "", "", err
	}

	sessions := findSessions(se.Name, nodeSessions)
	if sessions != nil {
		for _, s := range sessions {
			_, err = session.Destroy(s.ID, nil)
			if err != nil {
				return "", "", err
			}
		}
	}

	var f func(*api.SessionEntry, *api.WriteOptions) (string, *api.WriteMeta, error)
	if noChecks {
		f = session.CreateNoChecks
	} else {
		f = session.Create
	}

	id, _, err := f(se, nil)
	if err != nil {
		return "", "", err
	}

	return id, se.TTL, nil
}
			Address: "127.0.0.1",
		}
	})

	JustBeforeEach(func() {
		registrationRunner := locket.NewRegistrationRunner(logger, registration, consulClient, 5*time.Second, clock)
		registrationProcess = ginkgomon.Invoke(registrationRunner)
	})

	AfterEach(func() {
		ginkgomon.Kill(registrationProcess)
	})

	Context("when the service has not already been registered", func() {
		It("registers the service", func() {
			services, err := consulClient.Agent().Services()
			Expect(err).NotTo(HaveOccurred())
			service, ok := services[registration.ID]
			Expect(ok).To(BeTrue())
			Expect(*service).To(Equal(api.AgentService{
				ID:      registration.ID,
				Service: registration.Name,
				Tags:    registration.Tags,
				Port:    registration.Port,
				Address: registration.Address,
			}))
		})

		Context("when using a TTL check", func() {
			BeforeEach(func() {
				registration.Check = &api.AgentServiceCheck{