Esempio n. 1
0
	Context("Each", func() {
		It("applies a function to each endpoint", func() {
			e1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", modTag)
			e2 := route.NewEndpoint("", "5.6.7.8", 1234, "", nil, -1, "", modTag)
			pool.Put(e1)
			pool.Put(e2)

			endpoints := make(map[string]*route.Endpoint)
			pool.Each(func(e *route.Endpoint) {
				endpoints[e.CanonicalAddr()] = e
			})
			Expect(endpoints).To(HaveLen(2))
			Expect(endpoints[e1.CanonicalAddr()]).To(Equal(e1))
			Expect(endpoints[e2.CanonicalAddr()]).To(Equal(e2))
		})
	})

	It("marshals json", func() {
		e := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "https://my-rs.com", modTag)
		e2 := route.NewEndpoint("", "5.6.7.8", 5678, "", nil, -1, "", modTag)
		pool.Put(e)
		pool.Put(e2)

		json, err := pool.MarshalJSON()
		Expect(err).ToNot(HaveOccurred())

		Expect(string(json)).To(Equal(`[{"address":"1.2.3.4:5678","ttl":-1,"route_service_url":"https://my-rs.com"},{"address":"5.6.7.8:5678","ttl":-1}]`))
	})
})