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