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 }
fileContent string ) BeforeEach(func() { fileName = testutil.RandomFileName("fixtures/file_", "") fileContent = "some content" }) AfterEach(func() { err := os.Remove(fileName) Expect(err).ShouldNot(HaveOccurred()) }) Context("when valid content is passed", func() { It("writes to destination file", func() { err := utils.WriteToFile([]byte(fileContent), fileName) Expect(err).ShouldNot(HaveOccurred()) actualContent, err := ioutil.ReadFile(fileName) Expect(err).ShouldNot(HaveOccurred()) Expect(string(actualContent)).To(Equal(fileContent)) }) }) Context("when empty content is passed", func() { It("create an empty file", func() { err := utils.WriteToFile(nil, fileName) Expect(err).ShouldNot(HaveOccurred()) actualContent, err := ioutil.ReadFile(fileName) Expect(err).ShouldNot(HaveOccurred()) Expect(actualContent).Should(HaveLen(0)) })
routingAPIBinPath = context["routing-api"] }) var _ = BeforeEach(func() { randomFileName := testutil.RandomFileName("haproxy_", ".cfg") randomBackupFileName := fmt.Sprintf("%s.bak", randomFileName) randomBaseFileName := testutil.RandomFileName("haproxy_base_", ".cfg") 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()
return ifrit.Invoke(server) } 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