github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+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  		AfterEach(func() {
    51  			helpers.DeleteBuildpackIfOnOldCCAPI(oldBuildpackName)
    52  			helpers.DeleteBuildpackIfOnOldCCAPI(newBuildpackName)
    53  		})
    54  
    55  		When("the user provides a stack in an unsupported version", func() {
    56  			BeforeEach(func() {
    57  				helpers.SkipIfVersionAtLeast(ccversion.MinVersionBuildpackStackAssociationV2)
    58  			})
    59  
    60  			It("should report that the version of CAPI is too low", func() {
    61  				session := helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName, "-s", stacks[0])
    62  				Eventually(session.Err).Should(Say(`Option '-s' requires CF API version %s or higher. Your target is 2\.\d+\.\d+`, ccversion.MinVersionBuildpackStackAssociationV2))
    63  				Eventually(session).Should(Exit(1))
    64  			})
    65  		})
    66  
    67  		Context("when the user provides a stack", func() {
    68  			var session *Session
    69  			BeforeEach(func() {
    70  				helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV2)
    71  			})
    72  
    73  			JustBeforeEach(func() {
    74  				session = helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName, "-s", stacks[0])
    75  			})
    76  
    77  			When("no buildpack with the name/stack combo is found", func() {
    78  				When("no buildpacks with the same name exist", func() {
    79  					It("returns a buildpack not found error", func() {
    80  						Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
    81  						Eventually(session).Should(Say("FAILED"))
    82  						Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", oldBuildpackName, stacks[0]))
    83  						Eventually(session).Should(Exit(1))
    84  					})
    85  				})
    86  
    87  				When("no buildpacks with the same name and stack exist", func() {
    88  					BeforeEach(func() {
    89  						helpers.SetupBuildpackWithoutStack(oldBuildpackName)
    90  					})
    91  
    92  					It("returns a buildpack not found error", func() {
    93  						Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
    94  						Eventually(session).Should(Say("FAILED"))
    95  						Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", oldBuildpackName, stacks[0]))
    96  						Eventually(session).Should(Exit(1))
    97  					})
    98  				})
    99  			})
   100  
   101  			When("there are multiple existing buildpacks with the specified old name", func() {
   102  				When("one of the existing buildpacks has an empty stack", func() {
   103  					BeforeEach(func() {
   104  						helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0])
   105  						helpers.SetupBuildpackWithoutStack(oldBuildpackName)
   106  					})
   107  
   108  					When("renaming to unique name", func() {
   109  						It("successfully renames the buildpack", func() {
   110  							Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   111  							Eventually(session).Should(Say("OK"))
   112  							Eventually(session).Should(Exit(0))
   113  						})
   114  					})
   115  
   116  					When("renaming to the same name as another buildpack", func() {
   117  						When("the existing existing buildpack with the new name has the same stack", func() {
   118  							BeforeEach(func() {
   119  								helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0])
   120  							})
   121  
   122  							It("returns an error", func() {
   123  								Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   124  								Eventually(session).Should(Say("FAILED"))
   125  								Eventually(session.Err).Should(Say("%s is already in use", newBuildpackName))
   126  								Eventually(session).Should(Exit(1))
   127  							})
   128  						})
   129  
   130  						When("the existing buildpack with the new name has a different stack", func() {
   131  							BeforeEach(func() {
   132  								helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1])
   133  							})
   134  
   135  							It("successfully renames the buildpack", func() {
   136  								Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   137  								Eventually(session).Should(Say("OK"))
   138  								Eventually(session).Should(Exit(0))
   139  							})
   140  						})
   141  
   142  						When("the existing existing buildpack with the new name has an empty stack", func() {
   143  							BeforeEach(func() {
   144  								helpers.SetupBuildpackWithoutStack(newBuildpackName)
   145  							})
   146  
   147  							It("successfully renames the buildpack", func() {
   148  								Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   149  								Eventually(session).Should(Say("OK"))
   150  								Eventually(session).Should(Exit(0))
   151  							})
   152  						})
   153  					})
   154  
   155  					When("the new name is invalid", func() {
   156  						BeforeEach(func() {
   157  							newBuildpackName += ".dots!"
   158  						})
   159  						It("returns an invalid-name error", 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("FAILED"))
   162  							Eventually(session.Err).Should(Say("Buildpack is invalid: (?:name ){1,2}can only contain alphanumeric characters"))
   163  							Eventually(session).Should(Exit(1))
   164  						})
   165  					})
   166  				})
   167  
   168  				When("neither of the existing buildpacks has an empty stack", func() {
   169  					BeforeEach(func() {
   170  						helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0])
   171  						helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[1])
   172  					})
   173  
   174  					When("renaming to unique name", func() {
   175  						It("successfully renames the buildpack", func() {
   176  							Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   177  							Eventually(session).Should(Say("OK"))
   178  							Eventually(session).Should(Exit(0))
   179  						})
   180  					})
   181  				})
   182  			})
   183  
   184  			When("just one buildpack is found with the name/stack combo", func() {
   185  				BeforeEach(func() {
   186  					helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0])
   187  				})
   188  
   189  				When("renaming to unique name", func() {
   190  					It("successfully renames the buildpack", func() {
   191  						Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   192  						Eventually(session).Should(Say("OK"))
   193  						Eventually(session).Should(Exit(0))
   194  					})
   195  				})
   196  
   197  				When("renaming to the same name as another buildpack", func() {
   198  					When("the existing buildpack with the new name has the same stack", func() {
   199  						BeforeEach(func() {
   200  							helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0])
   201  						})
   202  
   203  						It("returns a buildpack name/stack taken error", func() {
   204  							Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   205  							Eventually(session).Should(Say("FAILED"))
   206  							Eventually(session.Err).Should(Say("%s is already in use", newBuildpackName))
   207  							Eventually(session).Should(Exit(1))
   208  						})
   209  					})
   210  
   211  					When("the existing buildpack with the new name has a different stack", func() {
   212  						BeforeEach(func() {
   213  							helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1])
   214  						})
   215  
   216  						It("successfully renames the buildpack", func() {
   217  							Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   218  							Eventually(session).Should(Say("OK"))
   219  							Eventually(session).Should(Exit(0))
   220  						})
   221  					})
   222  
   223  					When("the existing buildpack with the new name has an empty stack", func() {
   224  						BeforeEach(func() {
   225  							helpers.SetupBuildpackWithoutStack(newBuildpackName)
   226  						})
   227  
   228  						It("successfully renames the buildpack", func() {
   229  							Eventually(session).Should(Say(`Renaming buildpack %s to %s with stack %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, stacks[0], username))
   230  							Eventually(session).Should(Say("OK"))
   231  							Eventually(session).Should(Exit(0))
   232  						})
   233  					})
   234  				})
   235  			})
   236  		})
   237  
   238  		//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.
   239  		When("the user does not provide a stack", func() {
   240  			var session *Session
   241  
   242  			JustBeforeEach(func() {
   243  				session = helpers.CF("rename-buildpack", oldBuildpackName, newBuildpackName)
   244  			})
   245  
   246  			When("no buildpacks with the old name exist", func() {
   247  				It("returns a buildpack not found error", func() {
   248  					Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   249  					Eventually(session).Should(Say("FAILED"))
   250  					Eventually(session.Err).Should(Say("Buildpack '%s' not found", oldBuildpackName))
   251  					Eventually(session).Should(Exit(1))
   252  				})
   253  			})
   254  
   255  			When("one buildpack with the old name exists with a stack association", func() {
   256  				BeforeEach(func() {
   257  					helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0])
   258  				})
   259  
   260  				When("renaming to unique name", func() {
   261  					It("successfully renames the buildpack", func() {
   262  						Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   263  						Eventually(session).Should(Say("OK"))
   264  						Eventually(session).Should(Exit(0))
   265  					})
   266  				})
   267  
   268  				When("renaming to an invalid name", func() {
   269  					BeforeEach(func() {
   270  						newBuildpackName += ",hey.dots!"
   271  					})
   272  					It("complains about the new name", func() {
   273  						Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   274  						Eventually(session.Err).Should(Say("Buildpack is invalid: (?:name ){1,2}can only contain alphanumeric characters"))
   275  						Eventually(session).Should(Say("FAILED"))
   276  						Eventually(session).Should(Exit(1))
   277  					})
   278  				})
   279  
   280  				When("The API version supports stack association", func() {
   281  					BeforeEach(func() {
   282  						helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV2)
   283  					})
   284  
   285  					When("renaming to the same name as an existing buildpack with no stack association", func() {
   286  						BeforeEach(func() {
   287  							helpers.SetupBuildpackWithoutStack(newBuildpackName)
   288  						})
   289  
   290  						It("successfully renames the buildpack", func() {
   291  							Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   292  							Eventually(session).Should(Say("OK"))
   293  							Eventually(session).Should(Exit(0))
   294  						})
   295  
   296  					})
   297  
   298  					When("renaming to the same name as an existing buildpack with a different stack association", func() {
   299  						BeforeEach(func() {
   300  							helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1])
   301  						})
   302  
   303  						It("successfully renames the buildpack", func() {
   304  							Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   305  							Eventually(session).Should(Say("OK"))
   306  							Eventually(session).Should(Exit(0))
   307  						})
   308  
   309  					})
   310  
   311  					When("renaming to the same name as an existing buildpack with the same stack assocation", func() {
   312  						BeforeEach(func() {
   313  							helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0])
   314  						})
   315  
   316  						It("returns a buildpack name/stack taken error", func() {
   317  							Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   318  							Eventually(session).Should(Say("FAILED"))
   319  							Eventually(session.Err).Should(Say("The buildpack name %s is already in use for the stack %s", newBuildpackName, stacks[0]))
   320  							Eventually(session).Should(Exit(1))
   321  						})
   322  					})
   323  				})
   324  
   325  				When("The API version does not support stack association", func() {
   326  					BeforeEach(func() {
   327  						helpers.SkipIfVersionAtLeast(ccversion.MinVersionBuildpackStackAssociationV2)
   328  					})
   329  
   330  					When("renaming to the same name as an existing buildpack with no stack association", func() {
   331  						BeforeEach(func() {
   332  							helpers.SetupBuildpackWithoutStack(newBuildpackName)
   333  						})
   334  
   335  						It("returns a buildpack name 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  					When("renaming to the same name as an existing buildpack with a different stack association", func() {
   345  						BeforeEach(func() {
   346  							helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1])
   347  						})
   348  
   349  						It("successfully renames the buildpack", func() {
   350  							Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   351  							Eventually(session).Should(Say("FAILED"))
   352  							Eventually(session.Err).Should(Say("The buildpack name is already in use: %s", newBuildpackName))
   353  							Eventually(session).Should(Exit(1))
   354  						})
   355  
   356  					})
   357  
   358  					When("renaming to the same name as an existing buildpack with the same stack assocation", func() {
   359  						BeforeEach(func() {
   360  							helpers.SetupBuildpackWithStack(newBuildpackName, stacks[0])
   361  						})
   362  
   363  						It("returns a buildpack name/stack taken error", func() {
   364  							Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   365  							Eventually(session).Should(Say("FAILED"))
   366  							Eventually(session.Err).Should(Say("The buildpack name is already in use: %s", newBuildpackName))
   367  							Eventually(session).Should(Exit(1))
   368  						})
   369  					})
   370  				})
   371  			})
   372  
   373  			When("there are multiple existing buildpacks with the old name", func() {
   374  				BeforeEach(func() {
   375  					helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV2)
   376  				})
   377  
   378  				When("none of the buildpacks has an empty stack", func() {
   379  					BeforeEach(func() {
   380  						helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0])
   381  						helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[1])
   382  					})
   383  
   384  					It("returns a buildpack not found error", func() {
   385  						Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   386  						Eventually(session).Should(Say("FAILED"))
   387  						Eventually(session.Err).Should(Say(`Multiple buildpacks named %s found\. Specify a stack name by using a '-s' flag\.`, oldBuildpackName))
   388  						Eventually(session).Should(Exit(1))
   389  					})
   390  				})
   391  
   392  				When("one of the existing buildpacks with the old name has an empty stack", func() {
   393  					BeforeEach(func() {
   394  						helpers.SetupBuildpackWithStack(oldBuildpackName, stacks[0])
   395  						helpers.SetupBuildpackWithoutStack(oldBuildpackName)
   396  					})
   397  
   398  					When("renaming to unique name", func() {
   399  						It("successfully renames the buildpack", func() {
   400  							Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   401  							Eventually(session).Should(Say("OK"))
   402  							Eventually(session).Should(Exit(0))
   403  						})
   404  					})
   405  
   406  					When("renaming to the same name as another buildpack", func() {
   407  						When("the existing buildpack with the new name has a non-empty stack", func() {
   408  							BeforeEach(func() {
   409  								helpers.SetupBuildpackWithStack(newBuildpackName, stacks[1])
   410  							})
   411  
   412  							It("successfully renames the buildpack", func() {
   413  								Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   414  								Eventually(session).Should(Say("OK"))
   415  								Eventually(session).Should(Exit(0))
   416  							})
   417  						})
   418  
   419  						When("the existing buildpack with the new name has an empty stack", func() {
   420  							BeforeEach(func() {
   421  								helpers.SetupBuildpackWithoutStack(newBuildpackName)
   422  							})
   423  
   424  							It("returns a buildpack name/stack taken error", func() {
   425  								Eventually(session).Should(Say(`Renaming buildpack %s to %s as %s\.\.\.`, oldBuildpackName, newBuildpackName, username))
   426  								Eventually(session).Should(Say("FAILED"))
   427  								Eventually(session.Err).Should(Say("Buildpack %s already exists without a stack", newBuildpackName))
   428  								Eventually(session).Should(Exit(1))
   429  							})
   430  						})
   431  					})
   432  				})
   433  			})
   434  		})
   435  	})
   436  })