github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v7/push/droplet_flag_test.go (about)

     1  package push
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	"fmt"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  	"io/ioutil"
    11  	"os"
    12  )
    13  
    14  var _ = Describe("--droplet flag", func() {
    15  	When("the --droplet flag is provided", func() {
    16  		var (
    17  			appName     string
    18  			dropletPath string
    19  			originalApp string
    20  		)
    21  
    22  		BeforeEach(func() {
    23  			appName = helpers.NewAppName()
    24  
    25  			helpers.WithHelloWorldApp(func(appDir string) {
    26  				tmpfile, err := ioutil.TempFile("", "dropletFile*.tgz")
    27  				Expect(err).ToNot(HaveOccurred())
    28  				dropletPath = tmpfile.Name()
    29  				Expect(tmpfile.Close()).ToNot(HaveOccurred())
    30  
    31  				originalApp = helpers.NewAppName()
    32  				session := helpers.CF(PushCommandName, originalApp, "-b", "staticfile_buildpack")
    33  				Eventually(session).Should(Exit(0))
    34  
    35  				appGUID := helpers.AppGUID(originalApp)
    36  				Eventually(helpers.CF("curl", fmt.Sprintf("/v2/apps/%s/droplet/download", appGUID), "--output", dropletPath)).Should(Exit(0))
    37  				_, err = os.Stat(dropletPath)
    38  				Expect(err).ToNot(HaveOccurred())
    39  			})
    40  		})
    41  
    42  		AfterEach(func() {
    43  			Expect(os.RemoveAll(dropletPath)).ToNot(HaveOccurred())
    44  		})
    45  
    46  		When("the app does not exist", func() {
    47  			It("creates the app with the given droplet", func() {
    48  				session := helpers.CF(PushCommandName, appName, "--droplet", dropletPath)
    49  				Eventually(session).Should(Say(`Creating app %s\.\.\.`, appName))
    50  				Eventually(session).Should(Say(`Getting app info\.\.\.`))
    51  				Eventually(session).Should(Say(`Uploading droplet bits\.\.\.`))
    52  				Eventually(session).Should(Say(`Waiting for app %s to start\.\.\.`, appName))
    53  				Eventually(session).Should(Say(`requested state:\s+started`))
    54  				Eventually(session).Should(Exit(0))
    55  
    56  				session = helpers.CF("app", appName)
    57  				Eventually(session).Should(Say(`name:\s+%s`, appName))
    58  				Eventually(session).Should(Exit(0))
    59  			})
    60  		})
    61  
    62  		When("the app already exists", func() {
    63  			It("updates the app with the given droplet", func() {
    64  				session := helpers.CF(PushCommandName, originalApp, "--droplet", dropletPath)
    65  				Eventually(session).Should(Say(`Updating app %s\.\.\.`, originalApp))
    66  				Eventually(session).Should(Say(`Getting app info\.\.\.`))
    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(`Updating 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  })