github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/push/simple_manifest_only_test.go (about)

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