github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/integration/global/create_buildpack_command_test.go (about) 1 package global 2 3 import ( 4 "io/ioutil" 5 "os" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 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("create-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 creating a new buildpack", func() { 28 Context("without stack association", func() { 29 It("creates the new buildpack", func() { 30 helpers.BuildpackWithStack(func(buildpackPath string) { 31 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 32 Eventually(session).Should(Exit(0)) 33 }, "") 34 35 session := helpers.CF("buildpacks") 36 Eventually(session).Should(Exit(0)) 37 Expect(session.Out).To(Say(buildpackName)) 38 }) 39 }) 40 41 Context("with stack association", func() { 42 BeforeEach(func() { 43 helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV3) 44 stacks = helpers.FetchStacks() 45 }) 46 47 It("creates the new buildpack and assigns its stack", func() { 48 helpers.BuildpackWithStack(func(buildpackPath string) { 49 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 50 Eventually(session).Should(Exit(0)) 51 }, stacks[0]) 52 53 session := helpers.CF("buildpacks") 54 Eventually(session).Should(Exit(0)) 55 Expect(session.Out).To(Say(buildpackName+".*%s.*1", stacks[0])) 56 }) 57 }) 58 }) 59 60 Context("when creating a buildpack with no stack that already exists", func() { 61 BeforeEach(func() { 62 stacks = helpers.FetchStacks() 63 64 helpers.BuildpackWithStack(func(buildpackPath string) { 65 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 66 Eventually(session).Should(Exit(0)) 67 }, "") 68 }) 69 70 It("issues a warning and exits 0", func() { 71 helpers.BuildpackWithStack(func(buildpackPath string) { 72 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 73 Eventually(session).Should(Exit(0)) 74 Eventually(session.Out).Should(Say("Buildpack %s already exists", buildpackName)) 75 }, "") 76 }) 77 }) 78 79 Context("when creating a buildpack/stack that already exists", func() { 80 BeforeEach(func() { 81 helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV3) 82 83 helpers.BuildpackWithStack(func(buildpackPath string) { 84 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 85 Eventually(session).Should(Exit(0)) 86 }, stacks[0]) 87 }) 88 89 It("issues a warning and exits 0", func() { 90 helpers.BuildpackWithStack(func(buildpackPath string) { 91 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 92 Eventually(session).Should(Exit(0)) 93 Eventually(session.Out).Should(Say("The buildpack name " + buildpackName + " is already in use for the stack " + stacks[0])) 94 }, stacks[0]) 95 }) 96 }) 97 98 Context("when the wrong data type is provided as the position argument", func() { 99 var ( 100 filename string 101 ) 102 103 BeforeEach(func() { 104 // The args take a filepath. Creating a real file will avoid the file 105 // does not exist error, and trigger the correct error case we are 106 // testing. 107 f, err := ioutil.TempFile("", "create-buildpack-invalid") 108 Expect(err).NotTo(HaveOccurred()) 109 f.Close() 110 111 filename = f.Name() 112 }) 113 114 AfterEach(func() { 115 err := os.Remove(filename) 116 Expect(err).NotTo(HaveOccurred()) 117 }) 118 119 It("outputs an error message to the user, provides help text, and exits 1", func() { 120 session := helpers.CF("create-buildpack", buildpackName, filename, "not-an-integer") 121 Eventually(session.Err).Should(Say("Incorrect usage: Value for POSITION must be integer")) 122 Eventually(session).Should(Say("cf create-buildpack BUILDPACK PATH POSITION")) // help 123 Eventually(session).Should(Exit(1)) 124 }) 125 }) 126 127 Context("when a nonexistent file is provided", func() { 128 It("outputs an error message to the user and exits 1", func() { 129 session := helpers.CF("create-buildpack", buildpackName, "some-bogus-file", "1") 130 Eventually(session.Err).Should(Say("Incorrect Usage: The specified path 'some-bogus-file' does not exist.")) 131 Eventually(session).Should(Exit(1)) 132 }) 133 }) 134 135 Context("when a URL is provided as the buildpack", func() { 136 It("outputs an error message to the user, provides help text, and exits 1", func() { 137 session := helpers.CF("create-buildpack", buildpackName, "https://example.com/bogus.tgz", "1") 138 Eventually(session).Should(Say("Failed to create a local temporary zip file for the buildpack")) 139 Eventually(session).Should(Say("FAILED")) 140 Eventually(session).Should(Say("Couldn't write zip file: zip: not a valid zip file")) 141 Eventually(session).Should(Exit(1)) 142 }) 143 }) 144 })