コード例 #1
0
			It("returns a ErrRouterConfigFileNotFound error", func() {
				_, err := haproxy.NewHaProxyConfigurer(logger, haproxyConfigTemplate, "file/path/does/not/exists")
				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())
コード例 #2
0
	"github.com/cloudfoundry-incubator/cf-tcp-router/utils"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Fileutils", func() {
	Describe("WriteToFile", func() {
		Context("when valid path is passed", func() {
			var (
				fileName    string
				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))
コード例 #3
0
	Expect(err).NotTo(HaveOccurred())

	return payload
}, func(payload []byte) {
	context := map[string]string{}

	err := json.Unmarshal(payload, &context)
	Expect(err).NotTo(HaveOccurred())

	routerConfigurerPort = 7000 + GinkgoParallelNode()
	routerConfigurerPath = context["router-configurer"]
	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`),
コード例 #4
0
ファイル: main_test.go プロジェクト: jmptrader/cf-tcp-router
			},
		)
		logger.Info("starting-oauth-server", lager.Data{"address": server.URL()})
		return server
	}

	routingApiServer := func(logger lager.Logger) ifrit.Process {

		server := routingtestrunner.New(routingAPIBinPath, routingAPIArgs)
		logger.Info("starting-routing-api-server")

		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
	}