err := os.Remove(generatedHaproxyCfgFile)
				Expect(err).ShouldNot(HaveOccurred())

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

			Context("when CreateExternalPortMappings is called once", func() {
				Context("when only one mapping is provided as part of request", func() {

					BeforeEach(func() {
						routingTable := models.NewRoutingTable()
						routingTableEntry := models.NewRoutingTableEntry(
							models.BackendServerInfos{
								models.BackendServerInfo{"some-ip-1", 1234},
								models.BackendServerInfo{"some-ip-2", 1235},
							},
						)
						routinTableKey := models.RoutingKey{Port: 2222}
						ok := routingTable.Set(routinTableKey, routingTableEntry)
						Expect(ok).To(BeTrue())
						err = haproxyConfigurer.Configure(routingTable)
						Expect(err).ShouldNot(HaveOccurred())
					})

					It("appends the haproxy config with new listen configuration", func() {
						listenCfg :=
							"\nlisten listen_cfg_2222\n  mode tcp\n  bind :2222\n"
						serverConfig1 := "server server_some-ip-1_1234 some-ip-1:1234"
						serverConfig2 := "server server_some-ip-2_1235 some-ip-2:1235"
						verifyHaProxyConfigContent(generatedHaproxyCfgFile, listenCfg, true)
Ejemplo n.º 2
0
		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())

			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)
		})