github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/global/update_buildpack_command_test.go (about)

     1  package global
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"log"
     7  	"net/http"
     8  	"os"
     9  	"regexp"
    10  
    11  	"code.cloudfoundry.org/cli/integration/helpers"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  	. "github.com/onsi/gomega/gbytes"
    15  	. "github.com/onsi/gomega/gexec"
    16  	. "github.com/onsi/gomega/ghttp"
    17  )
    18  
    19  var _ = Describe("update-buildpack command", func() {
    20  	var (
    21  		buildpackName string
    22  		username      string
    23  	)
    24  
    25  	BeforeEach(func() {
    26  		buildpackName = helpers.NewBuildpackName()
    27  		username, _ = helpers.GetCredentials()
    28  	})
    29  
    30  	When("--help flag is set", func() {
    31  		It("Displays command usage to output", func() {
    32  			session := helpers.CF("update-buildpack", "--help")
    33  			Eventually(session).Should(Say("NAME:"))
    34  			Eventually(session).Should(Say("update-buildpack - Update a buildpack"))
    35  			Eventually(session).Should(Say("USAGE:"))
    36  			Eventually(session).Should(Say(regexp.QuoteMeta(`cf update-buildpack BUILDPACK [-p PATH | -s STACK | --assign-stack NEW_STACK] [-i POSITION] [--rename NEW_NAME] [--enable|--disable] [--lock|--unlock]`)))
    37  			Eventually(session).Should(Say("TIP:"))
    38  			Eventually(session).Should(Say("Path should be a zip file, a url to a zip file, or a local directory. Position is a positive integer, sets priority, and is sorted from lowest to highest.\n\n"))
    39  			Eventually(session).Should(Say("Use '--assign-stack' with caution. Associating a buildpack with a stack that it does not support may result in undefined behavior. Additionally, changing this association once made may require a local copy of the buildpack.\n\n"))
    40  			Eventually(session).Should(Say("OPTIONS:"))
    41  			Eventually(session).Should(Say(`--assign-stack\s+Assign a stack to a buildpack that does not have a stack association`))
    42  			Eventually(session).Should(Say(`--disable\s+Disable the buildpack from being used for staging`))
    43  			Eventually(session).Should(Say(`--enable\s+Enable the buildpack to be used for staging`))
    44  			Eventually(session).Should(Say(`--lock\s+Lock the buildpack to prevent updates`))
    45  			Eventually(session).Should(Say(`--path, -p\s+Path to directory or zip file`))
    46  			Eventually(session).Should(Say(`--position, -i\s+The order in which the buildpacks are checked during buildpack auto-detection`))
    47  			Eventually(session).Should(Say(`--rename\s+Rename an existing buildpack`))
    48  			Eventually(session).Should(Say(`--stack, -s\s+Specify stack to disambiguate buildpacks with the same name`))
    49  			Eventually(session).Should(Say(`--unlock\s+Unlock the buildpack to enable updates`))
    50  			Eventually(session).Should(Say("SEE ALSO:"))
    51  			Eventually(session).Should(Say("buildpacks, create-buildpack, delete-buildpack"))
    52  			Eventually(session).Should(Exit(0))
    53  		})
    54  	})
    55  
    56  	When("the environment is not setup correctly", func() {
    57  		It("fails with the appropriate errors", func() {
    58  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "update-buildpack", "fake-buildpack")
    59  		})
    60  	})
    61  
    62  	When("the user is logged in", func() {
    63  		BeforeEach(func() {
    64  			helpers.LoginCF()
    65  		})
    66  
    67  		AfterEach(func() {
    68  			helpers.DeleteBuildpackIfOnOldCCAPI(buildpackName)
    69  		})
    70  
    71  		When("the buildpack is not provided", func() {
    72  			It("returns a buildpack argument not provided error", func() {
    73  				session := helpers.CF("update-buildpack", "-p", ".")
    74  
    75  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `BUILDPACK` was not provided"))
    76  				Eventually(session).Should(Exit(1))
    77  			})
    78  		})
    79  
    80  		When("the buildpack name is provided", func() {
    81  			When("the buildpack does not exist", func() {
    82  				It("returns a buildpack not found error", func() {
    83  					session := helpers.CF("update-buildpack", buildpackName)
    84  					Eventually(session.Err).Should(Say("Buildpack '%s' not found", buildpackName))
    85  					Eventually(session).Should(Say("FAILED"))
    86  					Eventually(session).Should(Exit(1))
    87  				})
    88  			})
    89  
    90  			Describe("stack association", func() {
    91  				var stacks []string
    92  
    93  				BeforeEach(func() {
    94  					stacks = helpers.EnsureMinimumNumberOfStacks(2)
    95  				})
    96  
    97  				When("multiple buildpacks with the same name exist in enabled and unlocked state, and one has nil stack", func() {
    98  					BeforeEach(func() {
    99  						helpers.BuildpackWithStack(func(buildpackArchive string) {
   100  							createSession := helpers.CF("create-buildpack", buildpackName, buildpackArchive, "99")
   101  							Eventually(createSession).Should(Exit(0))
   102  						}, stacks[0])
   103  
   104  						helpers.BuildpackWithoutStack(func(buildpackArchive string) {
   105  							createSession := helpers.CF("create-buildpack", buildpackName, buildpackArchive, "100")
   106  							Eventually(createSession).Should(Exit(0))
   107  						})
   108  
   109  						listSession := helpers.CF("buildpacks")
   110  						Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{
   111  							Name: buildpackName, Stack: stacks[0]})))
   112  						Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{Name: buildpackName})))
   113  						Eventually(listSession).Should(Exit(0))
   114  					})
   115  
   116  					When("no stack association is specified", func() {
   117  						It("acts on the buildpack with the nil stack", func() {
   118  							session := helpers.CF("update-buildpack", buildpackName)
   119  
   120  							Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   121  							Eventually(session).Should(Say("OK"))
   122  							Eventually(session).Should(Exit(0))
   123  						})
   124  					})
   125  
   126  					When("the user specifies a stack association not matching any of the existing buildpacks with this name", func() {
   127  						It("reports that it couldn't find the buildpack", func() {
   128  							nonexistentStack := "some-incorrect-stack-name"
   129  							session := helpers.CF("update-buildpack", buildpackName, "-s", nonexistentStack)
   130  
   131  							Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", buildpackName, nonexistentStack))
   132  							Eventually(session).Should(Say("FAILED"))
   133  							Eventually(session).Should(Exit(1))
   134  						})
   135  					})
   136  
   137  					When("the user specifies a stack association matching one of the existing buildpacks with this name", func() {
   138  						It("finds the buildpack with the stack specified (and not the buildpack with the nil stack)", func() {
   139  							session := helpers.CF("update-buildpack", buildpackName, "-s", stacks[0])
   140  
   141  							Eventually(session).Should(Say("Updating buildpack %s with stack %s as %s...",
   142  								buildpackName, stacks[0], username,
   143  							))
   144  							Eventually(session).Should(Say("OK"))
   145  							Eventually(session).Should(Exit(0))
   146  						})
   147  					})
   148  				})
   149  
   150  				When("multiple buildpacks with the same name exist in enabled and unlocked state, and all have stacks", func() {
   151  					BeforeEach(func() {
   152  						helpers.BuildpackWithStack(func(buildpackArchive string) {
   153  							createSession := helpers.CF("create-buildpack", buildpackName, buildpackArchive, "98")
   154  							Eventually(createSession).Should(Exit(0))
   155  						}, stacks[0])
   156  
   157  						helpers.BuildpackWithStack(func(buildpackArchive string) {
   158  							createSession := helpers.CF("create-buildpack", buildpackName, buildpackArchive, "99")
   159  							Eventually(createSession).Should(Exit(0))
   160  						}, stacks[1])
   161  
   162  						listSession := helpers.CF("buildpacks")
   163  						Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{
   164  							Name: buildpackName, Stack: stacks[0]})))
   165  						Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{
   166  							Name: buildpackName, Stack: stacks[1]})))
   167  						Eventually(listSession).Should(Exit(0))
   168  					})
   169  
   170  					When("no stack association is specified", func() {
   171  						It("displays an error saying that multiple buildpacks were found", func() {
   172  							session := helpers.CF("update-buildpack", buildpackName)
   173  
   174  							Eventually(session.Err).Should(Say(`Multiple buildpacks named %s found\. Specify a stack name by using a '-s' flag\.`, buildpackName))
   175  							Eventually(session).Should(Say("FAILED"))
   176  							Eventually(session).Should(Exit(1))
   177  						})
   178  					})
   179  
   180  					When("the user specifies a stack association not matching any of the existing buildpacks with this name", func() {
   181  						It("reports that it couldn't find the buildpack", func() {
   182  							nonexistentStack := "some-incorrect-stack-name"
   183  							session := helpers.CF("update-buildpack", buildpackName, "-s", nonexistentStack)
   184  
   185  							Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", buildpackName, nonexistentStack))
   186  							Eventually(session).Should(Say("FAILED"))
   187  							Eventually(session).Should(Exit(1))
   188  						})
   189  					})
   190  
   191  					When("the user specifies a stack association matching one of the existing buildpacks with this name", func() {
   192  						It("finds the buildpack with the stack specified (and not the buildpack with the other stack)", func() {
   193  							session := helpers.CF("update-buildpack", buildpackName, "-s", stacks[0])
   194  
   195  							Eventually(session).Should(Say("Updating buildpack %s with stack %s as %s...",
   196  								buildpackName, stacks[0], username,
   197  							))
   198  							Eventually(session).Should(Say("OK"))
   199  							Eventually(session).Should(Exit(0))
   200  						})
   201  					})
   202  				})
   203  
   204  				When("one buildpack with the given name exists in enabled and unlocked state with a stack association", func() {
   205  					BeforeEach(func() {
   206  						helpers.BuildpackWithStack(func(buildpackArchive string) {
   207  							createSession := helpers.CF("create-buildpack", buildpackName, buildpackArchive, "99")
   208  							Eventually(createSession).Should(Exit(0))
   209  						}, stacks[0])
   210  
   211  						listSession := helpers.CF("buildpacks")
   212  						Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{
   213  							Name: buildpackName, Stack: stacks[0]})))
   214  						Eventually(listSession).Should(Exit(0))
   215  					})
   216  
   217  					When("no stack association is specified", func() {
   218  						It("updates the only buildpack with that name", func() {
   219  							session := helpers.CF("update-buildpack", buildpackName)
   220  
   221  							Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   222  							Eventually(session).Should(Say("OK"))
   223  							Eventually(session).Should(Exit(0))
   224  						})
   225  					})
   226  
   227  					When("the user specifies a stack association matching the buildpack with this name", func() {
   228  						It("finds the buildpack with the stack specified", func() {
   229  							session := helpers.CF("update-buildpack", buildpackName, "-s", stacks[0])
   230  
   231  							Eventually(session).Should(Say("Updating buildpack %s with stack %s as %s...",
   232  								buildpackName, stacks[0], username,
   233  							))
   234  							Eventually(session).Should(Say("OK"))
   235  							Eventually(session).Should(Exit(0))
   236  						})
   237  					})
   238  				})
   239  			})
   240  
   241  			When("one buildpack with given name exists in enabled and unlocked state with no stack association", func() {
   242  				BeforeEach(func() {
   243  					helpers.BuildpackWithoutStack(func(buildpackArchive string) {
   244  						createSession := helpers.CF("create-buildpack", buildpackName, buildpackArchive, "99")
   245  						Eventually(createSession).Should(Exit(0))
   246  					})
   247  
   248  					listSession := helpers.CF("buildpacks")
   249  					Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{Name: buildpackName})))
   250  					Eventually(listSession).Should(Exit(0))
   251  				})
   252  
   253  				When("only a name is provided", func() {
   254  					It("prints a success message", func() {
   255  						session := helpers.CF("update-buildpack", buildpackName)
   256  
   257  						Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   258  						Eventually(session).Should(Say("OK"))
   259  						Eventually(session).Should(Exit(0))
   260  					})
   261  				})
   262  
   263  				When("the -s flag is provided", func() {
   264  					var (
   265  						stackName string
   266  						session   *Session
   267  					)
   268  
   269  					JustBeforeEach(func() {
   270  						stackName = "some-stack"
   271  						session = helpers.CF("update-buildpack", buildpackName, "-s", stackName)
   272  					})
   273  
   274  					It("returns a buildpack with stack not found error", func() {
   275  						Eventually(session.Err).Should(Say("Buildpack '%s' with stack '%s' not found", buildpackName, stackName))
   276  						Eventually(session).Should(Say("FAILED"))
   277  						Eventually(session).Should(Exit(1))
   278  					})
   279  				})
   280  
   281  				When("the -p flag is provided", func() {
   282  					var (
   283  						buildpackPath string
   284  						session       *Session
   285  					)
   286  
   287  					JustBeforeEach(func() {
   288  						session = helpers.CF("update-buildpack", buildpackName, "-p", buildpackPath)
   289  					})
   290  
   291  					When("the path is local", func() {
   292  						When("the buildpack path exists", func() {
   293  							When("the buildpack path is an empty directory", func() {
   294  								BeforeEach(func() {
   295  									var err error
   296  									buildpackPath, err = ioutil.TempDir("", "create-buildpack-test-")
   297  									Expect(err).ToNot(HaveOccurred())
   298  								})
   299  
   300  								AfterEach(func() {
   301  									err := os.RemoveAll(buildpackPath)
   302  									Expect(err).ToNot(HaveOccurred())
   303  								})
   304  
   305  								It("prints an error message", func() {
   306  									Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   307  									Eventually(session.Err).Should(Say("The specified path '%s' cannot be an empty directory.", regexp.QuoteMeta(buildpackPath)))
   308  									Eventually(session).Should(Exit(1))
   309  								})
   310  							})
   311  
   312  							When("the path is a buildpack directory", func() {
   313  								BeforeEach(func() {
   314  									var err error
   315  									buildpackPath, err = ioutil.TempDir("", "create-buildpack-test-")
   316  									Expect(err).ToNot(HaveOccurred())
   317  									file, err := ioutil.TempFile(buildpackPath, "")
   318  									Expect(err).ToNot(HaveOccurred())
   319  									defer file.Close()
   320  								})
   321  
   322  								AfterEach(func() {
   323  									err := os.RemoveAll(buildpackPath)
   324  									Expect(err).ToNot(HaveOccurred())
   325  								})
   326  
   327  								It("updates the buildpack with the given bits", func() {
   328  									Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   329  									Eventually(session).Should(Say("OK"))
   330  									Eventually(session).Should(Exit(0))
   331  								})
   332  							})
   333  
   334  							When("uploading from a zip", func() {
   335  								BeforeEach(func() {
   336  									buildpackPath = helpers.MakeBuildpackArchive("")
   337  								})
   338  
   339  								AfterEach(func() {
   340  									err := os.Remove(buildpackPath)
   341  									Expect(err).NotTo(HaveOccurred())
   342  								})
   343  
   344  								It("updates the buildpack with the given bits", func() {
   345  									Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   346  									Eventually(session).Should(Say("OK"))
   347  									Eventually(session).Should(Exit(0))
   348  								})
   349  							})
   350  						})
   351  
   352  						When("the buildpack path does not exist", func() {
   353  							BeforeEach(func() {
   354  								buildpackPath = "this-is-a-bogus-path"
   355  							})
   356  
   357  							It("returns a buildpack does not exist error", func() {
   358  								Eventually(session.Err).Should(Say("Incorrect Usage: The specified path 'this-is-a-bogus-path' does not exist."))
   359  								Eventually(session).Should(Exit(1))
   360  							})
   361  						})
   362  					})
   363  
   364  					When("path is a URL", func() {
   365  						When("specifying a valid URL", func() {
   366  							BeforeEach(func() {
   367  								buildpackPath = "https://github.com/cloudfoundry/binary-buildpack/releases/download/v1.0.21/binary-buildpack-v1.0.21.zip"
   368  							})
   369  
   370  							It("successfully uploads a buildpack", func() {
   371  								Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   372  								Eventually(session).Should(Say("OK"))
   373  								Eventually(session).Should(Say("Uploading buildpack %s as %s...", buildpackName, username))
   374  								Eventually(session).Should(Say("OK"))
   375  								Eventually(session).Should(Exit(0))
   376  							})
   377  						})
   378  
   379  						When("a 4xx or 5xx HTTP response status is encountered", func() {
   380  							var server *Server
   381  
   382  							BeforeEach(func() {
   383  								server = NewServer()
   384  								// Suppresses ginkgo server logs
   385  								server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
   386  								server.AppendHandlers(
   387  									CombineHandlers(
   388  										VerifyRequest(http.MethodGet, "/"),
   389  										RespondWith(http.StatusNotFound, nil),
   390  									),
   391  								)
   392  								buildpackPath = server.URL()
   393  							})
   394  
   395  							AfterEach(func() {
   396  								server.Close()
   397  							})
   398  
   399  							It("displays an appropriate error", func() {
   400  								Eventually(session.Err).Should(Say("Download attempt failed; server returned 404 Not Found"))
   401  								Eventually(session.Err).Should(Say(`Unable to install; buildpack is not available from the given URL\.`))
   402  								Eventually(session).Should(Say("FAILED"))
   403  								Eventually(session).Should(Exit(1))
   404  							})
   405  						})
   406  
   407  						When("specifying an invalid URL", func() {
   408  							BeforeEach(func() {
   409  								buildpackPath = "http://not-a-real-url"
   410  							})
   411  
   412  							It("returns the appropriate error", func() {
   413  								Eventually(session.Err).Should(Say("Get %s: dial tcp: lookup", buildpackPath))
   414  								Eventually(session).Should(Say("FAILED"))
   415  								Eventually(session).Should(Exit(1))
   416  							})
   417  						})
   418  					})
   419  				})
   420  
   421  				When("the -i flag is provided", func() {
   422  					// TODO: These are tests that require global integration scoping, break these into their own test and isolate the others
   423  					var (
   424  						buildpackPosition string
   425  						session           *Session
   426  					)
   427  
   428  					JustBeforeEach(func() {
   429  						session = helpers.CF("update-buildpack", buildpackName, "-i", buildpackPosition)
   430  					})
   431  
   432  					When("position is a negative integer", func() {
   433  						BeforeEach(func() {
   434  							buildpackPosition = "-3"
   435  						})
   436  
   437  						It("fails with error that position must be at least 1", func() {
   438  							Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   439  							Eventually(session.Err).Should(Say("Position must be greater than or equal to 1"))
   440  							Eventually(session).Should(Exit(1))
   441  						})
   442  					})
   443  
   444  					When("position is positive integer", func() {
   445  						BeforeEach(func() {
   446  							buildpackPosition = "3"
   447  						})
   448  
   449  						It("successfully uploads buildpack in the provided position", func() {
   450  							Eventually(session).Should(Exit(0))
   451  
   452  							listSession := helpers.CF("buildpacks")
   453  							Eventually(listSession).Should(Say(`\s+3\s+%s`, buildpackName))
   454  							Eventually(listSession).Should(Exit(0))
   455  						})
   456  					})
   457  				})
   458  
   459  				When("the --assign-stack flag is provided", func() {
   460  					var (
   461  						stacks []string
   462  					)
   463  
   464  					When("the user assigns a stack that exists on the system", func() {
   465  						BeforeEach(func() {
   466  							stacks = helpers.EnsureMinimumNumberOfStacks(2)
   467  						})
   468  
   469  						It("successfully assigns the stack to the buildpack", func() {
   470  							session := helpers.CF("update-buildpack", buildpackName, "--assign-stack", stacks[0])
   471  
   472  							Eventually(session).Should(Say("Assigning stack %s to %s as %s...", stacks[0], buildpackName, username))
   473  							Eventually(session).Should(Say("OK"))
   474  							Eventually(session).Should(Exit(0))
   475  
   476  							listSession := helpers.CF("buildpacks")
   477  							Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{
   478  								Name: buildpackName, Stack: stacks[0]})))
   479  							Eventually(listSession).Should(Exit(0))
   480  						})
   481  
   482  						When("the buildpack already has a stack associated to it", func() {
   483  							BeforeEach(func() {
   484  								assignStackSession := helpers.CF("update-buildpack", buildpackName, "--assign-stack", stacks[0])
   485  								Eventually(assignStackSession).Should(Exit(0))
   486  							})
   487  
   488  							It("displays an error that the buildpack already has a stack association", func() {
   489  								session := helpers.CF("update-buildpack", buildpackName, "--assign-stack", stacks[1])
   490  								Eventually(session.Err).Should(Say("Buildpack stack cannot be changed"))
   491  								Eventually(session).Should(Say("FAILED"))
   492  								Eventually(session).Should(Exit(1))
   493  							})
   494  						})
   495  					})
   496  
   497  					When("the user assigns a stack that does NOT exist on the system", func() {
   498  						It("displays an error that the stack isn't found", func() {
   499  							session := helpers.CF("update-buildpack", buildpackName, "--assign-stack", "nonexistent-stack")
   500  							Eventually(session.Err).Should(Say("Stack 'nonexistent-stack' does not exist"))
   501  							Eventually(session).Should(Say("FAILED"))
   502  							Eventually(session).Should(Exit(1))
   503  						})
   504  					})
   505  				})
   506  
   507  				When("the --lock is provided", func() {
   508  					It("locks the buildpack", func() {
   509  						session := helpers.CF("update-buildpack", buildpackName, "--lock")
   510  						Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   511  						Eventually(session).Should(Say("OK"))
   512  						Eventually(session).Should(Exit(0))
   513  
   514  						session = helpers.CF("buildpacks")
   515  						Eventually(session).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{
   516  							Name:   buildpackName,
   517  							Locked: "true",
   518  						})))
   519  						Eventually(session).Should(Exit(0))
   520  					})
   521  				})
   522  
   523  				When("the --disable is provided", func() {
   524  					It("disables buildpack", func() {
   525  						session := helpers.CF("update-buildpack", buildpackName, "--disable")
   526  						Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   527  						Eventually(session).Should(Say("OK"))
   528  						Eventually(session).Should(Exit(0))
   529  
   530  						session = helpers.CF("buildpacks")
   531  						Eventually(session).Should(Say(`%s\s+false`, buildpackName))
   532  						Eventually(session).Should(Exit(0))
   533  					})
   534  				})
   535  
   536  				When("the --rename flag is provided", func() {
   537  					var (
   538  						newBuildpackName string
   539  					)
   540  
   541  					BeforeEach(func() {
   542  						newBuildpackName = helpers.NewBuildpackName()
   543  					})
   544  
   545  					When("a buildpack with the new name does not already exist", func() {
   546  						It("renames the buildpack", func() {
   547  							session := helpers.CF("update-buildpack", buildpackName, "--rename", newBuildpackName)
   548  							Eventually(session).Should(Say("Renaming buildpack %s to %s as %s...", buildpackName, newBuildpackName, username))
   549  							Eventually(session).Should(Say("OK"))
   550  							Eventually(session).Should(Exit(0))
   551  
   552  							session = helpers.CF("buildpacks")
   553  							Eventually(session).Should(Say(`%s`, newBuildpackName))
   554  							Eventually(session).ShouldNot(Say(`%s`, buildpackName))
   555  							Eventually(session).Should(Exit(0))
   556  						})
   557  					})
   558  
   559  					When("a buildpack with the new name already exists", func() {
   560  						BeforeEach(func() {
   561  							helpers.BuildpackWithoutStack(func(buildpackArchive string) {
   562  								createSession := helpers.CF("create-buildpack", newBuildpackName, buildpackArchive, "99")
   563  								Eventually(createSession).Should(Exit(0))
   564  							})
   565  
   566  							listSession := helpers.CF("buildpacks")
   567  							Eventually(listSession).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{Name: newBuildpackName})))
   568  							Eventually(listSession).Should(Exit(0))
   569  						})
   570  
   571  						It("fails to rename the buildpack", func() {
   572  							session := helpers.CF("update-buildpack", buildpackName, "--rename", newBuildpackName)
   573  							Eventually(session.Err).Should(Say("Buildpack with name '%s' and an unassigned stack already exists", newBuildpackName))
   574  							Eventually(session).Should(Say("FAILED"))
   575  							Eventually(session).Should(Exit(1))
   576  						})
   577  					})
   578  				})
   579  			})
   580  
   581  			When("the buildpack exists and is disabled", func() {
   582  				BeforeEach(func() {
   583  					helpers.BuildpackWithoutStack(func(buildpackPath string) {
   584  						session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1", "--disable")
   585  						Eventually(session).Should(Exit(0))
   586  					})
   587  				})
   588  
   589  				When("specifying enable flag", func() {
   590  					It("enables buildpack", func() {
   591  						session := helpers.CF("update-buildpack", buildpackName, "--enable")
   592  						Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   593  						Eventually(session).Should(Say("OK"))
   594  						Eventually(session).Should(Exit(0))
   595  
   596  						session = helpers.CF("buildpacks")
   597  						Eventually(session).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{Name: buildpackName})))
   598  						Eventually(session).Should(Exit(0))
   599  					})
   600  				})
   601  			})
   602  
   603  			When("the buildpack exists and is locked", func() {
   604  				var buildpackURL string
   605  
   606  				BeforeEach(func() {
   607  					helpers.BuildpackWithoutStack(func(buildpackPath string) {
   608  						session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
   609  						Eventually(session).Should(Exit(0))
   610  						session = helpers.CF("update-buildpack", buildpackName, "--lock")
   611  						Eventually(session).Should(Exit(0))
   612  					})
   613  					buildpackURL = "https://github.com/cloudfoundry/binary-buildpack/releases/download/v1.0.21/binary-buildpack-v1.0.21.zip"
   614  				})
   615  
   616  				Context("specifying -p argument", func() {
   617  					It("fails to update buildpack", func() {
   618  						session := helpers.CF("update-buildpack", buildpackName, "-p", buildpackURL)
   619  						Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   620  						Eventually(session).Should(Say("FAILED"))
   621  						Eventually(session.Err).Should(Say("Buildpack is locked"))
   622  						Eventually(session).Should(Exit(1))
   623  					})
   624  				})
   625  
   626  				Context("specifying unlock flag", func() {
   627  					It("unlocks the buildpack", func() {
   628  						session := helpers.CF("update-buildpack", buildpackName, "--unlock")
   629  						Eventually(session).Should(Say("Updating buildpack %s as %s...", buildpackName, username))
   630  						Eventually(session).Should(Say("OK"))
   631  						Eventually(session).Should(Exit(0))
   632  
   633  						session = helpers.CF("buildpacks")
   634  						Eventually(session).Should(Say(helpers.BuildpacksOutputRegex(helpers.BuildpackFields{Name: buildpackName})))
   635  						Eventually(session).Should(Exit(0))
   636  					})
   637  				})
   638  			})
   639  		})
   640  	})
   641  })