github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/push/combination_manifest_and_flag_test.go (about) 1 package push 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "regexp" 8 9 "github.com/liamawhite/cli-with-i18n/integration/helpers" 10 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 flags", func() { 18 var ( 19 appName string 20 pathToManifest string 21 ) 22 23 BeforeEach(func() { 24 appName = helpers.NewAppName() 25 26 tmpFile, err := ioutil.TempFile("", "combination-manifest") 27 Expect(err).ToNot(HaveOccurred()) 28 pathToManifest = tmpFile.Name() 29 Expect(tmpFile.Close()).ToNot(HaveOccurred()) 30 }) 31 32 AfterEach(func() { 33 Expect(os.RemoveAll(pathToManifest)).ToNot(HaveOccurred()) 34 }) 35 36 Context("when the app is new", func() { 37 Context("when pushing a single app from the manifest", func() { 38 Context("when the manifest is passed via '-f'", func() { 39 Context("when pushing the app from the current directory", func() { 40 BeforeEach(func() { 41 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 42 "applications": []map[string]string{ 43 { 44 "name": appName, 45 }, 46 }, 47 }) 48 }) 49 50 It("pushes the app from the current directory and the manifest for app settings", func() { 51 helpers.WithHelloWorldApp(func(dir string) { 52 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "-f", pathToManifest) 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+routes:")) 57 Eventually(session).Should(Say("(?i)\\+\\s+%s.%s", appName, defaultSharedDomain())) 58 Eventually(session).Should(Say("Mapping routes\\.\\.\\.")) 59 Eventually(session).Should(Say("Uploading files\\.\\.\\.")) 60 Eventually(session).Should(Say("100.00%")) 61 Eventually(session).Should(Say("Waiting for API to complete processing files\\.\\.\\.")) 62 helpers.ConfirmStagingLogs(session) 63 Eventually(session).Should(Say("Waiting for app to start\\.\\.\\.")) 64 Eventually(session).Should(Say("requested state:\\s+started")) 65 Eventually(session).Should(Exit(0)) 66 }) 67 68 session := helpers.CF("app", appName) 69 Eventually(session).Should(Say("name:\\s+%s", appName)) 70 Eventually(session).Should(Exit(0)) 71 }) 72 }) 73 74 Context("when the path to the application is provided in the manifest", func() { 75 It("pushes the app from the path specified in the manifest and uses the manifest for app settings", func() { 76 helpers.WithHelloWorldApp(func(dir string) { 77 helpers.WriteManifest(pathToManifest, map[string]interface{}{ 78 "applications": []map[string]string{ 79 { 80 "name": appName, 81 "path": filepath.Base(dir), 82 }, 83 }, 84 }) 85 86 session := helpers.CF(PushCommandName, "-f", pathToManifest) 87 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 88 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 89 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName)) 90 Eventually(session).Should(Say("\\s+path:\\s+%s", regexp.QuoteMeta(dir))) 91 Eventually(session).Should(Say("requested state:\\s+started")) 92 Eventually(session).Should(Exit(0)) 93 }) 94 95 session := helpers.CF("app", appName) 96 Eventually(session).Should(Say("name:\\s+%s", appName)) 97 Eventually(session).Should(Exit(0)) 98 }) 99 }) 100 }) 101 102 Context("manifest contains a path and a '-p' is provided", func() { 103 var tempDir string 104 105 BeforeEach(func() { 106 var err error 107 tempDir, err = ioutil.TempDir("", "combination-manifest-with-p") 108 Expect(err).ToNot(HaveOccurred()) 109 110 helpers.WriteManifest(filepath.Join(tempDir, "manifest.yml"), map[string]interface{}{ 111 "applications": []map[string]string{ 112 { 113 "name": appName, 114 "path": "does-not-exist", 115 }, 116 }, 117 }) 118 }) 119 120 AfterEach(func() { 121 Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred()) 122 }) 123 124 It("overrides the manifest path with the '-p' path", func() { 125 helpers.WithHelloWorldApp(func(dir string) { 126 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: tempDir}, PushCommandName, "-p", dir) 127 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName)) 128 Eventually(session).Should(Say("\\s+path:\\s+%s", regexp.QuoteMeta(dir))) 129 Eventually(session).Should(Say("requested state:\\s+started")) 130 Eventually(session).Should(Exit(0)) 131 }) 132 133 session := helpers.CF("app", appName) 134 Eventually(session).Should(Say("name:\\s+%s", appName)) 135 Eventually(session).Should(Exit(0)) 136 }) 137 }) 138 139 Context("manifest contains a name and a name is provided", func() { 140 It("overrides the manifest name", func() { 141 helpers.WithHelloWorldApp(func(dir string) { 142 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 143 "applications": []map[string]string{ 144 { 145 "name": "earle", 146 }, 147 }, 148 }) 149 150 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 151 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName)) 152 Eventually(session).Should(Say("requested state:\\s+started")) 153 Eventually(session).Should(Exit(0)) 154 }) 155 156 session := helpers.CF("app", appName) 157 Eventually(session).Should(Say("name:\\s+%s", appName)) 158 Eventually(session).Should(Exit(0)) 159 }) 160 }) 161 162 Context("when the --no-manifest flag is passed", func() { 163 It("does not use the provided manifest", func() { 164 helpers.WithHelloWorldApp(func(dir string) { 165 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 166 "applications": []map[string]string{ 167 { 168 "name": "crazy-jerry", 169 }, 170 }, 171 }) 172 173 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-manifest", appName) 174 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 175 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 176 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", appName)) 177 Eventually(session).Should(Say("\\s+routes:")) 178 Eventually(session).Should(Say("(?i)\\+\\s+%s.%s", appName, defaultSharedDomain())) 179 Eventually(session).Should(Say("Mapping routes\\.\\.\\.")) 180 Eventually(session).Should(Say("Uploading files\\.\\.\\.")) 181 Eventually(session).Should(Say("100.00%")) 182 Eventually(session).Should(Say("Waiting for API to complete processing files\\.\\.\\.")) 183 helpers.ConfirmStagingLogs(session) 184 Eventually(session).Should(Say("Waiting for app to start\\.\\.\\.")) 185 Eventually(session).Should(Say("requested state:\\s+started")) 186 Eventually(session).Should(Exit(0)) 187 }) 188 189 session := helpers.CF("app", appName) 190 Eventually(session.Out).Should(Say("name:\\s+%s", appName)) 191 Eventually(session).Should(Exit(0)) 192 }) 193 }) 194 }) 195 196 Context("when pushing multiple apps from the manifest", func() { 197 Context("manifest contains multiple apps and a '-p' is provided", func() { 198 var tempDir string 199 200 BeforeEach(func() { 201 var err error 202 tempDir, err = ioutil.TempDir("", "combination-manifest-with-p") 203 Expect(err).ToNot(HaveOccurred()) 204 205 helpers.WriteManifest(filepath.Join(tempDir, "manifest.yml"), map[string]interface{}{ 206 "applications": []map[string]string{ 207 { 208 "name": "name-1", 209 }, 210 { 211 "name": "name-2", 212 }, 213 }, 214 }) 215 }) 216 217 AfterEach(func() { 218 Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred()) 219 }) 220 221 It("returns an error", func() { 222 helpers.WithHelloWorldApp(func(dir string) { 223 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: tempDir}, PushCommandName, "-p", dir) 224 Eventually(session.Err).Should(Say("Incorrect Usage: Command line flags \\(except -f\\) cannot be applied when pushing multiple apps from a manifest file\\.")) 225 Eventually(session).Should(Exit(1)) 226 }) 227 }) 228 }) 229 230 Context("manifest contains multiple apps and '--no-start' is provided", func() { 231 var appName1, appName2 string 232 233 BeforeEach(func() { 234 appName1 = helpers.NewAppName() 235 appName2 = helpers.NewAppName() 236 }) 237 238 It("does not start the apps", func() { 239 helpers.WithHelloWorldApp(func(dir string) { 240 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 241 "applications": []map[string]string{ 242 {"name": appName1}, 243 {"name": appName2}, 244 }, 245 }) 246 247 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 248 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 249 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 250 Eventually(session).Should(Say("\\s+name:\\s+%s", appName1)) 251 Eventually(session).Should(Say("requested state:\\s+stopped")) 252 Eventually(session).Should(Say("\\s+name:\\s+%s", appName2)) 253 Eventually(session).Should(Say("requested state:\\s+stopped")) 254 Eventually(session).Should(Exit(0)) 255 }) 256 }) 257 }) 258 }) 259 }) 260 })