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