github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/integration/v6/global/rename_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("rename buildpack command", func() { 12 Describe("help", func() { 13 When("--help flag is set", func() { 14 It("Displays command usage to output", func() { 15 session := helpers.CF("rename-buildpack", "--help") 16 Eventually(session).Should(Say("NAME:")) 17 Eventually(session).Should(Say("rename-buildpack - Rename a buildpack")) 18 Eventually(session).Should(Say("USAGE:")) 19 Eventually(session).Should(Say(`cf rename-buildpack BUILDPACK_NAME NEW_BUILDPACK_NAME \[-s STACK\]`)) 20 Eventually(session).Should(Say("SEE ALSO:")) 21 Eventually(session).Should(Say("update-buildpack")) 22 Eventually(session).Should(Exit(0)) 23 }) 24 }) 25 }) 26 27 When("the environment is not setup correctly", func() { 28 It("fails with the appropriate errors", func() { 29 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "rename-buildpack", "fake-buildpack", "some-name") 30 }) 31 }) 32 33 When("the user is logged in", func() { 34 var ( 35 oldBuildpackName string 36 newBuildpackName string 37 stacks []string 38 username string 39 ) 40 41 BeforeEach(func() { 42 helpers.LoginCF() 43 oldBuildpackName = helpers.NewBuildpackName() 44 newBuildpackName = helpers.NewBuildpackName() 45 stacks = helpers.EnsureMinimumNumberOfStacks(2) 46 47 username, _ = helpers.GetCredentials() 48 }) 49 AfterEach(func() { 50 helpers.DeleteBuildpackIfOnOldCCAPI(oldBuildpackName) 51 helpers.DeleteBuildpackIfOnOldCCAPI(newBuildpackName) 52 }) 53 54 Context("when the user provides a stack", func() { 55 var session *Session 56 57 JustBeforeEach(func() { 58 session = helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName, "-s", stacks[0]) 59 }) 60 61 When("no buildpack with the name/stack combo is found", func() { 62 When("no buildpacks with the same name exist", func() { 63 It("returns a buildpack not found error", func() { 64 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 65 Eventually(session).Should(Say("FAILED")) 66 Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", oldBuildpackName, stacks[0])) 67 Eventually(session).Should(Exit(1)) 68 }) 69 }) 70 71 When("no buildpacks with the same name and stack exist", func() { 72 BeforeEach(func() { 73 helpers.SetupBuildpackWithoutStack(oldBuildpackName) 74 }) 75 76 It("returns a buildpack not found error", func() { 77 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 78 Eventually(session).Should(Say("FAILED")) 79 Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", oldBuildpackName, stacks[0])) 80 Eventually(session).Should(Exit(1)) 81 }) 82 }) 83 }) 84 85 When("there are multiple existing buildpacks with the specified old name", func() { 86 When("one of the existing buildpacks has an empty stack", func() { 87 BeforeEach(func() { 88 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 89 helpers.SetupBuildpackWithoutStack(oldBuildpackName) 90 }) 91 92 When("renaming to unique name", func() { 93 It("successfully renames the buildpack", func() { 94 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 95 Eventually(session).Should(Say("OK")) 96 Eventually(session).Should(Exit(0)) 97 }) 98 }) 99 100 When("renaming to the same name as another buildpack", func() { 101 When("the existing existing buildpack with the new name has the same stack", func() { 102 BeforeEach(func() { 103 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0]) 104 }) 105 106 It("returns an error", func() { 107 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 108 Eventually(session).Should(Say("FAILED")) 109 Eventually(session.Err).Should(Say("%s is already in use", newBuildpackName)) 110 Eventually(session).Should(Exit(1)) 111 }) 112 }) 113 114 When("the existing buildpack with the new name has a different stack", func() { 115 BeforeEach(func() { 116 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 117 }) 118 119 It("successfully renames the buildpack", func() { 120 Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username)) 121 Eventually(session).Should(Say("OK")) 122 Eventually(session).Should(Exit(0)) 123 }) 124 }) 125 126 When("the existing existing buildpack with the new name has an empty stack", func() { 127 BeforeEach(func() { 128 helpers.SetupBuildpackWithoutStack(newBuildpackName) 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 139 When("the new name is invalid", func() { 140 BeforeEach(func() { 141 newBuildpackName += ".dots!" 142 }) 143 It("returns an invalid-name error", 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("FAILED")) 146 Eventually(session.Err).Should(Say("Buildpack is invalid: (?:name ){1,2}can only contain alphanumeric characters")) 147 Eventually(session).Should(Exit(1)) 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("renaming to an invalid name", func() { 253 BeforeEach(func() { 254 newBuildpackName += ",hey.dots!" 255 }) 256 It("complains about the new name", func() { 257 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 258 Eventually(session.Err).Should(Say("Buildpack is invalid: (?:name ){1,2}can only contain alphanumeric characters")) 259 Eventually(session).Should(Say("FAILED")) 260 Eventually(session).Should(Exit(1)) 261 }) 262 }) 263 264 When("renaming to the same name as an existing buildpack with no stack association", func() { 265 BeforeEach(func() { 266 helpers.SetupBuildpackWithoutStack(newBuildpackName) 267 }) 268 269 It("successfully renames the buildpack", func() { 270 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 271 Eventually(session).Should(Say("OK")) 272 Eventually(session).Should(Exit(0)) 273 }) 274 275 }) 276 277 When("renaming to the same name as an existing buildpack with a different stack association", func() { 278 BeforeEach(func() { 279 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 280 }) 281 282 It("successfully renames the buildpack", func() { 283 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 284 Eventually(session).Should(Say("OK")) 285 Eventually(session).Should(Exit(0)) 286 }) 287 288 }) 289 290 When("renaming to the same name as an existing buildpack with the same stack assocation", func() { 291 BeforeEach(func() { 292 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0]) 293 }) 294 295 It("returns a buildpack name/stack taken error", func() { 296 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 297 Eventually(session).Should(Say("FAILED")) 298 Eventually(session.Err).Should(Say("The buildpack name %s is already in use for the stack %s", newBuildpackName, stacks[0])) 299 Eventually(session).Should(Exit(1)) 300 }) 301 }) 302 }) 303 304 When("there are multiple existing buildpacks with the old name", func() { 305 When("none of the buildpacks has an empty stack", func() { 306 BeforeEach(func() { 307 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 308 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[1]) 309 }) 310 311 It("returns a buildpack not found error", func() { 312 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 313 Eventually(session).Should(Say("FAILED")) 314 Eventually(session.Err).Should(Say(`Multiple buildpacks named %s found\. Specify a stack name by using a '-s' flag\.`, oldBuildpackName)) 315 Eventually(session).Should(Exit(1)) 316 }) 317 }) 318 319 When("one of the existing buildpacks with the old name has an empty stack", func() { 320 BeforeEach(func() { 321 helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0]) 322 helpers.SetupBuildpackWithoutStack(oldBuildpackName) 323 }) 324 325 When("renaming to unique name", func() { 326 It("successfully renames the buildpack", func() { 327 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 328 Eventually(session).Should(Say("OK")) 329 Eventually(session).Should(Exit(0)) 330 }) 331 }) 332 333 When("renaming to the same name as another buildpack", func() { 334 When("the existing buildpack with the new name has a non-empty stack", func() { 335 BeforeEach(func() { 336 helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1]) 337 }) 338 339 It("successfully renames the buildpack", func() { 340 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 341 Eventually(session).Should(Say("OK")) 342 Eventually(session).Should(Exit(0)) 343 }) 344 }) 345 346 When("the existing buildpack with the new name has an empty stack", func() { 347 BeforeEach(func() { 348 helpers.SetupBuildpackWithoutStack(newBuildpackName) 349 }) 350 351 It("returns a buildpack name/stack taken error", func() { 352 Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username)) 353 Eventually(session).Should(Say("FAILED")) 354 Eventually(session.Err).Should(Say("Buildpack %s already exists without a stack", newBuildpackName)) 355 Eventually(session).Should(Exit(1)) 356 }) 357 }) 358 }) 359 }) 360 }) 361 }) 362 }) 363 })