var routingTable models.RoutingTable BeforeEach(func() { routingTable = models.NewRoutingTable() }) Describe("Set", func() { Context("when a new entry is added", func() { It("adds the entry", func() { routingKey := models.RoutingKey{12} routingTableEntry := models.RoutingTableEntry{ Backends: map[models.BackendServerInfo]struct{}{ models.BackendServerInfo{"some-ip", 1234}: struct{}{}, }, } ok := routingTable.Set(routingKey, routingTableEntry) Expect(ok).To(BeTrue()) Expect(routingTable.Get(routingKey)).To(Equal(routingTableEntry)) Expect(routingTable.Size()).To(Equal(1)) }) }) Context("when setting pre-existing routing key", func() { var ( routingKey models.RoutingKey existingRoutingTableEntry models.RoutingTableEntry ) BeforeEach(func() { routingKey = models.RoutingKey{12} existingRoutingTableEntry = models.RoutingTableEntry{ Backends: map[models.BackendServerInfo]struct{}{
fakeTokenFetcher.FetchTokenReturns(token, nil) tmpRoutingTable := models.NewRoutingTable() routingTable = &tmpRoutingTable updater = routing_table.NewUpdater(logger, routingTable, fakeConfigurer, fakeRoutingApiClient, fakeTokenFetcher) }) Describe("HandleEvent", func() { BeforeEach(func() { existingRoutingKey1 = models.RoutingKey{externalPort1} existingRoutingTableEntry1 = models.NewRoutingTableEntry( models.BackendServerInfos{ models.BackendServerInfo{"some-ip-1", 1234}, models.BackendServerInfo{"some-ip-2", 1234}, }, ) Expect(routingTable.Set(existingRoutingKey1, existingRoutingTableEntry1)).To(BeTrue()) existingRoutingKey2 = models.RoutingKey{externalPort2} existingRoutingTableEntry2 = models.NewRoutingTableEntry( models.BackendServerInfos{ models.BackendServerInfo{"some-ip-3", 2345}, models.BackendServerInfo{"some-ip-4", 2345}, }, ) Expect(routingTable.Set(existingRoutingKey2, existingRoutingTableEntry2)).To(BeTrue()) updater = routing_table.NewUpdater(logger, routingTable, fakeConfigurer, fakeRoutingApiClient, fakeTokenFetcher) }) Context("when Upsert event is received", func() { Context("when entry does not exist", func() {