github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+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 buffer.Write([]byte("y\n")) 191 }) 192 193 It("deletes the buildpack", func() { 194 session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName) 195 Eventually(session).Should(Say(`Deleting buildpack %s\.\.\.`, buildpackName)) 196 Eventually(session).Should(Say("OK")) 197 Eventually(session).Should(Exit(0)) 198 }) 199 }) 200 201 When("the user enters 'n'", func() { 202 BeforeEach(func() { 203 buffer.Write([]byte("n\n")) 204 }) 205 206 It("does not delete the buildpack", func() { 207 session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName) 208 Eventually(session).Should(Say("Delete cancelled")) 209 Eventually(session).Should(Exit(0)) 210 211 session = helpers.CF("buildpacks") 212 Eventually(session).Should(Say(buildpackName)) 213 Eventually(session).Should(Exit(0)) 214 }) 215 }) 216 217 When("the user enters the default input (hits return)", func() { 218 BeforeEach(func() { 219 buffer.Write([]byte("\n")) 220 }) 221 222 It("does not delete the buildpack", func() { 223 session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName) 224 Eventually(session).Should(Say("Delete cancelled")) 225 Eventually(session).Should(Exit(0)) 226 227 session = helpers.CF("buildpacks") 228 Eventually(session).Should(Say(buildpackName)) 229 Eventually(session).Should(Exit(0)) 230 }) 231 }) 232 }) 233 234 When("the --force flag is provided", func() { 235 It("deletes the buildpack without asking for confirmation", func() { 236 session := helpers.CF("delete-buildpack", buildpackName, "--force") 237 Eventually(session).Should(Say(`Deleting buildpack %s\.\.\.`, buildpackName)) 238 Eventually(session).Should(Say("OK")) 239 Eventually(session).Should(Exit(0)) 240 }) 241 }) 242 })