github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+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/integration/helpers"
    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  	When("the app is new", func() {
    28  		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+(/private)?%s`, regexp.QuoteMeta(dir)))
    63  						Eventually(session).Should(Say(`(?m)\s+buildpacks:\s+\+\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, helpers.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  					time.Sleep(5 * time.Second)
    92  					session := helpers.CF("app", appName)
    93  					Eventually(session).Should(Say(`name:\s+%s`, appName))
    94  					Eventually(session).Should(Say(`last uploaded:\s+\w{3} \d{1,2} \w{3} \d{2}:\d{2}:\d{2} \w{3} \d{4}`))
    95  					Eventually(session).Should(Say(`stack:\s+cflinuxfs2`))
    96  					Eventually(session).Should(Say(`buildpacks:\s+staticfile`))
    97  					Eventually(session).Should(Say(`type:\s+web`))
    98  					Eventually(session).Should(Say(`instances:\s+2/2`))
    99  					Eventually(session).Should(Say(`memory usage:\s+70M`))
   100  					Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`))
   101  					Eventually(session).Should(Say(`#0\s+running\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   102  					Eventually(session).Should(Exit(0))
   103  
   104  					session = helpers.CF("env", appName)
   105  					Eventually(session).Should(Say(`key1:\s+val1`))
   106  					Eventually(session).Should(Say(`key2:\s+2`))
   107  					Eventually(session).Should(Say(`key3:\s+true`))
   108  					Eventually(session).Should(Say(`key4:\s+123412341234`))
   109  					Eventually(session).Should(Say(`key5:\s+12345.123`))
   110  					Eventually(session).Should(Exit(0))
   111  				})
   112  
   113  				When("health-check-type is http and no endpoint is provided", func() {
   114  					It("defaults health-check-http-endpoint to '/'", func() {
   115  						helpers.WithHelloWorldApp(func(dir string) {
   116  							helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   117  								"applications": []map[string]interface{}{
   118  									{
   119  										"name":              appName,
   120  										"path":              dir,
   121  										"health-check-type": "http",
   122  									},
   123  								},
   124  							})
   125  
   126  							session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   127  							Eventually(session).Should(Say(`Getting app info\.\.\.`))
   128  							Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
   129  							Eventually(session).Should(Say(`\+\s+name:\s+%s`, appName))
   130  							Eventually(session).Should(Say(`\s+health check http endpoint:\s+/`))
   131  							Eventually(session).Should(Say(`\s+health check type:\s+http`))
   132  							Eventually(session).Should(Say(`Mapping routes\.\.\.`))
   133  							Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   134  							Eventually(session).Should(Say(`requested state:\s+started`))
   135  							Eventually(session).Should(Exit(0))
   136  						})
   137  
   138  						session := helpers.CF("app", appName)
   139  						Eventually(session).Should(Exit(0))
   140  					})
   141  				})
   142  			})
   143  
   144  			When("the app has no name", func() {
   145  				It("returns an error", func() {
   146  					helpers.WithHelloWorldApp(func(dir string) {
   147  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   148  							"applications": []map[string]string{
   149  								{
   150  									"name": "",
   151  								},
   152  							},
   153  						})
   154  
   155  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   156  						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."))
   157  						Eventually(session).Should(Exit(1))
   158  					})
   159  				})
   160  			})
   161  
   162  			When("the app path does not exist", func() {
   163  				It("returns an error", func() {
   164  					helpers.WithHelloWorldApp(func(dir string) {
   165  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   166  							"applications": []map[string]string{
   167  								{
   168  									"name": "some-name",
   169  									"path": "does-not-exist",
   170  								},
   171  							},
   172  						})
   173  
   174  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   175  						Eventually(session.Err).Should(Say("File not found locally, make sure the file exists at given path .*does-not-exist"))
   176  						Eventually(session).Should(Exit(1))
   177  					})
   178  				})
   179  			})
   180  		})
   181  
   182  		Context("there is no name or no manifest", func() {
   183  			It("returns an error", func() {
   184  				helpers.WithHelloWorldApp(func(dir string) {
   185  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName)
   186  					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."))
   187  					Eventually(session).Should(Exit(1))
   188  				})
   189  			})
   190  		})
   191  	})
   192  
   193  	When("the app already exists", func() {
   194  		When("the app has manifest properties", func() {
   195  			BeforeEach(func() {
   196  				helpers.WithHelloWorldApp(func(dir string) {
   197  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   198  						"applications": []map[string]interface{}{
   199  							{
   200  								"name": appName,
   201  								"path": dir,
   202  								"env": map[string]interface{}{
   203  									"key1": "val10",
   204  									"key2": 2,
   205  									"key3": true,
   206  								},
   207  							},
   208  						},
   209  					})
   210  
   211  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   212  					Eventually(session).Should(Say(`\+\s+name:\s+%s`, appName))
   213  					Eventually(session).Should(Say(`\s+env:`))
   214  					Eventually(session).Should(Say(`\+\s+key1`))
   215  					Eventually(session).Should(Say(`\+\s+key2`))
   216  					Eventually(session).Should(Say(`\+\s+key3`))
   217  					Eventually(session).Should(Exit(0))
   218  				})
   219  			})
   220  
   221  			It("adds or overrides the original env values", func() {
   222  				helpers.WithHelloWorldApp(func(dir string) {
   223  					helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   224  						"applications": []map[string]interface{}{
   225  							{
   226  								"name": appName,
   227  								"path": dir,
   228  								"env": map[string]interface{}{
   229  									"key1": "val1",
   230  									"key4": false,
   231  								},
   232  							},
   233  						},
   234  					})
   235  
   236  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   237  					Eventually(session).Should(Say(`\s+name:\s+%s`, appName))
   238  					Eventually(session).Should(Say(`\s+env:`))
   239  					Eventually(session).Should(Say(`\-\s+key1`))
   240  					Eventually(session).Should(Say(`\+\s+key1`))
   241  					Eventually(session).Should(Say(`\s+key2`))
   242  					Eventually(session).Should(Say(`\s+key3`))
   243  					Eventually(session).Should(Say(`\+\s+key4`))
   244  					Eventually(session).Should(Exit(0))
   245  				})
   246  
   247  				session := helpers.CF("env", appName)
   248  				Eventually(session).Should(Say(`key1:\s+val1`))
   249  				Eventually(session).Should(Say(`key2:\s+2`))
   250  				Eventually(session).Should(Say(`key3:\s+true`))
   251  				Eventually(session).Should(Say(`key4:\s+false`))
   252  				Eventually(session).Should(Exit(0))
   253  			})
   254  		})
   255  	})
   256  })