func (runner *clusterTestRunner) streamLogs(timeout time.Duration, appName string, args ...string) *gexec.Session { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to stream logs from %s", appName))) command := runner.command("logs", appName) session, err := gexec.Start(command, getStyledWriter("logs"), getStyledWriter("logs")) Expect(err).NotTo(HaveOccurred()) return session }
func (runner *clusterTestRunner) removeApp(timeout time.Duration, appName string, args ...string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to remove app %s", appName))) command := runner.command("remove", appName) session, err := gexec.Start(command, getStyledWriter("remove"), getStyledWriter("remove")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) }
func (runner *clusterTestRunner) streamDebugLogs(timeout time.Duration, args ...string) *gexec.Session { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline("Attempting to stream cluster debug logs")) command := runner.command("debug-logs") session, err := gexec.Start(command, getStyledWriter("debug"), getStyledWriter("debug")) Expect(err).NotTo(HaveOccurred()) return session }
func (runner *integrationTestRunner) scaleApp(timeout time.Duration, appName string, args ...string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to scale %s", appName))) command := runner.command("scale", appName, "3") session, err := gexec.Start(command, getStyledWriter("scale"), getStyledWriter("scale")) Expect(err).ToNot(HaveOccurred()) expectExit(timeout, session) }
func (runner *clusterTestRunner) scaleApp(timeout time.Duration, appName string, args ...string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to scale %s", appName))) command := runner.command("scale", appName, "3") session, err := gexec.Start(command, getStyledWriter("scale"), getStyledWriter("scale")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say("App Scaled Successfully")) }
func (runner *clusterTestRunner) launchDroplet(timeout time.Duration, appName, dropletName string, args ...string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Launching droplet %s as %s", dropletName, appName))) launchArgs := append([]string{"launch-droplet", appName, dropletName}, args...) command := runner.command(launchArgs...) session, err := gexec.Start(command, getStyledWriter("launch-droplet"), getStyledWriter("launch-droplet")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say(appName + " is now running.")) }
func (runner *clusterTestRunner) buildDroplet(timeout time.Duration, dropletName, buildpack, srcDir string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Submitting build of %s with buildpack %s", dropletName, buildpack))) command := runner.command("build-droplet", dropletName, buildpack, "--timeout", timeout.String()) command.Dir = srcDir session, err := gexec.Start(command, getStyledWriter("build-droplet"), getStyledWriter("build-droplet")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say("Submitted build of " + dropletName)) }
func (runner *clusterTestRunner) removeDroplet(timeout time.Duration, dropletName string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to remove droplet %s", dropletName))) command := runner.command("remove-droplet", dropletName) session, err := gexec.Start(command, getStyledWriter("remove-droplet"), getStyledWriter("remove-droplet")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say("Droplet removed")) fmt.Fprintln(getStyledWriter("test"), "Removed", dropletName) }
func (runner *clusterTestRunner) listDroplets(timeout time.Duration, dropletName string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline("Attempting to find droplet in the list")) command := runner.command("list-droplets") session, err := gexec.Start(command, getStyledWriter("list-droplets"), getStyledWriter("list-droplets")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say(dropletName)) fmt.Fprintln(getStyledWriter("test"), "Found", dropletName, "in the list!") }
func (runner *clusterTestRunner) updateApp(timeout time.Duration, appName string, args ...string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to update %s", appName))) updateArgs := append([]string{"update", appName}, args...) command := runner.command(updateArgs...) session, err := gexec.Start(command, getStyledWriter("update"), getStyledWriter("update")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say("Updating " + appName + " routes")) fmt.Fprintln(getStyledWriter("test"), "Yay! updated", appName) }
func (runner *clusterTestRunner) createDockerApp(timeout time.Duration, appName, dockerPath string, args ...string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to create %s", appName))) createArgs := append([]string{"create", appName, dockerPath}, args...) command := runner.command(createArgs...) session, err := gexec.Start(command, getStyledWriter("create"), getStyledWriter("create")) Expect(err).NotTo(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say(appName + " is now running.")) fmt.Fprintln(getStyledWriter("test"), "Yay! Created", appName) }
func (runner *integrationTestRunner) uploadBits(timeout time.Duration, dropletName, bits string) { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to upload %s to %s", bits, dropletName))) command := runner.command("upload-bits", dropletName, bits) session, err := gexec.Start(command, getStyledWriter("upload-bits"), getStyledWriter("upload-bits")) Expect(err).ToNot(HaveOccurred()) expectExit(timeout, session) Expect(session.Out).To(gbytes.Say("Successfully uploaded " + dropletName)) fmt.Fprintln(getStyledWriter("test"), "Uploaded", bits, "to", dropletName) }
func (runner *clusterTestRunner) checkIfTaskCompleted(taskName string) func() bool { fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline("Waiting for task "+taskName+" to complete")) return func() bool { command := runner.command("task", taskName) session, err := gexec.Start(command, getStyledWriter("task"), getStyledWriter("task")) if err != nil { panic(err) } if exitCode := session.Wait().ExitCode(); exitCode != 0 { return true } return bytes.Contains(session.Out.Contents(), []byte("COMPLETED")) } }
func (runner *clusterTestRunner) cloneRepo(timeout time.Duration, repoURL string) string { tmpDir, err := ioutil.TempDir("", "repo") Expect(err).NotTo(HaveOccurred()) fmt.Fprintln(getStyledWriter("test"), colors.PurpleUnderline(fmt.Sprintf("Attempting to clone %s to %s", repoURL, tmpDir))) command := exec.Command("/usr/bin/env", "git", "clone", repoURL, tmpDir) session, err := gexec.Start(command, getStyledWriter("git-clone"), getStyledWriter("git-clone")) Expect(err).NotTo(HaveOccurred()) expectExitInBuffer(timeout, session, session.Err) Eventually(session.Err).Should(gbytes.Say(fmt.Sprintf("Cloning into '%s'...", tmpDir))) fmt.Fprintf(getStyledWriter("test"), "Cloned %s into %s\n", repoURL, tmpDir) return tmpDir }
}) itShouldNotColorizeWhitespace(colors.Gray) }) Describe("Bold", func() { It("adds the bold color code", func() { Expect(colors.Bold("Bold")).To(Equal("\x1b[1mBold\x1b[0m")) }) itShouldNotColorizeWhitespace(colors.Bold) }) Describe("PurpleUnderline", func() { It("adds the purple underlined color code", func() { Expect(colors.PurpleUnderline("PURPLE UNDERLINE")).To(Equal("\x1b[35;4mPURPLE UNDERLINE\x1b[0m")) }) itShouldNotColorizeWhitespace(colors.PurpleUnderline) }) Describe("NoColor", func() { It("adds no color code", func() { Expect(colors.NoColor("None")).To(Equal("\x1b[0mNone\x1b[0m")) }) itShouldNotColorizeWhitespace(colors.NoColor) }) })