func createConfig() string { configFilePath := fmt.Sprintf("/tmp/example_%d.yml", GinkgoParallelNode()) err := utils.WriteToFile( []byte( `log_guid: "my_logs" uaa_verification_key: "-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHFr+KICms+tuT1OXJwhCUmR2d KVy7psa8xzElSyzqx7oJyfJ1JZyOzToj9T5SfTIq396agbHJWVfYphNahvZ/7uMX qHxf+ZH9BL1gk9Y6kCnbM5R60gfwjyW1/dQPjOzn9N394zd2FJoFHwdq9Qs0wBug spULZVNRxq7veq/fzwIDAQAB -----END PUBLIC KEY-----" debug_address: "1.2.3.4:1234" metron_config: address: "1.2.3.4" port: "4567" metrics_reporting_interval: "500ms" statsd_endpoint: "localhost:8125" statsd_client_flush_interval: "10ms" max_concurrent_etcd_requests: 10`), configFilePath) Expect(err).ShouldNot(HaveOccurred()) Expect(utils.FileExists(configFilePath)).To(BeTrue()) return configFilePath }
generatedHaproxyCfgFile = testutil.RandomFileName("fixtures/haproxy_", ".cfg") haproxyCfgBackupFile = fmt.Sprintf("%s.bak", generatedHaproxyCfgFile) utils.CopyFile(haproxyConfigTemplate, generatedHaproxyCfgFile) haproxyConfigTemplateContent, err = ioutil.ReadFile(generatedHaproxyCfgFile) Expect(err).ShouldNot(HaveOccurred()) haproxyConfigurer, err = haproxy.NewHaProxyConfigurer(logger, haproxyConfigTemplate, generatedHaproxyCfgFile) Expect(err).ShouldNot(HaveOccurred()) }) AfterEach(func() { 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())
err := utils.CopyFile("fixtures/test_file", "fixtures-does-not-exist/file_does_not_exist") Expect(err).Should(HaveOccurred()) }) }) }) Context("when source file does not exist ", func() { It("returns error", func() { err := utils.CopyFile("fixtures-does-not-exist/file_does_not_exist", "fixtures/destination-file") Expect(err).Should(HaveOccurred()) }) }) }) Describe("FileExists", func() { Context("when file exists", func() { It("it returns true", func() { Expect(utils.FileExists("fixtures/test_file")).To(Equal(true)) }) }) Context("when file does not exists", func() { It("it returns false", func() { Expect(utils.FileExists("fixtures/non_existing_test_file")).To(Equal(false)) }) }) }) })
haproxyConfigFile = path.Join(os.TempDir(), randomFileName) haproxyConfigBackupFile = path.Join(os.TempDir(), randomBackupFileName) haproxyBaseConfigFile = path.Join(os.TempDir(), randomBaseFileName) err := utils.WriteToFile( []byte( `global maxconn 4096 defaults log global timeout connect 300000 timeout client 300000 timeout server 300000 maxconn 2000`), haproxyBaseConfigFile) Expect(err).ShouldNot(HaveOccurred()) Expect(utils.FileExists(haproxyBaseConfigFile)).To(BeTrue()) err = utils.CopyFile(haproxyBaseConfigFile, haproxyConfigFile) Expect(err).ShouldNot(HaveOccurred()) Expect(utils.FileExists(haproxyConfigFile)).To(BeTrue()) etcdPort = 4001 + GinkgoParallelNode() etcdUrl = fmt.Sprintf("http://127.0.0.1:%d", etcdPort) etcdRunner = etcdstorerunner.NewETCDClusterRunner(etcdPort, 1, nil) etcdRunner.Start() etcdAdapter = etcdRunner.Adapter(nil) routingAPIPort = uint16(6900 + GinkgoParallelNode()) routingAPIIP = "127.0.0.1" routingAPISystemDomain = "example.com"
} generateConfigFile := func(oauthServerPort, routingApiServerPort string, routingApiAuthDisabled bool) string { randomConfigFileName := testutil.RandomFileName("router_configurer", ".yml") configFile := path.Join(os.TempDir(), randomConfigFileName) cfg := fmt.Sprintf("%s\n port: %s\n%s\n auth_disabled: %t\n %s\n port: %s\n", `oauth: token_endpoint: "http://127.0.0.1" client_name: "someclient" client_secret: "somesecret"`, oauthServerPort, `routing_api:`, routingApiAuthDisabled, `uri: http://127.0.0.1`, routingApiServerPort) err := utils.WriteToFile([]byte(cfg), configFile) Expect(err).ShouldNot(HaveOccurred()) Expect(utils.FileExists(configFile)).To(BeTrue()) return configFile } verifyHaProxyConfigContent := func(haproxyFileName, expectedContent string) { data, err := ioutil.ReadFile(haproxyFileName) Expect(err).ShouldNot(HaveOccurred()) Expect(string(data)).Should(ContainSubstring(expectedContent)) } var ( externalIP string oauthServer *ghttp.Server server ifrit.Process logger *lagertest.TestLogger session *gexec.Session