github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/push/buildpacks_test.go (about)

     1  package push
     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("buildpacks", func() {
    12  	var (
    13  		appName string
    14  	)
    15  
    16  	BeforeEach(func() {
    17  		appName = helpers.PrefixedRandomName("app")
    18  	})
    19  
    20  	When("the -b flag is provided", func() {
    21  		When("an existing application has a buildpack set", func() {
    22  			BeforeEach(func() {
    23  				helpers.WithHelloWorldApp(func(appDir string) {
    24  					Eventually(
    25  						helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
    26  							PushCommandName, appName,
    27  							"-b", "java_buildpack"),
    28  					).Should(Exit(1))
    29  				})
    30  			})
    31  
    32  			When("resetting the buildpack to autodetection", func() {
    33  				It("successfully pushes the app with -b default", func() {
    34  					helpers.WithHelloWorldApp(func(appDir string) {
    35  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
    36  							PushCommandName, appName,
    37  							"-b", "default",
    38  						)
    39  
    40  						Eventually(session).Should(Exit(0))
    41  
    42  						Expect(session).To(Say(`name:\s+%s`, appName))
    43  						Expect(session).To(Say(`requested state:\s+started`))
    44  						Expect(session).To(Say("buildpacks:"))
    45  						Expect(session).To(Say(`staticfile_buildpack\s+\d+.\d+.\d+`))
    46  					})
    47  				})
    48  
    49  				It("successfully pushes the app with -b null", func() {
    50  					helpers.WithHelloWorldApp(func(appDir string) {
    51  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
    52  							PushCommandName, appName,
    53  							"-b", "null",
    54  						)
    55  
    56  						Eventually(session).Should(Exit(0))
    57  
    58  						Expect(session).To(Say(`name:\s+%s`, appName))
    59  						Expect(session).To(Say(`requested state:\s+started`))
    60  						Expect(session).To(Say("buildpacks:"))
    61  						Expect(session).To(Say(`staticfile_buildpack\s+\d+.\d+.\d+`))
    62  					})
    63  				})
    64  			})
    65  
    66  			When("omitting the buildpack", func() {
    67  				It("continues using previously set buildpack", func() {
    68  					helpers.WithHelloWorldApp(func(appDir string) {
    69  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, PushCommandName, appName)
    70  
    71  						Eventually(session).Should(Exit(1))
    72  
    73  						Expect(session).To(Say("FAILED"))
    74  					})
    75  				})
    76  			})
    77  		})
    78  
    79  		When("the buildpack is invalid", func() {
    80  			It("errors and does not push the app", func() {
    81  				helpers.WithHelloWorldApp(func(appDir string) {
    82  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, PushCommandName, appName, "-b", "wut")
    83  
    84  					Eventually(session).Should(Exit(1))
    85  
    86  					Expect(session.Err).To(Say(`For application '%s': Specified unknown buildpack name: "wut"`, appName))
    87  					Expect(session).To(Say("FAILED"))
    88  				})
    89  			})
    90  		})
    91  
    92  		When("the buildpack is valid", func() {
    93  			When("the buildpack already exists", func() {
    94  				When("pushing a single buildpack", func() {
    95  					It("uses the specified buildpack", func() {
    96  						helpers.WithHelloWorldApp(func(appDir string) {
    97  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
    98  								PushCommandName, appName,
    99  								"-b", "staticfile_buildpack",
   100  							)
   101  
   102  							Eventually(session).Should(Exit(0))
   103  
   104  							Expect(session).To(Say(`name:\s+%s`, appName))
   105  							Expect(session).To(Say(`requested state:\s+started`))
   106  							Expect(session).To(Say("buildpacks:"))
   107  							Expect(session).To(Say(`staticfile_buildpack\s+\d+.\d+.\d+`))
   108  						})
   109  					})
   110  				})
   111  
   112  				When("pushing a multi-buildpack app", func() {
   113  					It("uses all the provided buildpacks in order", func() {
   114  						helpers.WithMultiBuildpackApp(func(appDir string) {
   115  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
   116  								PushCommandName, appName,
   117  								"-b", "ruby_buildpack",
   118  								"-b", "go_buildpack",
   119  							)
   120  
   121  							Eventually(session).Should(Exit(0))
   122  
   123  							Expect(session).To(Say("Ruby Buildpack"))
   124  							Expect(session).To(Say("Go Buildpack"))
   125  							Expect(session).To(Say(`name:\s+%s`, appName))
   126  							Expect(session).To(Say(`requested state:\s+started`))
   127  							Expect(session).To(Say("buildpacks:"))
   128  							Expect(session).To(Say(`ruby_buildpack\s+\d+.\d+.\d+`))
   129  							Expect(session).To(Say(`go_buildpack\s+\d+.\d+.\d+`))
   130  						})
   131  					})
   132  				})
   133  			})
   134  
   135  			When("the buildpack is a URL", func() {
   136  				It("uses the specified buildpack", func() {
   137  					helpers.WithHelloWorldApp(func(appDir string) {
   138  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir},
   139  							PushCommandName, appName,
   140  							"-b", "https://github.com/cloudfoundry/staticfile-buildpack",
   141  						)
   142  
   143  						Eventually(session).Should(Exit(0))
   144  
   145  						Expect(session).To(Say(`name:\s+%s`, appName))
   146  						Expect(session).To(Say(`requested state:\s+started`))
   147  						Expect(session).To(Say("buildpacks:"))
   148  						Expect(session).To(Say(`https://github.com/cloudfoundry/staticfile-buildpack\s+\d+.\d+.\d+`))
   149  					})
   150  				})
   151  			})
   152  		})
   153  	})
   154  })