github.com/deiscc/workflow-e2e@v0.0.0-20181208071258-117299af888f/tests/git_push_test.go (about) 1 package tests 2 3 import ( 4 "os" 5 "path/filepath" 6 "time" 7 8 "github.com/deiscc/workflow-e2e/tests/cmd" 9 "github.com/deiscc/workflow-e2e/tests/cmd/apps" 10 "github.com/deiscc/workflow-e2e/tests/cmd/auth" 11 "github.com/deiscc/workflow-e2e/tests/cmd/git" 12 "github.com/deiscc/workflow-e2e/tests/cmd/keys" 13 "github.com/deiscc/workflow-e2e/tests/model" 14 "github.com/deiscc/workflow-e2e/tests/settings" 15 16 . "github.com/onsi/ginkgo" 17 . "github.com/onsi/gomega" 18 . "github.com/onsi/gomega/gbytes" 19 . "github.com/onsi/gomega/gexec" 20 ) 21 22 var _ = Describe("git push deis master", func() { 23 24 Context("with an existing user", func() { 25 26 var user model.User 27 var keyPath string 28 29 BeforeEach(func() { 30 user = auth.RegisterAndLogin() 31 }) 32 33 AfterEach(func() { 34 auth.Cancel(user) 35 }) 36 37 Context("who has added their public key", func() { 38 39 BeforeEach(func() { 40 _, keyPath = keys.Add(user) 41 }) 42 43 Context("and who has a local git repo containing buildpack source code", func() { 44 45 BeforeEach(func() { 46 output, err := cmd.Execute(`git clone https://github.com/deiscc/example-go.git`) 47 Expect(err).NotTo(HaveOccurred(), output) 48 }) 49 50 Context("and has run `deis apps:create` from within that repo", func() { 51 52 var app model.App 53 54 BeforeEach(func() { 55 os.Chdir("example-go") 56 app = apps.Create(user) 57 }) 58 59 AfterEach(func() { 60 apps.Destroy(user, app) 61 }) 62 63 Specify("that user can deploy that app using a git push", func() { 64 git.Push(user, keyPath, app, "Powered by Deis") 65 }) 66 67 Specify("that user can interrupt the deploy of the app and recover", func() { 68 git.PushWithInterrupt(user, keyPath) 69 70 git.PushUntilResult(user, keyPath, 71 model.CmdResult{ 72 Out: nil, 73 Err: []byte("Everything up-to-date"), 74 ExitCode: 0, 75 }) 76 }) 77 78 Specify("that user can deploy that app only once concurrently", func() { 79 sess := git.StartPush(user, keyPath) 80 // sleep for five seconds, then push the same app 81 time.Sleep(5000 * time.Millisecond) 82 sess2 := git.StartPush(user, keyPath) 83 Eventually(sess2.Err).Should(Say("fatal: remote error: Another git push is ongoing")) 84 Eventually(sess2).Should(Exit(128)) 85 git.PushUntilResult(user, keyPath, 86 model.CmdResult{ 87 Out: nil, 88 Err: []byte("Everything up-to-date"), 89 ExitCode: 0, 90 }) 91 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 92 git.Curl(app, "Powered by Deis") 93 }) 94 95 Context("with a bad buildpack", func() { 96 97 BeforeEach(func() { 98 badBuildpackURL := "https://github.com/deiscc/heroku-buildpack-epic-fail.git" 99 sess, err := cmd.Start("deis config:set BUILDPACK_URL=%s", &user, badBuildpackURL) 100 Expect(err).NotTo(HaveOccurred()) 101 Eventually(sess).Should(Say("BUILDPACK_URL")) 102 Eventually(sess).Should(Exit(0)) 103 }) 104 105 AfterEach(func() { 106 sess, err := cmd.Start("deis config:unset BUILDPACK_URL", &user) 107 Expect(err).NotTo(HaveOccurred()) 108 Eventually(sess).ShouldNot(Say("BUILDPACK_URL")) 109 Eventually(sess).Should(Exit(0)) 110 }) 111 112 Specify("that user can't deploy the app", func() { 113 sess := git.StartPush(user, keyPath) 114 Eventually(sess.Err, settings.MaxEventuallyTimeout).Should(Say("-----> Fetching custom buildpack")) 115 Eventually(sess.Err).Should(Say("exited with code 1, stopping build")) 116 Eventually(sess).Should(Exit(1)) 117 }) 118 119 }) 120 121 Context("and who has another local git repo containing buildpack source code", func() { 122 123 BeforeEach(func() { 124 os.Chdir("..") 125 output, err := cmd.Execute(`git clone https://github.com/deiscc/example-nodejs-express.git`) 126 Expect(err).NotTo(HaveOccurred(), output) 127 }) 128 129 Context("and has run `deis apps:create` from within that repo", func() { 130 131 var app2 model.App 132 133 BeforeEach(func() { 134 os.Chdir("example-nodejs-express") 135 app2 = apps.Create(user) 136 }) 137 138 AfterEach(func() { 139 apps.Destroy(user, app2) 140 }) 141 142 Specify("that user can deploy both apps concurrently", func() { 143 os.Chdir(filepath.Join("..", "example-go")) 144 sess := git.StartPush(user, keyPath) 145 os.Chdir(filepath.Join("..", "example-nodejs-express")) 146 sess2 := git.StartPush(user, keyPath) 147 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 148 Eventually(sess2, settings.MaxEventuallyTimeout).Should(Exit(0)) 149 git.Curl(app, "Powered by Deis") 150 git.Curl(app2, "Powered by Deis") 151 }) 152 153 }) 154 155 }) 156 157 Specify("and can execute deis run successfully", func() { 158 git.Push(user, keyPath, app, "Powered by Deis") 159 sess, err := cmd.Start("deis run env -a %s", &user, app.Name) 160 Expect(err).NotTo(HaveOccurred()) 161 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 162 }) 163 164 }) 165 166 }) 167 168 Context("and who has a local git repo containing dockerfile source code", func() { 169 170 BeforeEach(func() { 171 output, err := cmd.Execute(`git clone https://github.com/deiscc/example-dockerfile-http.git`) 172 Expect(err).NotTo(HaveOccurred(), output) 173 }) 174 175 Context("and has run `deis apps:create` from within that repo", func() { 176 177 var app model.App 178 179 BeforeEach(func() { 180 os.Chdir("example-dockerfile-http") 181 app = apps.Create(user) 182 }) 183 184 AfterEach(func() { 185 apps.Destroy(user, app) 186 }) 187 188 Specify("that user can deploy that app using a git push", func() { 189 git.Push(user, keyPath, app, "Powered by Deis") 190 }) 191 192 Specify("that user can deploy that app using a git push after setting config values", func() { 193 sess, err := cmd.Start("deis config:set -a %s PORT=80 POWERED_BY=midi-chlorians", &user, app.Name) 194 Expect(err).NotTo(HaveOccurred()) 195 Eventually(sess).Should(Say("Creating config")) 196 Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name)) 197 output := string(sess.Out.Contents()) 198 Expect(output).To(MatchRegexp(`PORT\s+80`)) 199 Expect(output).To(MatchRegexp(`POWERED_BY\s+midi-chlorians`)) 200 Expect(err).NotTo(HaveOccurred()) 201 Eventually(sess).Should(Exit(0)) 202 203 git.Push(user, keyPath, app, "Powered by midi-chlorians") 204 }) 205 206 Specify("that user can deploy that app only once concurrently", func() { 207 sess := git.StartPush(user, keyPath) 208 // sleep for five seconds, then push the same app 209 time.Sleep(5000 * time.Millisecond) 210 sess2 := git.StartPush(user, keyPath) 211 Eventually(sess2.Err).Should(Say("fatal: remote error: Another git push is ongoing")) 212 Eventually(sess2).Should(Exit(128)) 213 git.PushUntilResult(user, keyPath, 214 model.CmdResult{ 215 Out: nil, 216 Err: []byte("Everything up-to-date"), 217 ExitCode: 0, 218 }) 219 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 220 git.Curl(app, "Powered by Deis") 221 }) 222 223 Context("with a bad Dockerfile", func() { 224 225 BeforeEach(func() { 226 badCommit := `echo "BOGUS command" >> Dockerfile && EMAIL="ci@deis.cc" git commit Dockerfile -m "Added a bogus command"` 227 output, err := cmd.Execute(badCommit) 228 Expect(err).NotTo(HaveOccurred(), output) 229 }) 230 231 AfterEach(func() { 232 undoCommit := `git reset --hard HEAD~` 233 output, err := cmd.Execute(undoCommit) 234 Expect(err).NotTo(HaveOccurred(), output) 235 }) 236 237 Specify("that user can't deploy that app using a git push", func() { 238 sess := git.StartPush(user, keyPath) 239 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(1)) 240 Eventually(sess.Err).Should(Say("Unknown instruction: BOGUS")) 241 Eventually(sess.Err).Should(Say("error: failed to push some refs")) 242 }) 243 244 }) 245 246 Context("and who has another local git repo containing dockerfile source code", func() { 247 248 BeforeEach(func() { 249 os.Chdir("..") 250 output, err := cmd.Execute(`git clone https://github.com/deiscc/example-dockerfile-procfile-http.git`) 251 Expect(err).NotTo(HaveOccurred(), output) 252 }) 253 254 Context("and has run `deis apps:create` from within that repo", func() { 255 256 var app2 model.App 257 258 BeforeEach(func() { 259 os.Chdir("example-dockerfile-procfile-http") 260 app2 = apps.Create(user) 261 }) 262 263 AfterEach(func() { 264 apps.Destroy(user, app2) 265 }) 266 267 Specify("that user can deploy both apps concurrently", func() { 268 os.Chdir(filepath.Join("..", "example-dockerfile-http")) 269 sess := git.StartPush(user, keyPath) 270 os.Chdir(filepath.Join("..", "example-dockerfile-procfile-http")) 271 sess2 := git.StartPush(user, keyPath) 272 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 273 Eventually(sess2, settings.MaxEventuallyTimeout).Should(Exit(0)) 274 git.Curl(app, "Powered by Deis") 275 git.Curl(app2, "Powered by Deis") 276 _ = listProcs(user, app2, "web") 277 }) 278 279 }) 280 281 }) 282 283 Specify("and can execute deis run successfully", func() { 284 git.Push(user, keyPath, app, "Powered by Deis") 285 sess, err := cmd.Start("deis run env -a %s", &user, app.Name) 286 Expect(err).NotTo(HaveOccurred()) 287 Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0)) 288 }) 289 290 }) 291 292 }) 293 294 }) 295 296 }) 297 298 })