github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v6/global/rename_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 ) 11 12 var _ = Describe("rename buildpack command", func() { 13 Describe("help", func() { 14 When("--help flag is set", func() { 15 It("Displays command usage to output", func() { 16 session := helpers.CF("rename-buildpack", "--help") 17 Eventually(session).Should(Say("NAME:")) 18 Eventually(session).Should(Say("rename-buildpack - Rename a buildpack")) 19 Eventually(session).Should(Say("USAGE:")) 20 Eventually(session).Should(Say(`cf rename-buildpack BUILDPACK_NAME NEW_BUILDPACK_NAME \[-s STACK\]`)) 21 Eventually(session).Should(Say("SEE ALSO:")) 22 Eventually(session).Should(Say("update-buildpack")) 23 Eventually(session).Should(Exit(0)) 24 }) 25 }) 26 }) 27 28 When("the environment is not setup correctly", func() { 29 It("fails with the appropriate errors", func() { 30 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "rename-buildpack", "fake-buildpack", "some-name") 31 }) 32 }) 33 34 When("the user is logged in", func() { 35 var ( 36 oldBuildpackName string 37 newBuildpackName string 38 stacks []string 39 username string 40 ) 41 42 BeforeEach(func() { 43 helpers.LoginCF() 44 oldBuildpackName = helpers.NewBuildpackName() 45 newBuildpackName = helpers.NewBuildpackName() 46 stacks = helpers.EnsureMinimumNumberOfStacks(2) 47 48 username, _ = helpers.GetCredentials() 49 }) 50 51 When("the user provides a stack in an unsupported version", func() { 52 BeforeEach(func() { 53 helpers.SkipIfVersionAtLeast(ccversion.MinVersionBuildpackStackAssociationV2) 54 }) 55 56 It("should report that the version of CAPI is too low", func() { 57 session := helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName, "-s", stacks[0]) 58 Eventually(session.Err).Should(Say(`Option '-s' requires CF API version %s or higher. Your target is 2\.\d+\.\d+`, ccversion.MinVersionBuildpackStackAssociationV2)) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 Context("when the user provides a stack", func() { 64 var session *Session 65 BeforeEach(func() { 66 helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV2) 67 }) 68 69 JustBeforeEach(func() { 70 session = helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName, "-s", stacks[0]) 71 }) 72 73 When("no buildpack with the name/stack combo is found", func() { 74 When("no buildpacks with the same name exist", func() { 75 It("returns a buildpack not found error", func() { 76 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 77 Eventually(session).Should(Say("FAILED")) 78 Eventually(session.Err).Should(Say("Buildpack %s with stack %s not found", oldBuildpackName, stacks[0])) 79 Eventually(session).Should(Exit(1)) 80 }) 81 }) 82 83 When("no buildpacks with the same name and stack exist", func() { 84 BeforeEach(func() { 85 helpers.SetupBuildpackWithoutStack(oldBuildpackName) 86 }) 87 88 It("returns a buildpack not found error", func() { 89 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say("Buildpack %s with stack %s not found", oldBuildpackName, stacks[0])) 92 Eventually(session).Should(Exit(1)) 93 }) 94 }) 95 }) 96 97 When("there are multiple existing buildpacks with the specified old name", func() { 98 When("one of the existing buildpacks has an empty stack", func() { 99 BeforeEach(func() { 100 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 101 helpers.SetupBuildpackWithoutStack(oldBuildpackName) 102 }) 103 104 When("renaming to unique name", func() { 105 It("successfully renames the buildpack", func() { 106 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 107 Eventually(session).Should(Say("OK")) 108 Eventually(session).Should(Exit(0)) 109 }) 110 }) 111 112 When("renaming to the same name as another buildpack", func() { 113 When("the existing existing buildpack with the new name has the same stack", func() { 114 BeforeEach(func() { 115 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0]) 116 }) 117 118 It("returns an error", func() { 119 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 120 Eventually(session).Should(Say("FAILED")) 121 Eventually(session.Err).Should(Say("%s is already in use", newBuildpackName)) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 126 When("the existing buildpack with the new name has a different stack", func() { 127 BeforeEach(func() { 128 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 129 }) 130 131 It("successfully renames the buildpack", func() { 132 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 133 Eventually(session).Should(Say("OK")) 134 Eventually(session).Should(Exit(0)) 135 }) 136 }) 137 138 When("the existing existing buildpack with the new name has an empty stack", func() { 139 BeforeEach(func() { 140 helpers.SetupBuildpackWithoutStack(newBuildpackName) 141 }) 142 143 It("successfully renames the buildpack", func() { 144 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 145 Eventually(session).Should(Say("OK")) 146 Eventually(session).Should(Exit(0)) 147 }) 148 }) 149 }) 150 }) 151 152 When("neither of the existing buildpacks has an empty stack", func() { 153 BeforeEach(func() { 154 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 155 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[1]) 156 }) 157 158 When("renaming to unique name", func() { 159 It("successfully renames the buildpack", func() { 160 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 161 Eventually(session).Should(Say("OK")) 162 Eventually(session).Should(Exit(0)) 163 }) 164 }) 165 }) 166 }) 167 168 When("just one buildpack is found with the name/stack combo", func() { 169 BeforeEach(func() { 170 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 171 }) 172 173 When("renaming to unique name", func() { 174 It("successfully renames the buildpack", func() { 175 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 176 Eventually(session).Should(Say("OK")) 177 Eventually(session).Should(Exit(0)) 178 }) 179 }) 180 181 When("renaming to the same name as another buildpack", func() { 182 When("the existing buildpack with the new name has the same stack", func() { 183 BeforeEach(func() { 184 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0]) 185 }) 186 187 It("returns a buildpack name/stack taken error", func() { 188 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 189 Eventually(session).Should(Say("FAILED")) 190 Eventually(session.Err).Should(Say("%s is already in use", newBuildpackName)) 191 Eventually(session).Should(Exit(1)) 192 }) 193 }) 194 195 When("the existing buildpack with the new name has a different stack", func() { 196 BeforeEach(func() { 197 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 198 }) 199 200 It("successfully renames the buildpack", func() { 201 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 202 Eventually(session).Should(Say("OK")) 203 Eventually(session).Should(Exit(0)) 204 }) 205 }) 206 207 When("the existing buildpack with the new name has an empty stack", func() { 208 BeforeEach(func() { 209 helpers.SetupBuildpackWithoutStack(newBuildpackName) 210 }) 211 212 It("successfully renames the buildpack", func() { 213 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 214 Eventually(session).Should(Say("OK")) 215 Eventually(session).Should(Exit(0)) 216 }) 217 }) 218 }) 219 }) 220 }) 221 222 //If the user does not provide a stack, and there are multiple ambiguous buildpacks, we assume that they intended to rename the one with an empty stack. 223 When("the user does not provide a stack", func() { 224 var session *Session 225 226 JustBeforeEach(func() { 227 session = helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName) 228 }) 229 230 When("no buildpacks with the old name exist", func() { 231 It("returns a buildpack not found error", func() { 232 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 233 Eventually(session).Should(Say("FAILED")) 234 Eventually(session.Err).Should(Say("Buildpack %s not found", oldBuildpackName)) 235 Eventually(session).Should(Exit(1)) 236 }) 237 }) 238 239 When("one buildpack with the old name exists with a stack association", func() { 240 BeforeEach(func() { 241 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 242 }) 243 244 When("renaming to unique name", func() { 245 It("successfully renames the buildpack", func() { 246 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 247 Eventually(session).Should(Say("OK")) 248 Eventually(session).Should(Exit(0)) 249 }) 250 }) 251 252 When("The API version supports stack association", func() { 253 BeforeEach(func() { 254 helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV2) 255 }) 256 257 When("renaming to the same name as an existing buildpack with no stack association", func() { 258 BeforeEach(func() { 259 helpers.SetupBuildpackWithoutStack(newBuildpackName) 260 }) 261 262 It("successfully renames the buildpack", func() { 263 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 264 Eventually(session).Should(Say("OK")) 265 Eventually(session).Should(Exit(0)) 266 }) 267 268 }) 269 270 When("renaming to the same name as an existing buildpack with a different stack association", func() { 271 BeforeEach(func() { 272 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 273 }) 274 275 It("successfully renames the buildpack", func() { 276 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 277 Eventually(session).Should(Say("OK")) 278 Eventually(session).Should(Exit(0)) 279 }) 280 281 }) 282 283 When("renaming to the same name as an existing buildpack with the same stack assocation", func() { 284 BeforeEach(func() { 285 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0]) 286 }) 287 288 It("returns a buildpack name/stack taken error", func() { 289 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 290 Eventually(session).Should(Say("FAILED")) 291 Eventually(session.Err).Should(Say("The buildpack name %s is already in use for the stack %s", newBuildpackName, stacks[0])) 292 Eventually(session).Should(Exit(1)) 293 }) 294 }) 295 }) 296 297 When("The API version does not support stack association", func() { 298 BeforeEach(func() { 299 helpers.SkipIfVersionAtLeast(ccversion.MinVersionBuildpackStackAssociationV2) 300 }) 301 302 When("renaming to the same name as an existing buildpack with no stack association", func() { 303 BeforeEach(func() { 304 helpers.SetupBuildpackWithoutStack(newBuildpackName) 305 }) 306 307 It("returns a buildpack name taken error", func() { 308 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 309 Eventually(session).Should(Say("FAILED")) 310 Eventually(session.Err).Should(Say("The buildpack name is already in use: %s", newBuildpackName)) 311 Eventually(session).Should(Exit(1)) 312 }) 313 314 }) 315 316 When("renaming to the same name as an existing buildpack with a different stack association", func() { 317 BeforeEach(func() { 318 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 319 }) 320 321 It("successfully renames the buildpack", func() { 322 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 323 Eventually(session).Should(Say("FAILED")) 324 Eventually(session.Err).Should(Say("The buildpack name is already in use: %s", newBuildpackName)) 325 Eventually(session).Should(Exit(1)) 326 }) 327 328 }) 329 330 When("renaming to the same name as an existing buildpack with the same stack assocation", func() { 331 BeforeEach(func() { 332 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0]) 333 }) 334 335 It("returns a buildpack name/stack taken error", func() { 336 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 337 Eventually(session).Should(Say("FAILED")) 338 Eventually(session.Err).Should(Say("The buildpack name is already in use: %s", newBuildpackName)) 339 Eventually(session).Should(Exit(1)) 340 }) 341 }) 342 }) 343 }) 344 345 When("there are multiple existing buildpacks with the old name", func() { 346 BeforeEach(func() { 347 helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV2) 348 }) 349 350 When("none of the buildpacks has an empty stack", func() { 351 BeforeEach(func() { 352 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 353 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[1]) 354 }) 355 356 It("returns a buildpack not found error", func() { 357 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 358 Eventually(session).Should(Say("FAILED")) 359 Eventually(session.Err).Should(Say(`Multiple buildpacks named %s found\. Specify a stack name by using a '-s' flag\.`, oldBuildpackName)) 360 Eventually(session).Should(Exit(1)) 361 }) 362 }) 363 364 When("one of the existing buildpacks with the old name has an empty stack", func() { 365 BeforeEach(func() { 366 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 367 helpers.SetupBuildpackWithoutStack(oldBuildpackName) 368 }) 369 370 When("renaming to unique name", func() { 371 It("successfully renames the buildpack", func() { 372 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 373 Eventually(session).Should(Say("OK")) 374 Eventually(session).Should(Exit(0)) 375 }) 376 }) 377 378 When("renaming to the same name as another buildpack", func() { 379 When("the existing buildpack with the new name has a non-empty stack", func() { 380 BeforeEach(func() { 381 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 382 }) 383 384 It("successfully renames the buildpack", func() { 385 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 386 Eventually(session).Should(Say("OK")) 387 Eventually(session).Should(Exit(0)) 388 }) 389 }) 390 391 When("the existing buildpack with the new name has an empty stack", func() { 392 BeforeEach(func() { 393 helpers.SetupBuildpackWithoutStack(newBuildpackName) 394 }) 395 396 It("returns a buildpack name/stack taken error", func() { 397 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 398 Eventually(session).Should(Say("FAILED")) 399 Eventually(session.Err).Should(Say("Buildpack %s already exists without a stack", newBuildpackName)) 400 Eventually(session).Should(Exit(1)) 401 }) 402 }) 403 }) 404 }) 405 }) 406 }) 407 }) 408 })