github.com/deis/workflow-e2e@v2.12.2-0.20180227201524-4105be7001fe+incompatible/tests/cmd/git/commands.go (about) 1 package git 2 3 import ( 4 "fmt" 5 "net/http" 6 "os" 7 "strconv" 8 "time" 9 10 "github.com/deis/workflow-e2e/tests/cmd" 11 "github.com/deis/workflow-e2e/tests/model" 12 "github.com/deis/workflow-e2e/tests/settings" 13 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gbytes" 16 . "github.com/onsi/gomega/gexec" 17 ) 18 19 // The functions in this file implement SUCCESS CASES for commonly used `git` commands. 20 // This allows each of these to be re-used easily in multiple contexts. 21 22 const ( 23 pushCommandLineString = "GIT_SSH=%s GIT_KEY=%s git push deis master" 24 ) 25 26 // Push executes a `git push deis master` from the current directory using the provided key. 27 func Push(user model.User, keyPath string, app model.App, banner string) { 28 sess := StartPush(user, keyPath) 29 // sess.Wait(settings.MaxEventuallyTimeout) 30 // output := string(sess.Out.Contents()) 31 // Expect(output).To(MatchRegexp(`Done, %s:v\d deployed to Deis`, app.Name)) 32 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 33 Curl(app, banner) 34 } 35 36 // Curl polls an app over HTTP until it returns the expected "Powered by" banner. 37 func Curl(app model.App, banner string) { 38 // curl the app's root URL and print just the HTTP response code 39 cmdRetryTimeout := 60 40 curlCmd := model.Cmd{CommandLineString: fmt.Sprintf( 41 `curl -sL -w "%%{http_code}\\n" "%s" -o /dev/null`, app.URL)} 42 Eventually(cmd.Retry(curlCmd, strconv.Itoa(http.StatusOK), cmdRetryTimeout)).Should(BeTrue()) 43 // verify that the response contains "Powered by" as all the example apps do 44 curlCmd = model.Cmd{CommandLineString: fmt.Sprintf(`curl -sL "%s"`, app.URL)} 45 Eventually(cmd.Retry(curlCmd, banner, cmdRetryTimeout)).Should(BeTrue()) 46 } 47 48 // PushWithInterrupt executes a `git push deis master` from the current 49 // directory using the provided key, but then halts the progress via SIGINT. 50 func PushWithInterrupt(user model.User, keyPath string) { 51 sess := StartPush(user, keyPath) 52 Eventually(sess.Err).Should(Say("Starting build... but first, coffee!")) 53 54 sess = sess.Interrupt() 55 56 newSess := StartPush(user, keyPath) 57 Eventually(newSess.Err).ShouldNot(Say("exec request failed on channel 0")) 58 Eventually(newSess.Err).Should(Say("fatal: remote error: Another git push is ongoing")) 59 Eventually(newSess, settings.DefaultEventuallyTimeout).Should(Exit(128)) 60 } 61 62 // PushUntilResult executes a `git push deis master` from the current 63 // directory using the provided key, until the command result satisfies 64 // expectedCmdResult of type model.CmdResult, failing if 65 // settings.DefaultEventuallyTimeout is reached first. 66 func PushUntilResult(user model.User, keyPath string, expectedCmdResult model.CmdResult) { 67 envVars := append(os.Environ(), fmt.Sprintf("DEIS_PROFILE=%s", user.Username)) 68 pushCmd := model.Cmd{Env: envVars, CommandLineString: fmt.Sprintf( 69 pushCommandLineString, settings.GitSSH, keyPath)} 70 71 Eventually(cmd.RetryUntilResult(pushCmd, expectedCmdResult, 5*time.Second, 72 settings.MaxEventuallyTimeout)).Should(BeTrue()) 73 } 74 75 // StartPush starts a `git push deis master` command and returns the command session. 76 func StartPush(user model.User, keyPath string) *Session { 77 sess, err := cmd.Start(pushCommandLineString, &user, settings.GitSSH, keyPath) 78 Expect(err).NotTo(HaveOccurred()) 79 return sess 80 }