github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/global/delete_buildpack_command_test.go (about) 1 package global 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("delete-buildpack command", func() { 12 var ( 13 buildpackName string 14 stacks []string 15 ) 16 17 BeforeEach(func() { 18 helpers.LoginCF() 19 buildpackName = helpers.NewBuildpackName() 20 }) 21 22 When("the --help flag is passed", func() { 23 It("Displays the appropriate help text", func() { 24 session := helpers.CF("delete-buildpack", "--help") 25 Eventually(session).Should(Say("NAME:")) 26 Eventually(session).Should(Say("delete-buildpack - Delete a buildpack")) 27 Eventually(session).Should(Say("\n")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say(`cf delete-buildpack BUILDPACK \[-f] \[-s STACK]`)) 30 Eventually(session).Should(Say("\n")) 31 Eventually(session).Should(Say("OPTIONS:")) 32 Eventually(session).Should(Say(`--force, -f\s+Force deletion without confirmation`)) 33 Eventually(session).Should(Say(`--stack, -s\s+Specify stack to disambiguate buildpacks with the same name. Required when buildpack name is ambiguous`)) 34 Eventually(session).Should(Say("\n")) 35 Eventually(session).Should(Say("SEE ALSO:")) 36 Eventually(session).Should(Say("buildpacks")) 37 Eventually(session).Should(Exit(0)) 38 }) 39 }) 40 41 When("the buildpack name is not provided", func() { 42 It("displays an error and help", func() { 43 session := helpers.CF("delete-buildpack") 44 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `BUILDPACK` was not provided")) 45 Eventually(session).Should(Say("USAGE")) 46 Eventually(session).Should(Exit(1)) 47 }) 48 }) 49 50 When("the buildpack doesn't exist", func() { 51 When("the user does not specify a stack", func() { 52 It("displays a warning and exits 0", func() { 53 session := helpers.CF("delete-buildpack", "-f", "nonexistent-buildpack") 54 Eventually(session).Should(Say(`Deleting buildpack nonexistent-buildpack\.\.\.`)) 55 Eventually(session).Should(Say("OK")) 56 Eventually(session.Err).Should(Say(`Buildpack 'nonexistent-buildpack' does not exist\.`)) 57 Eventually(session).Should(Exit(0)) 58 }) 59 }) 60 61 When("the user specifies a stack", func() { 62 BeforeEach(func() { 63 stacks = helpers.FetchStacks() 64 }) 65 66 It("displays a warning and exits 0", func() { 67 session := helpers.CF("delete-buildpack", "-f", "nonexistent-buildpack", "-s", stacks[0]) 68 Eventually(session).Should(Say(`Deleting buildpack nonexistent-buildpack with stack %s\.\.\.`, stacks[0])) 69 Eventually(session).Should(Say("OK")) 70 Eventually(session.Err).Should(Say(`Buildpack 'nonexistent-buildpack' with stack '%s' not found\.`, stacks[0])) 71 Eventually(session).Should(Exit(0)) 72 }) 73 }) 74 }) 75 76 Context("there is exactly one buildpack with the specified name", func() { 77 When("the stack is specified", func() { 78 BeforeEach(func() { 79 stacks = helpers.FetchStacks() 80 helpers.BuildpackWithStack(func(buildpackPath string) { 81 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 82 Eventually(session).Should(Exit(0)) 83 }, stacks[0]) 84 }) 85 86 It("deletes the specified buildpack", func() { 87 session := helpers.CF("delete-buildpack", buildpackName, "-s", stacks[0], "-f") 88 Eventually(session.Out).Should(Say("OK")) 89 Eventually(session).Should(Exit(0)) 90 }) 91 }) 92 93 When("the stack is not specified", func() { 94 It("deletes the specified buildpack", func() { 95 session := helpers.CF("delete-buildpack", buildpackName, "-f") 96 Eventually(session.Out).Should(Say("OK")) 97 Eventually(session).Should(Exit(0)) 98 }) 99 }) 100 }) 101 102 Context("there are two buildpacks with same name", func() { 103 BeforeEach(func() { 104 stacks = helpers.EnsureMinimumNumberOfStacks(2) 105 }) 106 107 Context("neither buildpack has a nil stack", func() { 108 BeforeEach(func() { 109 helpers.BuildpackWithStack(func(buildpackPath string) { 110 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 111 Eventually(session).Should(Exit(0)) 112 }, stacks[0]) 113 114 helpers.BuildpackWithStack(func(buildpackPath string) { 115 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 116 Eventually(session).Should(Exit(0)) 117 }, stacks[1]) 118 }) 119 120 It("properly handles ambiguity", func() { 121 By("failing when no stack specified") 122 123 session := helpers.CF("delete-buildpack", buildpackName, "-f") 124 Eventually(session.Err).Should(Say("Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.", buildpackName)) 125 Eventually(session).Should(Exit(1)) 126 127 By("succeeding with warning when the buildpack name matches but the stack does not") 128 129 session = helpers.CF("delete-buildpack", buildpackName, "-s", "not-a-real-stack", "-f") 130 Eventually(session).Should(Say(`Deleting buildpack %s with stack not-a-real-stack\.\.\.`, buildpackName)) 131 Eventually(session).Should(Say("OK")) 132 Eventually(session.Err).Should(Say(`Buildpack '%s' with stack 'not-a-real-stack' not found\.`, buildpackName)) 133 Eventually(session).Should(Exit(0)) 134 135 By("deleting the buildpack when the associated stack is specified") 136 137 session = helpers.CF("delete-buildpack", buildpackName, "-s", stacks[0], "-f") 138 Eventually(session).Should(Say(`Deleting buildpack %s with stack %s\.\.\.`, buildpackName, stacks[0])) 139 Eventually(session).Should(Say("OK")) 140 Eventually(session).Should(Exit(0)) 141 142 session = helpers.CF("delete-buildpack", buildpackName, "-s", stacks[1], "-f") 143 Eventually(session).Should(Say(`Deleting buildpack %s with stack %s\.\.\.`, buildpackName, stacks[1])) 144 Eventually(session).Should(Say("OK")) 145 Eventually(session).Should(Exit(0)) 146 }) 147 }) 148 149 Context("one buildpack has a nil stack", func() { 150 BeforeEach(func() { 151 helpers.BuildpackWithStack(func(buildpackPath string) { 152 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 153 Eventually(session).Should(Exit(0)) 154 }, stacks[0]) 155 156 helpers.BuildpackWithoutStack(func(buildpackPath string) { 157 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 158 Eventually(session).Should(Exit(0)) 159 }) 160 }) 161 162 It("properly handles ambiguity", func() { 163 By("deleting the nil stack buildpack when no stack specified") 164 session := helpers.CF("delete-buildpack", buildpackName, "-f") 165 Eventually(session.Out).Should(Say("OK")) 166 Eventually(session).Should(Exit(0)) 167 168 By("deleting the remaining buildpack when no stack is specified") 169 session = helpers.CF("delete-buildpack", buildpackName, "-f") 170 Eventually(session.Out).Should(Say("OK")) 171 Eventually(session).Should(Exit(0)) 172 }) 173 }) 174 }) 175 176 When("the -f flag not is provided", func() { 177 var buffer *Buffer 178 179 BeforeEach(func() { 180 buffer = NewBuffer() 181 182 helpers.BuildpackWithoutStack(func(buildpackPath string) { 183 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1") 184 Eventually(session).Should(Exit(0)) 185 }) 186 }) 187 188 When("the user enters 'y'", func() { 189 BeforeEach(func() { 190 _, err := buffer.Write([]byte("y\n")) 191 Expect(err).ToNot(HaveOccurred()) 192 }) 193 194 It("deletes the buildpack", func() { 195 session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName) 196 Eventually(session).Should(Say(`Deleting buildpack %s\.\.\.`, buildpackName)) 197 Eventually(session).Should(Say("OK")) 198 Eventually(session).Should(Exit(0)) 199 }) 200 }) 201 202 When("the user enters 'n'", func() { 203 BeforeEach(func() { 204 _, err := buffer.Write([]byte("n\n")) 205 Expect(err).ToNot(HaveOccurred()) 206 }) 207 208 It("does not delete the buildpack", func() { 209 session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName) 210 Eventually(session).Should(Say("Delete cancelled")) 211 Eventually(session).Should(Exit(0)) 212 213 session = helpers.CF("buildpacks") 214 Eventually(session).Should(Say(buildpackName)) 215 Eventually(session).Should(Exit(0)) 216 }) 217 }) 218 219 When("the user enters the default input (hits return)", func() { 220 BeforeEach(func() { 221 _, err := buffer.Write([]byte("\n")) 222 Expect(err).ToNot(HaveOccurred()) 223 }) 224 225 It("does not delete the buildpack", func() { 226 session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName) 227 Eventually(session).Should(Say("Delete cancelled")) 228 Eventually(session).Should(Exit(0)) 229 230 session = helpers.CF("buildpacks") 231 Eventually(session).Should(Say(buildpackName)) 232 Eventually(session).Should(Exit(0)) 233 }) 234 }) 235 }) 236 237 When("the --force flag is provided", func() { 238 It("deletes the buildpack without asking for confirmation", func() { 239 session := helpers.CF("delete-buildpack", buildpackName, "--force") 240 Eventually(session).Should(Say(`Deleting buildpack %s\.\.\.`, buildpackName)) 241 Eventually(session).Should(Say("OK")) 242 Eventually(session).Should(Exit(0)) 243 }) 244 }) 245 })