import ( "time" "github.com/cloudfoundry-incubator/cf-test-helpers/runner" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gbytes" . "github.com/onsi/gomega/gexec" ) const CMD_TIMEOUT = 10 * time.Second var _ = Describe("Run", func() { It("runs the given command in a cmdtest Session", func() { session := runner.Run("bash", "-c", "echo hi out; echo hi err 1>&2; exit 42").Wait(CMD_TIMEOUT) Expect(session).To(Exit(42)) Expect(session.Out).To(Say("hi out")) Expect(session.Err).To(Say("hi err")) }) }) var _ = Describe("Curl", func() { It("outputs the body of the given URL", func() { session := runner.Curl("-I", "http://example.com").Wait(CMD_TIMEOUT) Expect(session).To(Exit(0)) Expect(session.Out).To(Say("HTTP/1.1 200 OK")) }) })
It("can copy package bits to another app and download the package", func() { destinationAppName := generator.PrefixedRandomName("CATS-APP-") destinationAppGuid = CreateApp(destinationAppName, spaceGuid, "{}") // COPY copyUrl := fmt.Sprintf("/v3/apps/%s/packages?source_package_guid=%s", destinationAppGuid, packageGuid) session := cf.Cf("curl", copyUrl, "-X", "POST") bytes := session.Wait(DEFAULT_TIMEOUT).Out.Contents() var pac struct { Guid string `json:"guid"` } json.Unmarshal(bytes, &pac) copiedPackageGuid := pac.Guid WaitForPackageToBeReady(copiedPackageGuid) tmpdir, err := ioutil.TempDir(os.TempDir(), "package-download") Expect(err).ToNot(HaveOccurred()) app_package_path := path.Join(tmpdir, destinationAppName) // DOWNLOAD session = cf.Cf("curl", fmt.Sprintf("/v3/packages/%s/download", copiedPackageGuid), "--output", app_package_path).Wait(DEFAULT_TIMEOUT) Expect(session).To(Exit(0)) session = runner.Run("unzip", "-l", app_package_path) Expect(session.Wait(DEFAULT_TIMEOUT)).To(Exit(0)) Expect(session.Out).To(Say("dora.rb")) }) })
func GetAuthToken() string { bytes := runner.Run("bash", "-c", "cf oauth-token | tail -n +4").Wait(DEFAULT_TIMEOUT).Out.Contents() return strings.TrimSpace(string(bytes)) }
package cf import ( "github.com/cloudfoundry-incubator/cf-test-helpers/runner" . "github.com/onsi/gomega/gexec" ) var Cf = func(args ...string) *Session { return runner.Run("gcf", args...) }
} json.Unmarshal(bytes, &app) appGuid = app.Guid // CREATE PACKAGE packageCreateUrl := fmt.Sprintf("/v3/apps/%s/packages", appGuid) session = cf.Cf("curl", packageCreateUrl, "-X", "POST", "-d", fmt.Sprintf(`{"type":"bits"}`)) bytes = session.Wait(DEFAULT_TIMEOUT).Out.Contents() var pac struct { Guid string `json:"guid"` } json.Unmarshal(bytes, &pac) packageGuid = pac.Guid // UPLOAD PACKAGE bytes = runner.Run("bash", "-c", "cf oauth-token | tail -n +4").Wait(DEFAULT_TIMEOUT).Out.Contents() token = strings.TrimSpace(string(bytes)) doraZip := fmt.Sprintf(`bits=@"%s"`, assets.NewAssets().DoraZip) uploadUrl := fmt.Sprintf("%s/v3/packages/%s/upload", config.ApiEndpoint, packageGuid) _, err := exec.Command("curl", "-v", "-s", uploadUrl, "-F", doraZip, "-H", fmt.Sprintf("Authorization: %s", token)).CombinedOutput() Expect(err).NotTo(HaveOccurred()) pkgUrl := fmt.Sprintf("/v3/packages/%s", packageGuid) Eventually(func() *Session { session = cf.Cf("curl", pkgUrl) Expect(session.Wait(DEFAULT_TIMEOUT)).To(Exit(0)) return session }, 1*time.Minute).Should(Say("READY")) })
func cf(timeout time.Duration, args ...string) int { cmd := fmt.Sprintf("cf %s", strings.Join(args, " ")) sess := runner.Run("bash", "-c", cmd) return sess.Wait(timeout).ExitCode() }
"strings" "time" "github.com/cloudfoundry-incubator/cf-test-helpers/runner" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gbytes" . "github.com/onsi/gomega/gexec" ) const cmdTimeout = 30 * time.Second var _ = Describe("Run", func() { It("runs the given command in a cmdtest Session", func() { session := runner.Run("bash", "-c", "echo hi out; echo hi err 1>&2; exit 42").Wait(cmdTimeout) Expect(session).To(Exit(42)) Expect(session.Out).To(Say("hi out")) Expect(session.Err).To(Say("hi err")) }) }) var _ = Describe("Curl", func() { It("outputs the body of the given URL", func() { session := runner.Curl("-I", "http://example.com").Wait(cmdTimeout) Expect(session).To(Exit(0)) Expect(session.Out).To(Say("HTTP/1.1 200 OK")) }) }) var _ = Describe("cmdRunner", func() {