github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/integration/v6/push/simple_manifest_only_test.go (about)

     1  package push
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"regexp"
     7  	"time"
     8  
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
    10  	"code.cloudfoundry.org/cli/integration/helpers"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  	. "github.com/onsi/gomega/gbytes"
    15  	. "github.com/onsi/gomega/gexec"
    16  )
    17  
    18  var _ = Describe("push with a simple manifest and no flags", func() {
    19  	var (
    20  		appName  string
    21  		username string
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		appName = helpers.NewAppName()
    26  		username, _ = helpers.GetCredentials()
    27  	})
    28  
    29  	When("the app is new", func() {
    30  		When("the manifest is in the current directory", func() {
    31  			Context("with no global properties", func() {
    32  				When("the API version is below 3.27.0", func() {
    33  					BeforeEach(func() {
    34  						helpers.SkipIfVersionAtLeast(ccversion.MinVersionApplicationFlowV3)
    35  					})
    36  
    37  					It("uses the manifest for app settings", func() {
    38  						helpers.WithHelloWorldApp(func(dir string) {
    39  							helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    40  								"applications": []map[string]interface{}{
    41  									{
    42  										"name":       appName,
    43  										"path":       dir,
    44  										"command":    fmt.Sprintf("echo 'hi' && %s", helpers.StaticfileBuildpackStartCommand),
    45  										"buildpack":  "staticfile_buildpack",
    46  										"disk_quota": "300M",
    47  										"env": map[string]interface{}{
    48  											"key1": "val1",
    49  											"key2": 2,
    50  											"key3": true,
    51  											"key4": 123412341234,
    52  											"key5": 12345.123,
    53  										},
    54  										"instances":                  2,
    55  										"memory":                     "70M",
    56  										"stack":                      "cflinuxfs2",
    57  										"health-check-type":          "http",
    58  										"health-check-http-endpoint": "/",
    59  										"timeout":                    180,
    60  									},
    61  								},
    62  							})
    63  
    64  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
    65  							Eventually(session).Should(Say("Pushing from manifest to org %s / space %s as %s\\.\\.\\.", organization, space, username))
    66  							Eventually(session).Should(Say("Getting app info\\.\\.\\."))
    67  							Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
    68  							Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
    69  							Eventually(session).Should(Say("\\s+path:\\s+%s", regexp.QuoteMeta(dir)))
    70  							Eventually(session).Should(Say("(?m)\\s+buildpacks:\\s+\\+\\s+staticfile_buildpack"))
    71  							Eventually(session).Should(Say("\\s+command:\\s+echo 'hi' && %s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand)))
    72  							Eventually(session).Should(Say("\\s+disk quota:\\s+300M"))
    73  							Eventually(session).Should(Say("\\s+health check http endpoint:\\s+/"))
    74  							Eventually(session).Should(Say("\\s+health check timeout:\\s+180"))
    75  							Eventually(session).Should(Say("\\s+health check type:\\s+http"))
    76  							Eventually(session).Should(Say("\\s+instances:\\s+2"))
    77  							Eventually(session).Should(Say("\\s+memory:\\s+70M"))
    78  							Eventually(session).Should(Say("\\s+stack:\\s+cflinuxfs2"))
    79  							Eventually(session).Should(Say("\\s+env:"))
    80  							Eventually(session).Should(Say("\\+\\s+key1"))
    81  							Eventually(session).Should(Say("\\+\\s+key2"))
    82  							Eventually(session).Should(Say("\\+\\s+key3"))
    83  							Eventually(session).Should(Say("\\+\\s+key4"))
    84  							Eventually(session).Should(Say("\\+\\s+key5"))
    85  							Eventually(session).Should(Say("\\s+routes:"))
    86  							Eventually(session).Should(Say("(?i)\\+\\s+%s.%s", appName, helpers.DefaultSharedDomain()))
    87  							Eventually(session).Should(Say("Mapping routes\\.\\.\\."))
    88  							Eventually(session).Should(Say("Uploading files\\.\\.\\."))
    89  							Eventually(session).Should(Say("100.00%"))
    90  							Eventually(session).Should(Say("Waiting for API to complete processing files\\.\\.\\."))
    91  							helpers.ConfirmStagingLogs(session)
    92  							Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
    93  							Eventually(session).Should(Say("requested state:\\s+started"))
    94  							Eventually(session).Should(Say("start command:\\s+echo 'hi' && %s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand)))
    95  							Eventually(session).Should(Exit(0))
    96  						})
    97  
    98  						session := helpers.CF("app", appName)
    99  						Eventually(session).Should(Say("name:\\s+%s", appName))
   100  						Eventually(session).Should(Say("instances:\\s+\\d/2"))
   101  						Eventually(session).Should(Say("usage:\\s+70M x 2"))
   102  						Eventually(session).Should(Say("stack:\\s+cflinuxfs2"))
   103  						Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   104  						Eventually(session).Should(Say("#0.* of 70M"))
   105  						Eventually(session).Should(Exit(0))
   106  
   107  						session = helpers.CF("env", appName)
   108  						Eventually(session).Should(Say("key1:\\s+val1"))
   109  						Eventually(session).Should(Say("key2:\\s+2"))
   110  						Eventually(session).Should(Say("key3:\\s+true"))
   111  						Eventually(session).Should(Say("key4:\\s+123412341234"))
   112  						Eventually(session).Should(Say("key5:\\s+12345.123"))
   113  						Eventually(session).Should(Exit(0))
   114  					})
   115  
   116  				})
   117  
   118  				When("the API version is above 3.27.0", func() {
   119  					BeforeEach(func() {
   120  						helpers.SkipIfVersionLessThan(ccversion.MinVersionApplicationFlowV3)
   121  					})
   122  
   123  					It("uses the manifest for app settings", func() {
   124  						helpers.WithHelloWorldApp(func(dir string) {
   125  							helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   126  								"applications": []map[string]interface{}{
   127  									{
   128  										"name":       appName,
   129  										"path":       dir,
   130  										"command":    fmt.Sprintf("echo 'hi' && %s", helpers.StaticfileBuildpackStartCommand),
   131  										"buildpack":  "staticfile_buildpack",
   132  										"disk_quota": "300M",
   133  										"env": map[string]interface{}{
   134  											"key1": "val1",
   135  											"key2": 2,
   136  											"key3": true,
   137  											"key4": 123412341234,
   138  											"key5": 12345.123,
   139  										},
   140  										"instances":                  2,
   141  										"memory":                     "70M",
   142  										"stack":                      "cflinuxfs2",
   143  										"health-check-type":          "http",
   144  										"health-check-http-endpoint": "/",
   145  										"timeout":                    180,
   146  									},
   147  								},
   148  							})
   149  
   150  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   151  							Eventually(session).Should(Say("Pushing from manifest to org %s / space %s as %s\\.\\.\\.", organization, space, username))
   152  							Eventually(session).Should(Say("Getting app info\\.\\.\\."))
   153  							Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
   154  							Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
   155  							Eventually(session).Should(Say("\\s+path:\\s+(/private)?%s", regexp.QuoteMeta(dir)))
   156  							Eventually(session).Should(Say("(?m)\\s+buildpacks:\\s+\\+\\s+staticfile_buildpack"))
   157  							Eventually(session).Should(Say("\\s+command:\\s+echo 'hi' && %s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand)))
   158  							Eventually(session).Should(Say("\\s+disk quota:\\s+300M"))
   159  							Eventually(session).Should(Say("\\s+health check http endpoint:\\s+/"))
   160  							Eventually(session).Should(Say("\\s+health check timeout:\\s+180"))
   161  							Eventually(session).Should(Say("\\s+health check type:\\s+http"))
   162  							Eventually(session).Should(Say("\\s+instances:\\s+2"))
   163  							Eventually(session).Should(Say("\\s+memory:\\s+70M"))
   164  							Eventually(session).Should(Say("\\s+stack:\\s+cflinuxfs2"))
   165  							Eventually(session).Should(Say("\\s+env:"))
   166  							Eventually(session).Should(Say("\\+\\s+key1"))
   167  							Eventually(session).Should(Say("\\+\\s+key2"))
   168  							Eventually(session).Should(Say("\\+\\s+key3"))
   169  							Eventually(session).Should(Say("\\+\\s+key4"))
   170  							Eventually(session).Should(Say("\\+\\s+key5"))
   171  							Eventually(session).Should(Say("\\s+routes:"))
   172  							Eventually(session).Should(Say("(?i)\\+\\s+%s.%s", appName, helpers.DefaultSharedDomain()))
   173  							Eventually(session).Should(Say("Mapping routes\\.\\.\\."))
   174  							Eventually(session).Should(Say("Uploading files\\.\\.\\."))
   175  							Eventually(session).Should(Say("100.00%"))
   176  							Eventually(session).Should(Say("Waiting for API to complete processing files\\.\\.\\."))
   177  							helpers.ConfirmStagingLogs(session)
   178  							Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   179  							Eventually(session).Should(Say("requested state:\\s+started"))
   180  							Eventually(session).Should(Say("start command:\\s+echo 'hi' && %s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand)))
   181  							Eventually(session).Should(Exit(0))
   182  						})
   183  
   184  						time.Sleep(5 * time.Second)
   185  						session := helpers.CF("app", appName)
   186  						Eventually(session).Should(Say("name:\\s+%s", appName))
   187  						Eventually(session).Should(Say("last uploaded:\\s+\\w{3} \\d{1,2} \\w{3} \\d{2}:\\d{2}:\\d{2} \\w{3} \\d{4}"))
   188  						Eventually(session).Should(Say("stack:\\s+cflinuxfs2"))
   189  						Eventually(session).Should(Say("buildpacks:\\s+staticfile"))
   190  						Eventually(session).Should(Say("type:\\s+web"))
   191  						Eventually(session).Should(Say("instances:\\s+2/2"))
   192  						Eventually(session).Should(Say("memory usage:\\s+70M"))
   193  						Eventually(session).Should(Say("\\s+state\\s+since\\s+cpu\\s+memory\\s+disk"))
   194  						Eventually(session).Should(Say("#0\\s+running\\s+\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z"))
   195  						Eventually(session).Should(Exit(0))
   196  
   197  						session = helpers.CF("env", appName)
   198  						Eventually(session).Should(Say("key1:\\s+val1"))
   199  						Eventually(session).Should(Say("key2:\\s+2"))
   200  						Eventually(session).Should(Say("key3:\\s+true"))
   201  						Eventually(session).Should(Say("key4:\\s+123412341234"))
   202  						Eventually(session).Should(Say("key5:\\s+12345.123"))
   203  						Eventually(session).Should(Exit(0))
   204  					})
   205  
   206  				})
   207  
   208  				When("health-check-type is http and no endpoint is provided", func() {
   209  					It("defaults health-check-http-endpoint to '/'", func() {
   210  						helpers.WithHelloWorldApp(func(dir string) {
   211  							helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   212  								"applications": []map[string]interface{}{
   213  									{
   214  										"name":              appName,
   215  										"path":              dir,
   216  										"health-check-type": "http",
   217  									},
   218  								},
   219  							})
   220  
   221  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   222  							Eventually(session).Should(Say("Getting app info\\.\\.\\."))
   223  							Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
   224  							Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
   225  							Eventually(session).Should(Say("\\s+health check http endpoint:\\s+/"))
   226  							Eventually(session).Should(Say("\\s+health check type:\\s+http"))
   227  							Eventually(session).Should(Say("Mapping routes\\.\\.\\."))
   228  							Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   229  							Eventually(session).Should(Say("requested state:\\s+started"))
   230  							Eventually(session).Should(Exit(0))
   231  						})
   232  
   233  						session := helpers.CF("app", appName)
   234  						Eventually(session).Should(Exit(0))
   235  					})
   236  				})
   237  			})
   238  
   239  			When("the app has no name", func() {
   240  				It("returns an error", func() {
   241  					helpers.WithHelloWorldApp(func(dir string) {
   242  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   243  							"applications": []map[string]string{
   244  								{
   245  									"name": "",
   246  								},
   247  							},
   248  						})
   249  
   250  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   251  						Eventually(session.Err).Should(Say("Incorrect usage: The push command requires an app name. The app name can be supplied as an argument or with a manifest.yml file."))
   252  						Eventually(session).Should(Exit(1))
   253  					})
   254  				})
   255  			})
   256  
   257  			When("the app path does not exist", func() {
   258  				It("returns an error", func() {
   259  					helpers.WithHelloWorldApp(func(dir string) {
   260  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   261  							"applications": []map[string]string{
   262  								{
   263  									"name": "some-name",
   264  									"path": "does-not-exist",
   265  								},
   266  							},
   267  						})
   268  
   269  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   270  						Eventually(session.Err).Should(Say("File not found locally, make sure the file exists at given path .*does-not-exist"))
   271  						Eventually(session).Should(Exit(1))
   272  					})
   273  				})
   274  			})
   275  		})
   276  
   277  		Context("there is no name or no manifest", func() {
   278  			It("returns an error", func() {
   279  				helpers.WithHelloWorldApp(func(dir string) {
   280  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   281  					Eventually(session.Err).Should(Say("Incorrect usage: The push command requires an app name. The app name can be supplied as an argument or with a manifest.yml file."))
   282  					Eventually(session).Should(Exit(1))
   283  				})
   284  			})
   285  		})
   286  	})
   287  
   288  	When("the app already exists", func() {
   289  		When("the app has manifest properties", func() {
   290  			BeforeEach(func() {
   291  				helpers.WithHelloWorldApp(func(dir string) {
   292  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   293  						"applications": []map[string]interface{}{
   294  							{
   295  								"name": appName,
   296  								"path": dir,
   297  								"env": map[string]interface{}{
   298  									"key1": "val10",
   299  									"key2": 2,
   300  									"key3": true,
   301  								},
   302  							},
   303  						},
   304  					})
   305  
   306  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   307  					Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
   308  					Eventually(session).Should(Say("\\s+env:"))
   309  					Eventually(session).Should(Say("\\+\\s+key1"))
   310  					Eventually(session).Should(Say("\\+\\s+key2"))
   311  					Eventually(session).Should(Say("\\+\\s+key3"))
   312  					Eventually(session).Should(Exit(0))
   313  				})
   314  			})
   315  
   316  			It("adds or overrides the original env values", func() {
   317  				helpers.WithHelloWorldApp(func(dir string) {
   318  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   319  						"applications": []map[string]interface{}{
   320  							{
   321  								"name": appName,
   322  								"path": dir,
   323  								"env": map[string]interface{}{
   324  									"key1": "val1",
   325  									"key4": false,
   326  								},
   327  							},
   328  						},
   329  					})
   330  
   331  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   332  					Eventually(session).Should(Say("\\s+name:\\s+%s", appName))
   333  					Eventually(session).Should(Say("\\s+env:"))
   334  					Eventually(session).Should(Say("\\-\\s+key1"))
   335  					Eventually(session).Should(Say("\\+\\s+key1"))
   336  					Eventually(session).Should(Say("\\s+key2"))
   337  					Eventually(session).Should(Say("\\s+key3"))
   338  					Eventually(session).Should(Say("\\+\\s+key4"))
   339  					Eventually(session).Should(Exit(0))
   340  				})
   341  
   342  				session := helpers.CF("env", appName)
   343  				Eventually(session).Should(Say("key1:\\s+val1"))
   344  				Eventually(session).Should(Say("key2:\\s+2"))
   345  				Eventually(session).Should(Say("key3:\\s+true"))
   346  				Eventually(session).Should(Say("key4:\\s+false"))
   347  				Eventually(session).Should(Exit(0))
   348  			})
   349  		})
   350  	})
   351  })