github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/v7/push/simple_manifest_only_test.go (about) 1 package push 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/ginkgo/extensions/table" 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", func() { 17 var ( 18 appName string 19 ) 20 21 BeforeEach(func() { 22 appName = helpers.NewAppName() 23 }) 24 25 When("the manifest is in the current directory", func() { 26 It("uses the manifest", func() { 27 helpers.WithHelloWorldApp(func(dir string) { 28 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 29 "applications": []map[string]interface{}{ 30 { 31 "name": appName, 32 "env": map[string]interface{}{ 33 "key1": "val1", 34 "key4": false, 35 }, 36 }, 37 }, 38 }) 39 40 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 41 Eventually(session).Should(Exit(0)) 42 }) 43 44 session := helpers.CF("env", appName) 45 Eventually(session).Should(Say(`key1:\s+val1`)) 46 Eventually(session).Should(Say(`key4:\s+false`)) 47 Eventually(session).Should(Exit(0)) 48 }) 49 50 When("the --no-manifest flag is provided", func() { 51 It("ignores the manifest", func() { 52 helpers.WithHelloWorldApp(func(dir string) { 53 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 54 "applications": []map[string]interface{}{ 55 { 56 "name": appName, 57 "env": map[string]interface{}{ 58 "key1": "val1", 59 "key4": false, 60 }, 61 }, 62 }, 63 }) 64 65 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start", "--no-manifest") 66 Eventually(session).Should(Exit(0)) 67 }) 68 69 session := helpers.CF("env", appName) 70 Consistently(session).ShouldNot(Say(`key1:\s+val1`)) 71 Consistently(session).ShouldNot(Say(`key4:\s+false`)) 72 Eventually(session).Should(Exit(0)) 73 }) 74 DescribeTable("incompatible flags", 75 func(flag string, needsPath bool) { 76 helpers.WithHelloWorldApp(func(dir string) { 77 var path string 78 var session *Session 79 if needsPath { 80 path = filepath.Join(dir, "file.yml") 81 helpers.WriteManifest(path, map[string]interface{}{ 82 "applications": []map[string]interface{}{ 83 { 84 "name": appName, 85 }, 86 }, 87 }, 88 ) 89 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start", "--no-manifest", flag, path) 90 } else { 91 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start", "--no-manifest", flag) 92 } 93 Eventually(session).Should(Exit(1)) 94 }) 95 }, 96 Entry("--vars-file flag", "--vars-file", true), 97 Entry("-f flag", "-f", true), 98 Entry("--var flag", "--var=foo=bar", false), 99 ) 100 }) 101 }) 102 103 When("the manifest is provided via '-f' flag", func() { 104 var ( 105 tempDir string 106 pathToManifest string 107 ) 108 109 BeforeEach(func() { 110 var err error 111 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 112 Expect(err).ToNot(HaveOccurred()) 113 pathToManifest = filepath.Join(tempDir, "manifest.yml") 114 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 115 "applications": []map[string]interface{}{ 116 { 117 "name": appName, 118 "env": map[string]interface{}{ 119 "key1": "val1", 120 "key4": false, 121 }, 122 }, 123 }, 124 }) 125 }) 126 127 AfterEach(func() { 128 Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred()) 129 }) 130 131 It("uses the manifest", func() { 132 helpers.WithHelloWorldApp(func(dir string) { 133 session := helpers.CustomCF( 134 helpers.CFEnv{WorkingDirectory: dir}, 135 PushCommandName, appName, 136 "-f", pathToManifest, 137 "--no-start") 138 Eventually(session).Should(Exit(0)) 139 }) 140 141 session := helpers.CF("env", appName) 142 Eventually(session).Should(Say(`key1:\s+val1`)) 143 Eventually(session).Should(Say(`key4:\s+false`)) 144 Eventually(session).Should(Exit(0)) 145 }) 146 }) 147 148 When("A single --vars-file is specified", func() { 149 var ( 150 tempDir string 151 pathToManifest string 152 pathToVarsFile string 153 ) 154 155 BeforeEach(func() { 156 var err error 157 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 158 Expect(err).ToNot(HaveOccurred()) 159 pathToManifest = filepath.Join(tempDir, "manifest.yml") 160 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 161 "applications": []map[string]interface{}{ 162 { 163 "name": appName, 164 "env": map[string]interface{}{ 165 "key1": "((var1))", 166 "key4": false, 167 }, 168 }, 169 }, 170 }) 171 172 pathToVarsFile = filepath.Join(tempDir, "vars.yml") 173 helpers.WriteManifest(pathToVarsFile, map[string]interface{}{"var1": "secret-key"}) 174 }) 175 176 It("uses the manifest with substituted variables", func() { 177 helpers.WithHelloWorldApp(func(dir string) { 178 session := helpers.CustomCF( 179 helpers.CFEnv{WorkingDirectory: dir}, 180 PushCommandName, appName, 181 "-f", pathToManifest, 182 "--vars-file", pathToVarsFile, 183 "--no-start") 184 Eventually(session).Should(Exit(0)) 185 }) 186 187 session := helpers.CF("env", appName) 188 Eventually(session).Should(Say(`key1:\s+secret-key`)) 189 Eventually(session).Should(Say(`key4:\s+false`)) 190 Eventually(session).Should(Exit(0)) 191 }) 192 193 }) 194 195 When("A multiple --vars-file are specified", func() { 196 var ( 197 tempDir string 198 pathToManifest string 199 pathToVarsFile1 string 200 pathToVarsFile2 string 201 ) 202 203 BeforeEach(func() { 204 var err error 205 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 206 Expect(err).ToNot(HaveOccurred()) 207 pathToManifest = filepath.Join(tempDir, "manifest.yml") 208 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 209 "applications": []map[string]interface{}{ 210 { 211 "name": appName, 212 "env": map[string]interface{}{ 213 "key1": "((var1))", 214 "key4": "((var2))", 215 }, 216 }, 217 }, 218 }) 219 220 pathToVarsFile1 = filepath.Join(tempDir, "vars1.yml") 221 helpers.WriteManifest(pathToVarsFile1, map[string]interface{}{"var1": "not-so-secret-key", "var2": "foobar"}) 222 223 pathToVarsFile2 = filepath.Join(tempDir, "vars2.yml") 224 helpers.WriteManifest(pathToVarsFile2, map[string]interface{}{"var1": "secret-key"}) 225 }) 226 227 It("uses the manifest with substituted variables", func() { 228 helpers.WithHelloWorldApp(func(dir string) { 229 session := helpers.CustomCF( 230 helpers.CFEnv{WorkingDirectory: dir}, 231 PushCommandName, appName, 232 "-f", pathToManifest, 233 "--vars-file", pathToVarsFile1, 234 "--vars-file", pathToVarsFile2, 235 "--no-start") 236 Eventually(session).Should(Exit(0)) 237 }) 238 239 session := helpers.CF("env", appName) 240 Eventually(session).Should(Say(`key1:\s+secret-key`)) 241 Eventually(session).Should(Say(`key4:\s+foobar`)) 242 Eventually(session).Should(Exit(0)) 243 }) 244 245 }) 246 247 When("A manifest contains a variable not in the vars-file or --var", func() { 248 var ( 249 tempDir string 250 pathToManifest string 251 pathToVarsFile1 string 252 ) 253 254 BeforeEach(func() { 255 var err error 256 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 257 Expect(err).ToNot(HaveOccurred()) 258 pathToManifest = filepath.Join(tempDir, "manifest.yml") 259 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 260 "applications": []map[string]interface{}{ 261 { 262 "name": appName, 263 "env": map[string]interface{}{ 264 "key1": "((var1))", 265 "key4": "((var2))", 266 }, 267 }, 268 }, 269 }) 270 271 pathToVarsFile1 = filepath.Join(tempDir, "vars1.yml") 272 helpers.WriteManifest(pathToVarsFile1, map[string]interface{}{"var2": "foobar"}) 273 }) 274 275 It("It fails to push because of unfound variables", func() { 276 helpers.WithHelloWorldApp(func(dir string) { 277 session := helpers.CustomCF( 278 helpers.CFEnv{WorkingDirectory: dir}, 279 PushCommandName, appName, 280 "-f", pathToManifest, 281 "--vars-file", pathToVarsFile1, 282 "--var=not=here", 283 "--no-start") 284 Eventually(session).Should(Exit(1)) 285 Eventually(session.Err).Should(Say(`Expected to find variables: var1`)) 286 }) 287 }) 288 289 }) 290 291 When("A single --var is provided", func() { 292 293 var ( 294 tempDir string 295 pathToManifest string 296 ) 297 298 BeforeEach(func() { 299 var err error 300 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 301 Expect(err).ToNot(HaveOccurred()) 302 pathToManifest = filepath.Join(tempDir, "manifest.yml") 303 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 304 "applications": []map[string]interface{}{ 305 { 306 "name": appName, 307 "env": map[string]interface{}{ 308 "key1": "((var1))", 309 }, 310 }, 311 }, 312 }) 313 }) 314 315 It("uses the manifest with substituted variables", func() { 316 helpers.WithHelloWorldApp(func(dir string) { 317 session := helpers.CustomCF( 318 helpers.CFEnv{WorkingDirectory: dir}, 319 PushCommandName, appName, 320 "-f", pathToManifest, 321 "--var=var1=secret-key", 322 "--no-start") 323 Eventually(session).Should(Exit(0)) 324 }) 325 326 session := helpers.CF("env", appName) 327 Eventually(session).Should(Say(`key1:\s+secret-key`)) 328 Eventually(session).Should(Exit(0)) 329 }) 330 }) 331 332 When("Multiple --vars are provided", func() { 333 334 var ( 335 tempDir string 336 pathToManifest string 337 ) 338 339 BeforeEach(func() { 340 var err error 341 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 342 Expect(err).ToNot(HaveOccurred()) 343 pathToManifest = filepath.Join(tempDir, "manifest.yml") 344 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 345 "applications": []map[string]interface{}{ 346 { 347 "name": appName, 348 "env": map[string]interface{}{ 349 "key1": "((var1))", 350 "key4": "((var2))", 351 }, 352 }, 353 }, 354 }) 355 }) 356 357 It("uses the manifest with substituted variables", func() { 358 helpers.WithHelloWorldApp(func(dir string) { 359 session := helpers.CustomCF( 360 helpers.CFEnv{WorkingDirectory: dir}, 361 PushCommandName, appName, 362 "-f", pathToManifest, 363 "--var=var1=secret-key", "--var=var2=foobar", 364 "--no-start") 365 Eventually(session).Should(Exit(0)) 366 }) 367 368 session := helpers.CF("env", appName) 369 Eventually(session).Should(Say(`key1:\s+secret-key`)) 370 Eventually(session).Should(Say(`key4:\s+foobar`)) 371 Eventually(session).Should(Exit(0)) 372 }) 373 }) 374 375 })