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