github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/update_buildpack_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     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("update-buildpack command", func() {
    16  	Context("when the buildpack is not provided", func() {
    17  		It("returns a buildpack argument not provided error", func() {
    18  			session := CF("update-buildpack", "-p", ".")
    19  			Eventually(session).Should(Exit(1))
    20  
    21  			Expect(session.Err.Contents()).To(BeEquivalentTo("Incorrect Usage: the required argument `BUILDPACK` was not provided\n\n"))
    22  		})
    23  	})
    24  
    25  	Context("when the buildpack's path does not exist", func() {
    26  		It("returns a buildpack does not exist error", func() {
    27  			session := CF("update-buildpack", "some-buildpack", "-p", "this-is-a-bogus-path")
    28  
    29  			Eventually(session.Err).Should(Say("Incorrect Usage: The specified path 'this-is-a-bogus-path' does not exist."))
    30  			Eventually(session).Should(Exit(1))
    31  		})
    32  	})
    33  
    34  	Context("when the wrong data type is provided as the position argument", func() {
    35  		It("outputs an error message to the user, provides help text, and exits 1", func() {
    36  			session := CF("update-buildpack", "some-buildpack", "-i", "not-an-integer")
    37  			Eventually(session.Err).Should(Say("Incorrect Usage: invalid argument for flag `-i' \\(expected int\\)"))
    38  			Eventually(session.Out).Should(Say("cf update-buildpack BUILDPACK")) // help
    39  			Eventually(session).Should(Exit(1))
    40  		})
    41  	})
    42  
    43  	Context("when a URL is provided as the buildpack", func() {
    44  		var dir string
    45  
    46  		BeforeEach(func() {
    47  			LoginCF()
    48  
    49  			dir, err := ioutil.TempDir("", "bp")
    50  			Expect(err).ToNot(HaveOccurred())
    51  
    52  			filename := "some-file"
    53  			tempfile := filepath.Join(dir, filename)
    54  			err = ioutil.WriteFile(tempfile, []byte{}, 0400)
    55  			Expect(err).ToNot(HaveOccurred())
    56  
    57  			session := CF("create-buildpack", "some-buildpack", dir, "1")
    58  			Eventually(session).Should(Exit(0))
    59  		})
    60  
    61  		AfterEach(func() {
    62  			err := os.RemoveAll(dir)
    63  			Expect(err).NotTo(HaveOccurred())
    64  		})
    65  
    66  		It("outputs an error message to the user, provides help text, and exits 1", func() {
    67  			session := CF("update-buildpack", "some-buildpack", "-p", "https://example.com/bogus.tgz")
    68  			Eventually(session.Out).Should(Say("Failed to create a local temporary zip file for the buildpack"))
    69  			Eventually(session.Out).Should(Say("FAILED"))
    70  			Eventually(session.Out).Should(Say("Couldn't write zip file: zip: not a valid zip file"))
    71  			Eventually(session).Should(Exit(1))
    72  		})
    73  	})
    74  })