github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/integration/push/droplet_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  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  	. "github.com/onsi/gomega/ghttp"
    15  )
    16  
    17  var _ = Describe("when a droplet is provided", func() {
    18  	var (
    19  		appName     string
    20  		dropletPath string
    21  	)
    22  
    23  	BeforeEach(func() {
    24  		appName = helpers.NewAppName()
    25  
    26  		helpers.WithHelloWorldApp(func(appDir string) {
    27  			tmpfile, err := ioutil.TempFile("", "dropletFile")
    28  			Expect(err).ToNot(HaveOccurred())
    29  			dropletPath = tmpfile.Name()
    30  			Expect(tmpfile.Close()).ToNot(HaveOccurred())
    31  
    32  			tempApp := helpers.NewAppName()
    33  			session := helpers.CF(PushCommandName, tempApp, "-b", "staticfile_buildpack")
    34  			Eventually(session).Should(Exit(0))
    35  
    36  			appGUID := helpers.AppGUID(tempApp)
    37  			Eventually(helpers.CF("curl", fmt.Sprintf("/v2/apps/%s/droplet/download", appGUID), "--output", dropletPath)).Should(Exit(0))
    38  			_, err = os.Stat(dropletPath)
    39  			Expect(err).ToNot(HaveOccurred())
    40  		})
    41  	})
    42  
    43  	AfterEach(func() {
    44  		Expect(os.RemoveAll(dropletPath)).ToNot(HaveOccurred())
    45  	})
    46  
    47  	Context("when the v2 api version is lower than the minimum version", func() {
    48  		var server *Server
    49  
    50  		BeforeEach(func() {
    51  			server = helpers.StartAndTargetServerWithAPIVersions("2.50.0", helpers.DefaultV3Version)
    52  		})
    53  
    54  		AfterEach(func() {
    55  			server.Close()
    56  		})
    57  
    58  		It("fails with error message that the minimum version is not met", func() {
    59  			session := helpers.CF(PushCommandName, appName, "--droplet", dropletPath)
    60  			Eventually(session).Should(Say("FAILED"))
    61  			Eventually(session.Err).Should(Say("Option '--droplet' requires CF API version 2\\.63\\.0 or higher\\. Your target is 2\\.50\\.0"))
    62  			Eventually(session).Should(Exit(1))
    63  		})
    64  	})
    65  
    66  	Context("when the app does not exist", func() {
    67  
    68  		It("creates the app", func() {
    69  			session := helpers.CF(PushCommandName, appName, "--droplet", dropletPath)
    70  			Eventually(session).Should(Say("Getting app info\\.\\.\\."))
    71  			Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
    72  			Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
    73  			Eventually(session).Should(Say("Uploading droplet\\.\\.\\."))
    74  			Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
    75  			Eventually(session).Should(Say("requested state:\\s+started"))
    76  			Eventually(session).Should(Exit(0))
    77  
    78  			session = helpers.CF("app", appName)
    79  			Eventually(session).Should(Say("name:\\s+%s", appName))
    80  			Eventually(session).Should(Exit(0))
    81  		})
    82  	})
    83  
    84  	Context("when the app exists", func() {
    85  		BeforeEach(func() {
    86  			helpers.WithHelloWorldApp(func(appDir string) {
    87  				Eventually(helpers.CF(PushCommandName, appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
    88  			})
    89  		})
    90  
    91  		It("updates the app", func() {
    92  			session := helpers.CF(PushCommandName, appName, "--droplet", dropletPath)
    93  			Eventually(session).Should(Say("Updating app with these attributes\\.\\.\\."))
    94  			Eventually(session).Should(Say("Uploading droplet\\.\\.\\."))
    95  			Eventually(session).Should(Exit(0))
    96  		})
    97  	})
    98  })