allLegacy = map[string]string{ "a": "udp://lahost:laport", "b": "udp://lbhost:lbport", } }) JustBeforeEach(func() { pool = clientpool.NewDopplerPool(logger, clientFactory) }) Describe("Setters", func() { Context("non-Legacy servers", func() { Context("with preferred servers", func() { It("has only preferred servers", func() { pool.Set(allServers, preferredServers) Expect(urls(pool.Clients())).To(ConsistOf(values(preferredServers))) }) }) Context("with no preferred servers", func() { It("has only non-preferred servers", func() { pool.Set(allServers, nil) Expect(urls(pool.Clients())).To(ConsistOf(values(allServers))) }) }) Context("when the client factory errors", func() { BeforeEach(func() { logger = loggertesthelper.Logger() loggertesthelper.TestLoggerSink.Clear()
Context("with successful client creation", func() { var clients []clientpool.Client BeforeEach(func() { clients = []clientpool.Client{ newMockClient(), newMockClient(), } close(mockClientCreator.CreateClientOutput.err) mockClientCreator.CreateClientOutput.client <- clients[0] mockClientCreator.CreateClientOutput.client <- clients[1] }) It("creates a client for each address", func() { Expect(pool.Clients()).To(HaveLen(0)) clients := pool.SetAddresses(addresses) Expect(clients).To(Equal(2)) Eventually(mockClientCreator.CreateClientInput.url).Should(Receive(Equal(addresses[0]))) Eventually(mockClientCreator.CreateClientInput.url).Should(Receive(Equal(addresses[1]))) Expect(pool.Clients()).To(HaveLen(2)) }) }) Context("with failed client creation", func() { var err error BeforeEach(func() {