github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/global/update_buildpack_command_test.go (about) 1 package global 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 9 "code.cloudfoundry.org/cli/integration/helpers" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("update-buildpack command", func() { 17 var ( 18 buildpackName string 19 stacks []string 20 ) 21 22 BeforeEach(func() { 23 helpers.LoginCF() 24 buildpackName = helpers.NewBuildpack() 25 }) 26 27 Context("when the buildpack is not provided", func() { 28 It("returns a buildpack argument not provided error", func() { 29 session := helpers.CF("update-buildpack", "-p", ".") 30 Eventually(session).Should(Exit(1)) 31 32 Expect(session.Err.Contents()).To(BeEquivalentTo("Incorrect Usage: the required argument `BUILDPACK` was not provided\n\n")) 33 }) 34 }) 35 36 Context("when the buildpack's path does not exist", func() { 37 It("returns a buildpack does not exist error", func() { 38 session := helpers.CF("update-buildpack", "integration-buildpack-update-bogus", "-p", "this-is-a-bogus-path") 39 40 Eventually(session.Err).Should(Say("Incorrect Usage: The specified path 'this-is-a-bogus-path' does not exist.")) 41 Eventually(session).Should(Exit(1)) 42 }) 43 }) 44 45 Context("when the wrong data type is provided as the position argument", func() { 46 It("outputs an error message to the user, provides help text, and exits 1", func() { 47 session := helpers.CF("update-buildpack", "integration-buildpack-not-an-integer", "-i", "not-an-integer") 48 Eventually(session.Err).Should(Say("Incorrect Usage: invalid argument for flag `-i' \\(expected int\\)")) 49 Eventually(session).Should(Say("cf update-buildpack BUILDPACK")) // help 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 54 PContext("when not using stack association", func() { 55 BeforeEach(func() { 56 helpers.BuildpackWithStack(func(buildpackPath string) { 57 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 58 Eventually(session).Should(Exit(0)) 59 }, "") 60 }) 61 62 It("updates buildpack properly", func() { 63 session := helpers.CF("update-buildpack", buildpackName, "-i", "999") 64 Eventually(session).Should(Exit(0)) 65 Eventually(session).Should(Say("Updating buildpack %s\\.\\.\\.", buildpackName)) 66 }) 67 }) 68 69 Context("when multiple buildpacks have the same name", func() { 70 71 BeforeEach(func() { 72 helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV3) 73 helpers.SkipIfOneStack() 74 75 stacks = helpers.FetchStacks() 76 helpers.BuildpackWithStack(func(buildpackPath string) { 77 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 78 Eventually(session).Should(Exit(0)) 79 }, stacks[0]) 80 81 helpers.BuildpackWithStack(func(buildpackPath string) { 82 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 83 Eventually(session).Should(Exit(0)) 84 }, stacks[1]) 85 }) 86 87 It("handles ambiguity properly", func() { 88 By("failing when no stack is specified") 89 session := helpers.CF("update-buildpack", buildpackName, "-i", "999") 90 Eventually(session).Should(Exit(1)) 91 Eventually(session.Out).Should(Say("FAILED")) 92 93 By("failing when updating buildpack with non-existent stack") 94 session = helpers.CF("update-buildpack", buildpackName, "-i", "999", "-s", "bogus-stack") 95 Eventually(session).Should(Exit(1)) 96 Eventually(session.Out).Should(Say("FAILED")) 97 98 By("updating when a stack associated with that buildpack name is specified") 99 session = helpers.CF("update-buildpack", buildpackName, "-s", stacks[0], "-i", "999") 100 Eventually(session).Should(Exit(0)) 101 Eventually(session.Out).Should(Say("OK")) 102 Expect(session.Err).NotTo(Say("Incorrect Usage:")) 103 }) 104 }) 105 106 Context("when a URL is provided as the buildpack", func() { 107 var dir string 108 109 BeforeEach(func() { 110 111 var err error 112 dir, err = ioutil.TempDir("", "update-buildpack-test") 113 Expect(err).ToNot(HaveOccurred()) 114 115 filename := "some-file" 116 tempfile := filepath.Join(dir, filename) 117 err = ioutil.WriteFile(tempfile, []byte{}, 0400) 118 Expect(err).ToNot(HaveOccurred()) 119 120 buildpackName = helpers.NewBuildpack() 121 session := helpers.CF("create-buildpack", buildpackName, dir, "1") 122 Eventually(session).Should(Exit(0)) 123 }) 124 125 AfterEach(func() { 126 Expect(os.RemoveAll(dir)).To(Succeed()) 127 }) 128 129 It("outputs an error message to the user, provides help text, and exits 1", func() { 130 session := helpers.CF("update-buildpack", buildpackName, "-p", "https://example.com/bogus.tgz") 131 Eventually(session).Should(Say("Failed to create a local temporary zip file for the buildpack")) 132 Eventually(session).Should(Say("FAILED")) 133 Eventually(session).Should(Say("Couldn't write zip file: zip: not a valid zip file")) 134 Eventually(session).Should(Exit(1)) 135 }) 136 }) 137 })