Exemple #1
0
func TestExperiment(t *testing.T) {
	RegisterFailHandler(Fail)

	var _ = SynchronizedBeforeSuite(func() []byte {
		var s sbsState

		path, err := gexec.Build(
			"github.com/ice-stuff/clique/cmd/clique-agent",
		)
		Expect(err).NotTo(HaveOccurred())
		s.CliqueAgentBin = path

		c, err := json.Marshal(s)
		Expect(err).NotTo(HaveOccurred())

		return c
	}, func(c []byte) {
		var s sbsState

		Expect(json.Unmarshal(c, &s)).To(Succeed())

		cliqueAgentBin = s.CliqueAgentBin
	})

	var _ = SynchronizedAfterSuite(func() {
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RunSpecs(t, "Control script Suite")
}
func TestWinswPipe(t *testing.T) {
	BeforeSuite(func() {
		var err error
		pathToPipeCLI, err = gexec.Build("github.com/cloudfoundry/bosh-agent/jobsupervisor/pipe")
		Expect(err).To(Succeed())

		GoSequencePath, err = gexec.Build("./testdata/gosequence/gosequence.go")
		Expect(err).To(Succeed())
		PrintPidsPath, err = gexec.Build("./testdata/printpids/printpids.go")
		Expect(err).To(Succeed())
		ExitRunnerPath, err = gexec.Build("./testdata/exitrunner/exitrunner.go")
		Expect(err).To(Succeed())
	})

	BeforeEach(func() {
		if runtime.GOOS == "windows" {
			shell = "powershell"
			echoCmdArgs = []string{shell, "-c", "echo", echoOutput}
			SetDefaultEventuallyTimeout(5 * time.Second)
		} else {
			echoCmdArgs = []string{"echo", echoOutput}
			shell = "bash"
		}
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "WinswPipe Suite")
}
func TestLifecycle(t *testing.T) {
	SynchronizedBeforeSuite(func() []byte {
		shmPath, err := gexec.Build("github.com/cloudfoundry-incubator/garden-linux/integration/lifecycle/shm_test")
		Expect(err).ToNot(HaveOccurred())
		return []byte(shmPath)
	}, func(path []byte) {
		Expect(string(path)).NotTo(BeEmpty())
		shmTestBin = string(path)
	})

	BeforeEach(func() {
		if os.Getenv("GARDEN_TEST_ROOTFS") == "" {
			Skip("GARDEN_TEST_ROOTFS undefined")
		}
	})

	AfterEach(func() {
		err := client.DestroyAndStop()
		Expect(err).NotTo(HaveOccurred())
		client.Cleanup()
	})

	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	SetDefaultEventuallyTimeout(5 * time.Second) // CI is sometimes slow

	RegisterFailHandler(Fail)
	RunSpecs(t, "Lifecycle Suite")
}
func TestIntegration(t *testing.T) {
	var beforeSuite struct {
		RabbitMQCeBinPath string
	}

	SynchronizedBeforeSuite(func() []byte {
		var err error

		beforeSuite.RabbitMQCeBinPath, err = gexec.Build("github.com/glestaris/gofigure/integration/rabbitmq_chan_echo")
		Ω(err).ShouldNot(HaveOccurred())

		b, err := json.Marshal(beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		return b
	}, func(data []byte) {
		err := json.Unmarshal(data, &beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		RabbitMQCeBinPath = beforeSuite.RabbitMQCeBinPath
		Expect(RabbitMQCeBinPath).NotTo(BeEmpty())
	})

	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Integration Suite")
}
func TestProcess_tracker(t *testing.T) {
	var beforeSuite struct {
		IodaemonPath        string
		TestPrintSignalPath string
	}

	SynchronizedBeforeSuite(func() []byte {
		var err error
		beforeSuite.IodaemonPath, err = gexec.Build("github.com/cloudfoundry-incubator/guardian/rundmc/iodaemon/cmd/iodaemon")
		Expect(err).ToNot(HaveOccurred())

		b, err := json.Marshal(beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		return b
	}, func(paths []byte) {
		err := json.Unmarshal(paths, &beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		iodaemonBin = beforeSuite.IodaemonPath
		Expect(iodaemonBin).NotTo(BeEmpty())
	})

	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Process Tracker Suite")
}
func TestContainerDeamon(t *testing.T) {
	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "ContainerDaemon Suite")
}
func TestVerifyStrings(t *testing.T) {
	BeforeSuite(test_helpers.BuildExecutable)

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "VerifyStrings Suite")
}
Exemple #8
0
func TestRewritePackage(t *testing.T) {
	BeforeSuite(test_helpers.BuildExecutable)

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "rewrite-package Suite")
}
Exemple #9
0
func Test(t *testing.T) {
	BeforeSuite(func() {
		var err error
		spiff, err = gexec.Build("github.com/cloudfoundry-incubator/spiff")
		Ω(err).ShouldNot(HaveOccurred())
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Executable")
}
Exemple #10
0
func TestGexec(t *testing.T) {
	BeforeSuite(func() {
		var err error
		fireflyPath, err = gexec.Build("./_fixture/firefly")
		Ω(err).ShouldNot(HaveOccurred())
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Gexec Suite")
}
func TestSteganogify(t *testing.T) {

	BeforeSuite(func() {
		var err error
		steganogifyPath, err = gexec.Build("github.com/topherbullock/steganogify")
		Expect(err).ShouldNot(HaveOccurred())
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Steganogify Suite")
}
func TestSystem(t *testing.T) {
	var beforeSuite struct {
		FakeMounterPath   string
		FakeContainerPath string
		TempDirPath       string
	}

	SynchronizedBeforeSuite(func() []byte {
		var err error
		beforeSuite.FakeMounterPath, err = gexec.Build("github.com/cloudfoundry-incubator/garden-linux/containerizer/system/fake_mounter", "-race")
		Expect(err).ToNot(HaveOccurred())

		beforeSuite.FakeContainerPath, err = gexec.Build("github.com/cloudfoundry-incubator/garden-linux/containerizer/system/fake_container", "-race")
		Expect(err).ToNot(HaveOccurred())

		beforeSuite.TempDirPath, err = ioutil.TempDir("", "system-tempdir")
		Expect(err).NotTo(HaveOccurred())

		b, err := json.Marshal(beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		return b
	}, func(paths []byte) {
		err := json.Unmarshal(paths, &beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		fakeMounterBin = beforeSuite.FakeMounterPath
		Expect(fakeMounterBin).NotTo(BeEmpty())

		fakeContainerBin = beforeSuite.FakeContainerPath
		Expect(fakeContainerBin).NotTo(BeEmpty())

		tempDirPath = beforeSuite.TempDirPath
		Expect(tempDirPath).NotTo(BeEmpty())
	})

	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()

		// Cleaning up this directoy causes the VM to hang occasionally.
		// Expect(os.RemoveAll(tempDirPath)).To(Succeed())
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "System Suite")
}
func TestIntegration(t *testing.T) {

	// build main program for testing
	SynchronizedBeforeSuite(func() []byte {
		jbmcExec, err := gexec.Build("github.com/cloudfoundry/java-buildpack-memory-calculator", "-a", "-race")
		Ω(err).ShouldNot(HaveOccurred())
		return []byte(jbmcExec)
	}, func(jbmcBinPath []byte) {
		jbmcExec = string(jbmcBinPath)
	})

	SynchronizedAfterSuite(func() {
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Integration Suite")
}
func TestContainerDeamon(t *testing.T) {
	var beforeSuite struct {
		WshPath         string
		ProcStarterPath string
	}

	SynchronizedBeforeSuite(func() []byte {
		var err error
		beforeSuite.WshPath, err = gexec.Build("github.com/cloudfoundry-incubator/garden-linux/container_daemon/wsh", "-race")
		Expect(err).ToNot(HaveOccurred())

		beforeSuite.ProcStarterPath, err = gexec.Build("github.com/cloudfoundry-incubator/garden-linux/container_daemon/proc_starter", "-race")
		Expect(err).ToNot(HaveOccurred())

		b, err := json.Marshal(beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		return b
	}, func(paths []byte) {
		err := json.Unmarshal(paths, &beforeSuite)
		Expect(err).ToNot(HaveOccurred())

		wshBin = beforeSuite.WshPath
		Expect(wshBin).NotTo(BeNil())

		procStarterBin = beforeSuite.ProcStarterPath
		Expect(procStarterBin).NotTo(BeNil())
	})

	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "ContainerDeamon Suite")
}
func TestSecurity(t *testing.T) {

	BeforeSuite(func() {
		containerizerBin = helpers.BuildContainerizer()
		gardenBin = helpers.BuildGarden()
	})

	BeforeEach(func() {
		gardenArgs := []string{}
		gardenProcess, client = helpers.StartGarden(gardenBin, containerizerBin, gardenArgs...)
	})

	AfterEach(func() {
		helpers.StopGarden(gardenProcess, client)
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Security Suite")
}
func TestLifecycle(t *testing.T) {

	BeforeSuite(func() {
		containerizerBin = helpers.BuildContainerizer()
		gardenBin = helpers.BuildGarden()
	})

	BeforeEach(func() {
		helpers.KillAllGarden()
		helpers.KillAllContainerizer()
	})

	AfterEach(func() {
		helpers.StopGarden(gardenProcess, client)
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Lifecycle Suite")
}
func TestLifecycle(t *testing.T) {
	SynchronizedBeforeSuite(func() []byte {
		gardenPath, err := gexec.Build("github.com/julz/garden-runc/cmd/garden-runc")
		Expect(err).ToNot(HaveOccurred())
		return []byte(gardenPath)
	}, func(gardenPath []byte) {
		gardenBin = string(gardenPath)
	})

	AfterEach(func() {
		ensureGardenRunning()
		gardenProcess.Signal(syscall.SIGQUIT)
		Eventually(gardenProcess.Wait(), 10).Should(Receive())
	})

	SynchronizedAfterSuite(func() {
		//noop
	}, func() {
		gexec.CleanupBuildArtifacts()
	})

	RegisterFailHandler(Fail)
	RunSpecs(t, "Lifecycle Suite")
}
var execPath string
var redisSession *gexec.Session

func TestIntegration(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Integration Suite")
}

var _ = BeforeSuite(func() {
	var err error
	execPath, err = gexec.Build("github.com/pivotal-cf/redis-cpu")
	Expect(err).ToNot(HaveOccurred())
})

var _ = AfterSuite(func() {
	gexec.CleanupBuildArtifacts()
})

func execBin(configPath string) *gexec.Session {
	var cmd *exec.Cmd
	if configPath != "" {
		cmd = exec.Command(execPath, "--config", configPath)
	} else {
		cmd = exec.Command(execPath)
	}

	session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
	Expect(err).ToNot(HaveOccurred())
	Eventually(session).Should(gexec.Exit())
	return session
}
func defineTheGinkgoTests(runner *clusterTestRunner, timeout time.Duration) {
	BeforeSuite(func() {
		if err := runner.config.Load(); err != nil {
			fmt.Fprintln(getStyledWriter("test"), "Error loading config")
			return
		}
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	Describe("Lattice cluster", func() {
		Describe("docker apps with HTTP routes", func() {
			var appName, appRoute string

			BeforeEach(func() {
				appGUID, err := uuid.NewV4()
				Expect(err).NotTo(HaveOccurred())

				appName = fmt.Sprintf("lattice-test-app-%s", appGUID.String())
				appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
			})

			AfterEach(func() {
				runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

				Eventually(errorCheckForRoute(appRoute), timeout, 1).Should(HaveOccurred())
			})

			It("should run with the provided ltc options", func() {
				debugLogsStream := runner.streamDebugLogs(timeout)
				defer func() { killSession(debugLogsStream) }()

				runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app", fmt.Sprintf("--timeout=%s", timeout.String()))

				Eventually(errorCheckForRoute(appRoute), timeout, 1).ShouldNot(HaveOccurred())

				Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("rep.*lattice-(colocated|cell|brain)-\\d+"))
				Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("garden-linux.*lattice-(colocated|cell|brain)-\\d+"))
				killSession(debugLogsStream)

				logsStream := runner.streamLogs(timeout, appName)
				defer func() { killSession(logsStream) }()

				Eventually(logsStream.Out, timeout).Should(gbytes.Say("Lattice-app. Says Hello."))

				resp, err := makeGetRequestToURL(appRoute + "/env")
				Expect(err).NotTo(HaveOccurred())
				defer resp.Body.Close()
				respBytes, err := ioutil.ReadAll(resp.Body)
				Expect(err).NotTo(HaveOccurred())
				Expect(respBytes).To(MatchRegexp("<dt>USER</dt><dd>lattice</dd>"))

				runner.scaleApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

				instanceCountChan := make(chan int, numCPU)
				go countInstances(appRoute, instanceCountChan)
				Eventually(instanceCountChan, timeout).Should(Receive(Equal(3)))
			})
		})

		Context("docker apps with TCP routes", func() {
			var appName string

			BeforeEach(func() {
				appGUID, err := uuid.NewV4()
				Expect(err).NotTo(HaveOccurred())

				appName = fmt.Sprintf("lattice-test-app-%s", appGUID.String())
			})

			AfterEach(func() {
				runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))
			})

			It("should run with the provided ltc options", func() {
				externalPort := uint16(rand.Intn(9999) + 50000)
				runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-tcp-test", fmt.Sprintf("--tcp-route=%d:5222", externalPort), fmt.Sprintf("--timeout=%s", timeout.String()))
				Eventually(readLineFromConnection(runner.config.Target(), externalPort), timeout, 1).Should(Equal("y"))

				externalPort++
				By("Updating the routes")
				runner.updateApp(timeout, appName, fmt.Sprintf("--tcp-route=%d:5222", externalPort))
				Eventually(readLineFromConnection(runner.config.Target(), externalPort), timeout, 1).Should(Equal("y"))
			})
		})

		Context("droplet apps", func() {
			var dropletName, appName, dropletFolderURL, appRoute string

			BeforeEach(func() {
				dropletGUID, err := uuid.NewV4()
				Expect(err).NotTo(HaveOccurred())
				dropletName = "droplet-" + dropletGUID.String()

				appName = "running-" + dropletName

				blobTarget := runner.config.BlobStore()

				if blobTarget.Username != "" {
					dropletFolderURL = fmt.Sprintf("%s:%s@%s:%s/blobs/%s",
						blobTarget.Username,
						blobTarget.Password,
						blobTarget.Host,
						blobTarget.Port,
						dropletName)
				} else {
					dropletFolderURL = fmt.Sprintf("%s:%s/blobs/%s",
						blobTarget.Host,
						blobTarget.Port,
						dropletName)
				}

				appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
			})

			AfterEach(func() {
				runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))
				Eventually(errorCheckForRoute(appRoute), timeout, .5).Should(HaveOccurred())

				runner.removeDroplet(timeout, dropletName)
			})

			It("builds, lists and launches a droplet", func() {
				By("checking out lattice-app from github")
				gitDir := runner.cloneRepo(timeout, "https://github.com/cloudfoundry-samples/lattice-app.git")
				defer os.RemoveAll(gitDir)

				By("launching a build task")
				runner.buildDroplet(timeout, dropletName, "https://github.com/cloudfoundry/go-buildpack.git", gitDir)

				Eventually(runner.checkIfTaskCompleted("build-droplet-"+dropletName), timeout, 1).Should(BeTrue())

				By("listing droplets")
				runner.listDroplets(timeout, dropletName)

				By("launching the droplet")
				runner.launchDroplet(timeout, appName, dropletName)

				Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())
			})
		})
	})
}
Exemple #20
0
func defineTheGinkgoTests(runner *clusterTestRunner, timeout time.Duration) {
	BeforeSuite(func() {
		if err := runner.config.Load(); err != nil {
			fmt.Fprintln(getStyledWriter("test"), "Error loading config")
			return
		}
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	Describe("Lattice", func() {
		Context("docker", func() {
			Context("when desiring a docker-based LRP", func() {
				var appName, appRoute string

				BeforeEach(func() {
					appGUID, err := uuid.NewV4()
					Expect(err).NotTo(HaveOccurred())

					appName = fmt.Sprintf("lattice-test-app-%s", appGUID.String())
					appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
				})

				AfterEach(func() {
					runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

					Eventually(errorCheckForRoute(appRoute), timeout, 1).Should(HaveOccurred())
				})

				It("should run a docker app", func() {
					debugLogsStream := runner.streamDebugLogs(timeout)
					defer func() { debugLogsStream.Terminate().Wait() }()

					runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app", fmt.Sprintf("--timeout=%s", timeout.String()), "--working-dir=/", "--env", "APP_NAME", "--", "/lattice-app", "--message", "Hello Lattice User", "--quiet")

					Eventually(errorCheckForRoute(appRoute), timeout, 1).ShouldNot(HaveOccurred())

					Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("rep.*cell-\\d+"))
					Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("garden-linux.*cell-\\d+"))
					debugLogsStream.Terminate().Wait()

					logsStream := runner.streamLogs(timeout, appName)
					defer func() { logsStream.Terminate().Wait() }()

					Eventually(logsStream.Out, timeout).Should(gbytes.Say("LATTICE-TEST-APP. Says Hello Lattice User."))

					runner.scaleApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

					instanceCountChan := make(chan int, numCPU)
					go countInstances(appRoute, instanceCountChan)
					Eventually(instanceCountChan, timeout).Should(Receive(Equal(3)))
				})

				It("should run a docker app using metadata from Docker Hub", func() {
					runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app")

					Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())
				})

				Context("when `--run-as-root` is passed as an argument to `ltc create`", func() {
					It("should run the app as the root user", func() {
						runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app", "--run-as-root", fmt.Sprintf("--timeout=%s", timeout.String()))

						Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())

						resp, err := makeGetRequestToURL(appRoute + "/env")
						Expect(err).NotTo(HaveOccurred())
						defer resp.Body.Close()
						respBytes, err := ioutil.ReadAll(resp.Body)
						Expect(err).NotTo(HaveOccurred())

						Expect(respBytes).To(MatchRegexp("<dt>USER</dt><dd>root</dd>"), "lattice-app should report running as root")
					})
				})
			})

			Context("when desiring a docker-based LRP with tcp routes", func() {
				var appName string

				BeforeEach(func() {
					appGUID, err := uuid.NewV4()
					Expect(err).NotTo(HaveOccurred())

					appName = fmt.Sprintf("lattice-test-app-%s", appGUID.String())
				})

				AfterEach(func() {
					runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))
				})

				It("should run a docker app exposing tcp routes", func() {
					externalPort := uint16(rand.Intn(9999) + 50000)
					runner.createDockerApp(timeout, appName, "cloudfoundry/tcp-sample-receiver", fmt.Sprintf("--tcp-routes=%d:5222", externalPort), fmt.Sprintf("--timeout=%s", timeout.String()))
					Eventually(errorCheckForConnection(runner.config.Target(), externalPort, "docker-server1"), timeout, 1).ShouldNot(HaveOccurred())

					externalPort++
					By("Updating the routes")
					runner.updateApp(timeout, appName, fmt.Sprintf("--tcp-routes=%d:5222", externalPort))
					Eventually(errorCheckForConnection(runner.config.Target(), externalPort, "docker-server1"), timeout, 1).ShouldNot(HaveOccurred())
				})
			})
		})

		Context("droplets", func() {
			var dropletName, appName, dropletFolderURL, appRoute string

			BeforeEach(func() {
				// Generate a droplet name up front so that it can persist across droplet tests
				dropletGUID, err := uuid.NewV4()
				Expect(err).NotTo(HaveOccurred())
				dropletName = "droplet-" + dropletGUID.String()

				appName = "running-" + dropletName

				blobTarget := runner.config.BlobStore()

				if blobTarget.Username != "" {
					dropletFolderURL = fmt.Sprintf("%s:%s@%s:%s/blobs/%s",
						blobTarget.Username,
						blobTarget.Password,
						blobTarget.Host,
						blobTarget.Port,
						dropletName)
				} else {
					dropletFolderURL = fmt.Sprintf("%s:%s/blobs/%s",
						blobTarget.Host,
						blobTarget.Port,
						dropletName)
				}

				appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
			})

			AfterEach(func() {
				runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))
				Eventually(errorCheckForRoute(appRoute), timeout, .5).Should(HaveOccurred())

				runner.removeDroplet(timeout, dropletName)
			})

			It("builds, lists and launches a droplet", func() {
				By("checking out lattice-app from github")
				gitDir := runner.cloneRepo(timeout, "https://github.com/cloudfoundry-samples/lattice-app.git")
				defer os.RemoveAll(gitDir)

				By("launching a build task")
				runner.buildDroplet(timeout, dropletName, "https://github.com/cloudfoundry/go-buildpack.git", gitDir)

				Eventually(runner.checkIfTaskCompleted("build-droplet-"+dropletName), timeout, 1).Should(BeTrue())

				By("listing droplets")
				runner.listDroplets(timeout, dropletName)

				By("launching the droplet")
				runner.launchDroplet(timeout, appName, dropletName)

				Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())
			})

			Context("droplet with tcp routes", func() {
				It("should build, lists and launches a droplet with tcp routes", func() {
					externalPort := uint16(rand.Intn(10000) + 50000)
					By("checking out droplet-receiver from github")
					gitDir := runner.cloneRepo(timeout, "https://github.com/cloudfoundry-incubator/cf-tcp-router-acceptance-tests.git")
					dropletDir := gitDir + "/assets/tcp-droplet-receiver"
					defer os.RemoveAll(gitDir)

					By("launching a build task")
					runner.buildDroplet(timeout, dropletName, "https://github.com/cloudfoundry/go-buildpack.git", dropletDir)

					Eventually(runner.checkIfTaskCompleted("build-droplet-"+dropletName), timeout, 1).Should(BeTrue())

					By("listing droplets")
					runner.listDroplets(timeout, dropletName)

					By("launching the droplet")
					runner.launchDroplet(timeout, appName, dropletName, fmt.Sprintf("--tcp-routes=%d:3333", externalPort), "--ports=3333")

					Eventually(errorCheckForConnection(runner.config.Target(), externalPort, "droplet_server"), timeout, 1).ShouldNot(HaveOccurred())
				})
			})
		})
	})
}
func defineTheGinkgoTests(runner *clusterTestRunner, timeout time.Duration) {
	BeforeSuite(func() {
		if err := runner.config.Load(); err != nil {
			fmt.Fprintln(getStyledWriter("test"), "Error loading config")
			return
		}
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	Describe("Lattice", func() {
		Context("docker", func() {
			Context("when desiring a docker-based LRP", func() {
				var appName, appRoute string

				BeforeEach(func() {
					appGUID, err := uuid.NewV4()
					Expect(err).NotTo(HaveOccurred())

					appName = fmt.Sprintf("lattice-test-app-%s", appGUID.String())
					appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
				})

				AfterEach(func() {
					runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

					Eventually(errorCheckForRoute(appRoute), timeout, 1).Should(HaveOccurred())
				})

				It("should run a docker app", func() {
					debugLogsStream := runner.streamDebugLogs(timeout)
					defer func() { debugLogsStream.Terminate().Wait() }()

					runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app", fmt.Sprintf("--timeout=%s", timeout.String()), "--working-dir=/", "--env", "APP_NAME", "--", "/lattice-app", "--message", "Hello Lattice User", "--quiet")

					Eventually(errorCheckForRoute(appRoute), timeout, 1).ShouldNot(HaveOccurred())

					Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("rep.*cell-\\d+"))
					Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("garden-linux.*cell-\\d+"))
					debugLogsStream.Terminate().Wait()

					logsStream := runner.streamLogs(timeout, appName)
					defer func() { logsStream.Terminate().Wait() }()

					Eventually(logsStream.Out, timeout).Should(gbytes.Say("LATTICE-TEST-APP. Says Hello Lattice User."))

					runner.scaleApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

					instanceCountChan := make(chan int, numCPU)
					go countInstances(appRoute, instanceCountChan)
					Eventually(instanceCountChan, timeout).Should(Receive(Equal(3)))
				})

				It("should run a docker app using metadata from Docker Hub", func() {
					runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app")

					Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())
				})

				Context("when the docker app requires escalated privileges to run", func() {
					It("should start the nginx app successfully", func() {
						By("passing the `--run-as-root` flag to `ltc create`")
						runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app", "--run-as-root", fmt.Sprintf("--timeout=%s", timeout.String()))

						Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())

						resp, err := makeGetRequestToURL(appRoute + "/env")
						Expect(err).NotTo(HaveOccurred())
						defer resp.Body.Close()
						respBytes, err := ioutil.ReadAll(resp.Body)
						Expect(err).NotTo(HaveOccurred())

						Expect(respBytes).To(MatchRegexp("<dt>USER</dt><dd>root</dd>"), "lattice-app should report running as root")
					})
				})
			})
		})

		Context("droplets", func() {
			var dropletName, appName, dropletFolderURL, appRoute string

			BeforeEach(func() {
				// Generate a droplet name up front so that it can persist across droplet tests
				dropletGUID, err := uuid.NewV4()
				Expect(err).NotTo(HaveOccurred())
				dropletName = "droplet-" + dropletGUID.String()

				appName = "running-" + dropletName

				blobTarget := runner.config.BlobStore()
				dropletFolderURL = fmt.Sprintf("%s:%s@%s:%s/blobs/%s",
					blobTarget.Username,
					blobTarget.Password,
					blobTarget.Host,
					blobTarget.Port,
					dropletName)

				appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
			})

			AfterEach(func() {
				runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))
				Eventually(errorCheckForRoute(appRoute), timeout, .5).Should(HaveOccurred())

				runner.removeDroplet(timeout, dropletName)
				Eventually(errorCheckURLExists(dropletFolderURL+"/droplet.tgz"), timeout, 1).Should(HaveOccurred())
			})

			It("builds, lists and launches a droplet", func() {
				By("checking out lattice-app from github")
				gitDir := runner.cloneRepo(timeout, "https://github.com/pivotal-cf-experimental/lattice-app.git")
				defer os.RemoveAll(gitDir)

				By("launching a build task")
				runner.buildDroplet(timeout, dropletName, "https://github.com/cloudfoundry/go-buildpack.git", gitDir)

				By("uploading a compiled droplet to the blob store")
				Eventually(errorCheckURLExists(dropletFolderURL+"/droplet.tgz"), timeout, 1).ShouldNot(HaveOccurred())

				By("listing droplets")
				runner.listDroplets(timeout, dropletName)

				By("launching the droplet")
				runner.launchDroplet(timeout, appName, dropletName)

				Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())
			})
		})
	})
}
func defineTheGinkgoTests(runner *integrationTestRunner, timeout time.Duration) {
	var _ = BeforeSuite(func() {
		err := runner.config.Load()
		if err != nil {
			fmt.Fprintln(getStyledWriter("test"), "Error loading config")
			return
		}
	})

	var _ = AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	var _ = Describe("Lattice", func() {
		Context("docker", func() {
			Context("when desiring a docker-based LRP", func() {

				var (
					appName string
					route   string
				)

				BeforeEach(func() {
					appGuid, err := uuid.NewV4()
					Expect(err).ToNot(HaveOccurred())

					appName = fmt.Sprintf("lattice-test-app-%s", appGuid.String())
					route = fmt.Sprintf("%s.%s", appName, runner.config.Target())
				})

				AfterEach(func() {
					runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

					Eventually(errorCheckForRoute(route), timeout, 1).Should(HaveOccurred())
				})

				It("eventually runs a docker app", func() {
					debugLogsStream := runner.streamDebugLogs(timeout)
					defer func() { debugLogsStream.Terminate().Wait() }()

					runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app", fmt.Sprintf("--timeout=%s", timeout.String()), "--working-dir=/", "--env", "APP_NAME", "--", "/lattice-app", "--message", "Hello Lattice User", "--quiet")

					Eventually(errorCheckForRoute(route), timeout, 1).ShouldNot(HaveOccurred())

					Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("rep.*cell-\\d+"))
					Eventually(debugLogsStream.Out, timeout).Should(gbytes.Say("garden-linux.*cell-\\d+"))
					debugLogsStream.Terminate().Wait()

					logsStream := runner.streamLogs(timeout, appName)
					defer func() { logsStream.Terminate().Wait() }()

					Eventually(logsStream.Out, timeout).Should(gbytes.Say("LATTICE-TEST-APP. Says Hello Lattice User."))

					runner.scaleApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))

					instanceCountChan := make(chan int, numCpu)
					go countInstances(route, instanceCountChan)
					Eventually(instanceCountChan, timeout).Should(Receive(Equal(3)))
				})

				It("eventually runs a docker app with metadata from Docker Hub", func() {
					runner.createDockerApp(timeout, appName, "cloudfoundry/lattice-app")

					Eventually(errorCheckForRoute(route), timeout, .5).ShouldNot(HaveOccurred())
				})
			})
		})

		if runner.config.BlobTarget().AccessKey != "" && runner.config.BlobTarget().SecretKey != "" {
			Context("droplets", func() {
				var dropletName, appName, dropletFolderURL, appRoute string

				BeforeEach(func() {
					// Generate a droplet name up front so that it can persist across droplet tests
					dropletGuid, err := uuid.NewV4()
					Expect(err).ToNot(HaveOccurred())
					dropletName = "droplet-" + dropletGuid.String()

					appName = "running-" + dropletName

					blobTarget := runner.config.BlobTarget()
					dropletFolderURL = fmt.Sprintf("%s:%d/%s/%s",
						blobTarget.TargetHost,
						blobTarget.TargetPort,
						blobTarget.BucketName,
						dropletName)

					appRoute = fmt.Sprintf("%s.%s", appName, runner.config.Target())
				})

				AfterEach(func() {
					runner.removeApp(timeout, appName, fmt.Sprintf("--timeout=%s", timeout.String()))
					Eventually(errorCheckForRoute(appRoute), timeout, .5).Should(HaveOccurred())

					runner.removeDroplet(timeout, dropletName)
					Eventually(errorCheckURLExists(dropletFolderURL+"/droplet.tgz"), timeout, 1).Should(HaveOccurred())
				})

				It("builds, lists and launches a droplet", func() {
					By("checking out lattice-app from github")
					gitDir := runner.cloneRepo(timeout, "https://github.com/pivotal-cf-experimental/lattice-app.git")
					defer os.RemoveAll(gitDir)

					By("launching a build task")
					runner.buildDroplet(timeout, dropletName, "https://github.com/cloudfoundry/go-buildpack.git", gitDir)

					By("uploading to the blob store")
					Eventually(errorCheckURLExists(dropletFolderURL+"/bits.tgz"), timeout, 1).ShouldNot(HaveOccurred())

					By("uploading a compiled droplet to the blob store")
					Eventually(errorCheckURLExists(dropletFolderURL+"/droplet.tgz"), timeout, 1).ShouldNot(HaveOccurred())

					By("listing droplets")
					runner.listDroplets(timeout, dropletName)

					By("launching the droplet")
					runner.launchDroplet(timeout, appName, dropletName)

					Eventually(errorCheckForRoute(appRoute), timeout, .5).ShouldNot(HaveOccurred())
				})
			})
		}
	})
}
Exemple #23
0
func Cleanup() {
	gexec.CleanupBuildArtifacts()
}