github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/push/manifest_with_app_name_test.go (about) 1 package push 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 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 manifest and an app name", func() { 17 var ( 18 appName string 19 secondName string 20 tempDir string 21 pathToManifest string 22 ) 23 24 When("the inputs are valid", func() { 25 BeforeEach(func() { 26 appName = helpers.NewAppName() 27 secondName = helpers.NewAppName() 28 var err error 29 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 30 Expect(err).ToNot(HaveOccurred()) 31 pathToManifest = filepath.Join(tempDir, "manifest.yml") 32 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 33 "applications": []map[string]interface{}{ 34 { 35 "name": appName, 36 "env": map[string]interface{}{ 37 "key1": "val1", 38 "key4": false, 39 }, 40 }, 41 { 42 "name": secondName, 43 "env": map[string]interface{}{ 44 "key1": "val1", 45 "key4": false, 46 }, 47 }, 48 }, 49 }) 50 }) 51 52 AfterEach(func() { 53 Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred()) 54 }) 55 56 It("pushes only the specified app", func() { 57 helpers.WithHelloWorldApp(func(dir string) { 58 session := helpers.CustomCF( 59 helpers.CFEnv{WorkingDirectory: dir}, 60 PushCommandName, appName, 61 "-f", pathToManifest, 62 "--no-start") 63 Eventually(session).Should(Exit(0)) 64 }) 65 66 session := helpers.CF("env", appName) 67 Eventually(session).Should(Say(`key1:\s+val1`)) 68 Eventually(session).Should(Say(`key4:\s+false`)) 69 Eventually(session).Should(Exit(0)) 70 71 session = helpers.CF("env", secondName) 72 Eventually(session.Err).Should(Say(fmt.Sprintf("App '%s' not found", secondName))) 73 Eventually(session).Should(Exit(1)) 74 }) 75 76 When("tha app name is not in the manifest", func() { 77 It("errors", func() { 78 helpers.WithHelloWorldApp(func(dir string) { 79 session := helpers.CustomCF( 80 helpers.CFEnv{WorkingDirectory: dir}, 81 PushCommandName, "bad-app", 82 "-f", pathToManifest, 83 "--no-start") 84 Eventually(session.Err).Should(Say(`Could not find app named 'bad-app' in manifest`)) 85 Eventually(session).Should(Exit(1)) 86 }) 87 88 }) 89 }) 90 }) 91 92 When("an appName is not given with a nameless manifest", func() { 93 BeforeEach(func() { 94 var err error 95 tempDir, err = ioutil.TempDir("", "simple-manifest-test") 96 Expect(err).ToNot(HaveOccurred()) 97 pathToManifest = filepath.Join(tempDir, "manifest.yml") 98 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 99 "applications": []map[string]interface{}{ 100 { 101 "env": map[string]interface{}{ 102 "key1": "val1", 103 "key4": false, 104 }, 105 }, 106 }, 107 }) 108 }) 109 110 AfterEach(func() { 111 Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred()) 112 }) 113 114 It("errors with a helpful warning", func() { 115 helpers.WithHelloWorldApp(func(dir string) { 116 session := helpers.CustomCF( 117 helpers.CFEnv{WorkingDirectory: dir}, 118 PushCommandName, 119 "-f", pathToManifest, 120 "--no-start") 121 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.")) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 }) 126 })