github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/push/droplet_flag_test.go (about) 1 package push 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("--droplet flag", func() { 16 When("the --droplet flag is provided", func() { 17 var ( 18 appName string 19 dropletPath string 20 originalApp string 21 ) 22 23 BeforeEach(func() { 24 appName = helpers.NewAppName() 25 26 helpers.WithHelloWorldApp(func(appDir string) { 27 tmpfile, err := ioutil.TempFile("", "dropletFile*.tgz") 28 Expect(err).ToNot(HaveOccurred()) 29 dropletPath = tmpfile.Name() 30 Expect(tmpfile.Close()).ToNot(HaveOccurred()) 31 32 originalApp = helpers.NewAppName() 33 helpers.WithHelloWorldApp(func(appDir string) { 34 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, PushCommandName, originalApp, "-b", "staticfile_buildpack", "-v")).Should(Exit(0)) 35 }) 36 37 appGUID := helpers.AppGUID(originalApp) 38 Eventually(helpers.CF("curl", fmt.Sprintf("/v2/apps/%s/droplet/download", appGUID), "--output", dropletPath)).Should(Exit(0)) 39 _, err = os.Stat(dropletPath) 40 Expect(err).ToNot(HaveOccurred()) 41 }) 42 }) 43 44 AfterEach(func() { 45 Expect(os.RemoveAll(dropletPath)).ToNot(HaveOccurred()) 46 }) 47 48 When("the app does not exist", func() { 49 It("creates the app with the given droplet", func() { 50 session := helpers.CF(PushCommandName, appName, "--droplet", dropletPath) 51 Eventually(session).Should(Say(`Pushing app %s`, appName)) 52 Eventually(session).Should(Say(`Uploading droplet bits\.\.\.`)) 53 Eventually(session).Should(Say(`Waiting for app %s to start\.\.\.`, appName)) 54 Eventually(session).Should(Say(`requested state:\s+started`)) 55 Eventually(session).Should(Exit(0)) 56 57 session = helpers.CF("app", appName) 58 Eventually(session).Should(Say(`name:\s+%s`, appName)) 59 Eventually(session).Should(Exit(0)) 60 }) 61 }) 62 63 When("the app already exists", func() { 64 It("updates the app with the given droplet", func() { 65 session := helpers.CF(PushCommandName, originalApp, "--droplet", dropletPath) 66 Eventually(session).Should(Say(`Pushing app %s`, originalApp)) 67 Eventually(session).Should(Say(`Uploading droplet bits\.\.\.`)) 68 Eventually(session).Should(Say(`Waiting for app %s to start\.\.\.`, originalApp)) 69 Eventually(session).Should(Say(`requested state:\s+started`)) 70 Eventually(session).Should(Exit(0)) 71 72 session = helpers.CF("app", originalApp) 73 Eventually(session).Should(Say(`name:\s+%s`, originalApp)) 74 Eventually(session).Should(Exit(0)) 75 }) 76 }) 77 78 When("the droplet bits path is not a gzipped tarball", func() { 79 It("fails with a helpful error message", func() { 80 nonTgzFile, err := ioutil.TempFile("", "dropletFile*.txt") 81 Expect(err).ToNot(HaveOccurred()) 82 session := helpers.CF(PushCommandName, appName, "--droplet", nonTgzFile.Name()) 83 Eventually(session).Should(Say(`FAILED`)) 84 Eventually(session.Err).Should(Say(`Uploaded droplet file is invalid: .+ not a tgz`)) 85 Eventually(session).Should(Exit(1)) 86 }) 87 }) 88 89 When("along with the --no-start flag", func() { 90 It("updates the app with the given droplet", func() { 91 originalAppGUID := helpers.AppGUID(originalApp) 92 93 var routeResponse struct { 94 GUID string `json:"guid"` 95 } 96 97 currentDropletEndpoint := fmt.Sprintf("v3/apps/%s/droplets/current", originalAppGUID) 98 99 helpers.Curl(&routeResponse, currentDropletEndpoint) 100 preUploadDropletGUID := routeResponse.GUID 101 102 session := helpers.CF(PushCommandName, originalApp, "--droplet", dropletPath, "--no-start") 103 Eventually(session).Should(Say(`Pushing app %s`, originalApp)) 104 Eventually(session).Should(Say(`Uploading droplet bits\.\.\.`)) 105 Eventually(session).Should(Say(`requested state:\s+stopped`)) 106 Eventually(session).Should(Exit(0)) 107 108 helpers.Curl(&routeResponse, currentDropletEndpoint) 109 postUploadDropletGUID := routeResponse.GUID 110 111 Expect(preUploadDropletGUID).To(Not(Equal(postUploadDropletGUID))) 112 }) 113 }) 114 }) 115 })