github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/push/simple_manifest_only_test.go (about)

     1  package push
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"regexp"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("push with a simple manifest and no flags", func() {
    17  	var (
    18  		appName  string
    19  		username string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		appName = helpers.NewAppName()
    24  		username, _ = helpers.GetCredentials()
    25  	})
    26  
    27  	Context("when the app is new", func() {
    28  		Context("when the manifest is in the current directory", func() {
    29  			Context("with no global properties", func() {
    30  				It("uses the manifest for app settings", func() {
    31  					helpers.WithHelloWorldApp(func(dir string) {
    32  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    33  							"applications": []map[string]interface{}{
    34  								{
    35  									"name":       appName,
    36  									"path":       dir,
    37  									"command":    fmt.Sprintf("echo 'hi' && %s", helpers.StaticfileBuildpackStartCommand),
    38  									"buildpack":  "staticfile_buildpack",
    39  									"disk_quota": "300M",
    40  									"env": map[string]interface{}{
    41  										"key1": "val1",
    42  										"key2": 2,
    43  										"key3": true,
    44  										"key4": 123412341234,
    45  										"key5": 12345.123,
    46  									},
    47  									"instances":                  2,
    48  									"memory":                     "70M",
    49  									"stack":                      "cflinuxfs2",
    50  									"health-check-type":          "http",
    51  									"health-check-http-endpoint": "/",
    52  									"timeout":                    180,
    53  								},
    54  							},
    55  						})
    56  
    57  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
    58  						Eventually(session).Should(Say("Pushing from manifest to org %s / space %s as %s\\.\\.\\.", organization, space, username))
    59  						Eventually(session).Should(Say("Getting app info\\.\\.\\."))
    60  						Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
    61  						Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
    62  						Eventually(session).Should(Say("\\s+path:\\s+%s", regexp.QuoteMeta(dir)))
    63  						Eventually(session).Should(Say("\\s+buildpack:\\s+staticfile_buildpack"))
    64  						Eventually(session).Should(Say("\\s+command:\\s+echo 'hi' && %s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand)))
    65  						Eventually(session).Should(Say("\\s+disk quota:\\s+300M"))
    66  						Eventually(session).Should(Say("\\s+health check http endpoint:\\s+/"))
    67  						Eventually(session).Should(Say("\\s+health check timeout:\\s+180"))
    68  						Eventually(session).Should(Say("\\s+health check type:\\s+http"))
    69  						Eventually(session).Should(Say("\\s+instances:\\s+2"))
    70  						Eventually(session).Should(Say("\\s+memory:\\s+70M"))
    71  						Eventually(session).Should(Say("\\s+stack:\\s+cflinuxfs2"))
    72  						Eventually(session).Should(Say("\\s+env:"))
    73  						Eventually(session).Should(Say("\\+\\s+key1"))
    74  						Eventually(session).Should(Say("\\+\\s+key2"))
    75  						Eventually(session).Should(Say("\\+\\s+key3"))
    76  						Eventually(session).Should(Say("\\+\\s+key4"))
    77  						Eventually(session).Should(Say("\\+\\s+key5"))
    78  						Eventually(session).Should(Say("\\s+routes:"))
    79  						Eventually(session).Should(Say("(?i)\\+\\s+%s.%s", appName, defaultSharedDomain()))
    80  						Eventually(session).Should(Say("Mapping routes\\.\\.\\."))
    81  						Eventually(session).Should(Say("Uploading files\\.\\.\\."))
    82  						Eventually(session).Should(Say("100.00%"))
    83  						Eventually(session).Should(Say("Waiting for API to complete processing files\\.\\.\\."))
    84  						helpers.ConfirmStagingLogs(session)
    85  						Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
    86  						Eventually(session).Should(Say("requested state:\\s+started"))
    87  						Eventually(session).Should(Say("start command:\\s+echo 'hi' && %s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand)))
    88  						Eventually(session).Should(Exit(0))
    89  					})
    90  
    91  					session := helpers.CF("app", appName)
    92  					Eventually(session).Should(Say("name:\\s+%s", appName))
    93  					Eventually(session).Should(Say("instances:\\s+\\d/2"))
    94  					Eventually(session).Should(Say("usage:\\s+70M x 2"))
    95  					Eventually(session).Should(Say("stack:\\s+cflinuxfs2"))
    96  					Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
    97  					Eventually(session).Should(Say("#0.* of 70M"))
    98  					Eventually(session).Should(Exit(0))
    99  
   100  					session = helpers.CF("env", appName)
   101  					Eventually(session).Should(Say("key1:\\s+val1"))
   102  					Eventually(session).Should(Say("key2:\\s+2"))
   103  					Eventually(session).Should(Say("key3:\\s+true"))
   104  					Eventually(session).Should(Say("key4:\\s+123412341234"))
   105  					Eventually(session).Should(Say("key5:\\s+12345.123"))
   106  					Eventually(session).Should(Exit(0))
   107  				})
   108  
   109  				Context("when health-check-type is http and no endpoint is provided", func() {
   110  					It("defaults health-check-http-endpoint to '/'", func() {
   111  						helpers.WithHelloWorldApp(func(dir string) {
   112  							helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   113  								"applications": []map[string]interface{}{
   114  									{
   115  										"name":              appName,
   116  										"path":              dir,
   117  										"health-check-type": "http",
   118  									},
   119  								},
   120  							})
   121  
   122  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   123  							Eventually(session).Should(Say("Getting app info\\.\\.\\."))
   124  							Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\."))
   125  							Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
   126  							Eventually(session).Should(Say("\\s+health check http endpoint:\\s+/"))
   127  							Eventually(session).Should(Say("\\s+health check type:\\s+http"))
   128  							Eventually(session).Should(Say("Mapping routes\\.\\.\\."))
   129  							Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   130  							Eventually(session).Should(Say("requested state:\\s+started"))
   131  							Eventually(session).Should(Exit(0))
   132  						})
   133  
   134  						session := helpers.CF("app", appName)
   135  						Eventually(session).Should(Exit(0))
   136  					})
   137  				})
   138  			})
   139  
   140  			Context("when the app has no name", func() {
   141  				It("returns an error", func() {
   142  					helpers.WithHelloWorldApp(func(dir string) {
   143  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   144  							"applications": []map[string]string{
   145  								{
   146  									"name": "",
   147  								},
   148  							},
   149  						})
   150  
   151  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   152  						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."))
   153  						Eventually(session).Should(Exit(1))
   154  					})
   155  				})
   156  			})
   157  
   158  			Context("when the app path does not exist", func() {
   159  				It("returns an error", func() {
   160  					helpers.WithHelloWorldApp(func(dir string) {
   161  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   162  							"applications": []map[string]string{
   163  								{
   164  									"name": "some-name",
   165  									"path": "does-not-exist",
   166  								},
   167  							},
   168  						})
   169  
   170  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   171  						Eventually(session.Err).Should(Say("File not found locally, make sure the file exists at given path .*does-not-exist"))
   172  						Eventually(session).Should(Exit(1))
   173  					})
   174  				})
   175  			})
   176  		})
   177  
   178  		Context("there is no name or no manifest", func() {
   179  			It("returns an error", func() {
   180  				helpers.WithHelloWorldApp(func(dir string) {
   181  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   182  					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."))
   183  					Eventually(session).Should(Exit(1))
   184  				})
   185  			})
   186  		})
   187  	})
   188  
   189  	Context("when the app already exists", func() {
   190  		Context("when the app has manifest properties", func() {
   191  			BeforeEach(func() {
   192  				helpers.WithHelloWorldApp(func(dir string) {
   193  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   194  						"applications": []map[string]interface{}{
   195  							{
   196  								"name": appName,
   197  								"path": dir,
   198  								"env": map[string]interface{}{
   199  									"key1": "val10",
   200  									"key2": 2,
   201  									"key3": true,
   202  								},
   203  							},
   204  						},
   205  					})
   206  
   207  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   208  					Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName))
   209  					Eventually(session).Should(Say("\\s+env:"))
   210  					Eventually(session).Should(Say("\\+\\s+key1"))
   211  					Eventually(session).Should(Say("\\+\\s+key2"))
   212  					Eventually(session).Should(Say("\\+\\s+key3"))
   213  					Eventually(session).Should(Exit(0))
   214  				})
   215  			})
   216  
   217  			It("adds or overrides the original env values", func() {
   218  				helpers.WithHelloWorldApp(func(dir string) {
   219  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   220  						"applications": []map[string]interface{}{
   221  							{
   222  								"name": appName,
   223  								"path": dir,
   224  								"env": map[string]interface{}{
   225  									"key1": "val1",
   226  									"key4": false,
   227  								},
   228  							},
   229  						},
   230  					})
   231  
   232  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   233  					Eventually(session).Should(Say("\\s+name:\\s+%s", appName))
   234  					Eventually(session).Should(Say("\\s+env:"))
   235  					Eventually(session).Should(Say("\\-\\s+key1"))
   236  					Eventually(session).Should(Say("\\+\\s+key1"))
   237  					Eventually(session).Should(Say("\\s+key2"))
   238  					Eventually(session).Should(Say("\\s+key3"))
   239  					Eventually(session).Should(Say("\\+\\s+key4"))
   240  					Eventually(session).Should(Exit(0))
   241  				})
   242  
   243  				session := helpers.CF("env", appName)
   244  				Eventually(session).Should(Say("key1:\\s+val1"))
   245  				Eventually(session).Should(Say("key2:\\s+2"))
   246  				Eventually(session).Should(Say("key3:\\s+true"))
   247  				Eventually(session).Should(Say("key4:\\s+false"))
   248  				Eventually(session).Should(Exit(0))
   249  			})
   250  		})
   251  	})
   252  })