コード例 #1
0
				err := os.Remove(generatedHaproxyCfgFile)
				Expect(err).ShouldNot(HaveOccurred())

				Expect(utils.FileExists(haproxyCfgBackupFile)).To(BeTrue())
				err = os.Remove(haproxyCfgBackupFile)
				Expect(err).ShouldNot(HaveOccurred())
			})

			It("doesn't update config file with invalid routing table entry", func() {
				invalidRoutingKey := models.RoutingKey{Port: 0}
				invalidRoutingTableEntry := models.RoutingTableEntry{
					Backends: map[models.BackendServerInfo]struct{}{
						models.BackendServerInfo{"some-ip-1", 1234}: struct{}{},
					},
				}
				routingTable := models.NewRoutingTable()
				ok := routingTable.Set(invalidRoutingKey, invalidRoutingTableEntry)
				Expect(ok).To(BeTrue())

				routingKey := models.RoutingKey{Port: 80}
				routingTableEntry := models.RoutingTableEntry{
					Backends: map[models.BackendServerInfo]struct{}{
						models.BackendServerInfo{"some-ip-2", 1234}: struct{}{},
					},
				}
				ok = routingTable.Set(routingKey, routingTableEntry)
				Expect(ok).To(BeTrue())

				err := haproxyConfigurer.Configure(routingTable)
				Expect(err).ShouldNot(HaveOccurred())
コード例 #2
0
	verifyRoutingTableEntry := func(key models.RoutingKey, entry models.RoutingTableEntry) {
		existingEntry := routingTable.Get(key)
		Expect(existingEntry).NotTo(BeZero())
		Expect(existingEntry).Should(Equal(entry))
	}

	BeforeEach(func() {
		fakeConfigurer = new(fakes.FakeRouterConfigurer)
		fakeRoutingApiClient = new(fake_routing_api.FakeClient)
		fakeTokenFetcher = &testTokenFetcher.FakeTokenFetcher{}
		token := &token_fetcher.Token{
			AccessToken: "access_token",
			ExpireTime:  5,
		}
		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())