Пример #1
0
	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"
	routingAPIAddress = fmt.Sprintf("http://%s:%d", routingAPIIP, routingAPIPort)
				Expect(err).Should(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring(cf_tcp_router.ErrRouterConfigFileNotFound))
			})
		})

		Context("when invalid routing table is passed", func() {
			var (
				haproxyConfigTemplateContent []byte
				generatedHaproxyCfgFile      string
				haproxyCfgBackupFile         string
				err                          error
			)
			BeforeEach(func() {
				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())
Пример #3
0
				var (
					fileName string
				)

				BeforeEach(func() {
					fileName = testutil.RandomFileName("fixtures/file_", "")
				})

				AfterEach(func() {
					err := os.Remove(fileName)
					Expect(err).ShouldNot(HaveOccurred())
				})

				It("copies to destination file ", func() {
					srcFileName := "fixtures/test_file"
					err := utils.CopyFile(srcFileName, fileName)
					Expect(err).ShouldNot(HaveOccurred())

					expectedContent, err := ioutil.ReadFile(srcFileName)
					Expect(err).ShouldNot(HaveOccurred())

					actualContent, err := ioutil.ReadFile(fileName)
					Expect(err).ShouldNot(HaveOccurred())

					Expect(actualContent).To(Equal(expectedContent))
				})
			})
			Context("when destinaiton file is invalid", func() {
				It("returns error", func() {
					err := utils.CopyFile("fixtures/test_file", "fixtures-does-not-exist/file_does_not_exist")
					Expect(err).Should(HaveOccurred())