github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/integration/v7/isolated/copy_source_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 8 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 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("copy-source command", func() { 17 var ( 18 sourceAppName string 19 targetAppName string 20 orgName string 21 secondOrgName string 22 spaceName string 23 secondSpaceName string 24 ) 25 26 Describe("help", func() { 27 When("--help flag is set", func() { 28 It("appears in cf help -a", func() { 29 session := helpers.CF("help", "-a") 30 Eventually(session).Should(Exit(0)) 31 Expect(session).To(HaveCommandInCategoryWithDescription("copy-source", "APPS", "Copies the source code of an application to another existing application and restages that application")) 32 }) 33 34 It("Displays command usage to output", func() { 35 session := helpers.CF("copy-source", "--help") 36 helpText(session) 37 Eventually(session).Should(Exit(0)) 38 }) 39 }) 40 }) 41 42 Describe("command behavior without flags", func() { 43 BeforeEach(func() { 44 orgName = helpers.NewOrgName() 45 spaceName = helpers.NewSpaceName() 46 47 helpers.SetupCF(orgName, spaceName) 48 49 sourceAppName = helpers.PrefixedRandomName("hello") 50 targetAppName = helpers.PrefixedRandomName("banana") 51 52 helpers.WithHelloWorldApp(func(appDir string) { 53 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 54 }) 55 56 helpers.WithBananaPantsApp(func(appDir string) { 57 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 58 }) 59 }) 60 61 AfterEach(func() { 62 helpers.QuickDeleteOrg(orgName) 63 }) 64 65 It("copies the app", func() { 66 username, _ := helpers.GetCredentials() 67 session := helpers.CF("copy-source", sourceAppName, targetAppName) 68 Eventually(session).Should(Say("Copying source from app %s to target app %s", sourceAppName, targetAppName)) 69 Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) 70 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) 71 Eventually(session).Should(Exit(0)) 72 73 resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) 74 Expect(err).ToNot(HaveOccurred()) 75 defer resp.Body.Close() 76 body, err := ioutil.ReadAll(resp.Body) 77 Expect(err).ToNot(HaveOccurred()) 78 Expect(string(body)).To(MatchRegexp("hello world")) 79 }) 80 }) 81 82 Describe("command behavior when source app has no packages", func() { 83 BeforeEach(func() { 84 orgName = helpers.NewOrgName() 85 spaceName = helpers.NewSpaceName() 86 87 helpers.SetupCF(orgName, spaceName) 88 89 sourceAppName = helpers.PrefixedRandomName("hello") 90 targetAppName = helpers.PrefixedRandomName("banana") 91 92 helpers.CF("create-app", sourceAppName) 93 94 helpers.WithBananaPantsApp(func(appDir string) { 95 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 96 }) 97 }) 98 99 AfterEach(func() { 100 helpers.QuickDeleteOrg(orgName) 101 }) 102 103 It("errors", func() { 104 session := helpers.CF("copy-source", sourceAppName, targetAppName) 105 Eventually(session).Should(Say("Copying source from app %s to target app %s", sourceAppName, targetAppName)) 106 Eventually(session.Err).Should(Say(`App '%s' has no eligible packages\.`, sourceAppName)) 107 Eventually(session).Should(Exit(1)) 108 }) 109 }) 110 111 Describe("command behavior with a space flag", func() { 112 BeforeEach(func() { 113 orgName = helpers.NewOrgName() 114 spaceName = helpers.NewSpaceName() 115 secondSpaceName = helpers.NewSpaceName() 116 117 helpers.SetupCF(orgName, spaceName) 118 119 sourceAppName = helpers.PrefixedRandomName("hello") 120 targetAppName = helpers.PrefixedRandomName("banana") 121 122 helpers.WithHelloWorldApp(func(appDir string) { 123 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 124 }) 125 126 helpers.CreateSpace(secondSpaceName) 127 helpers.TargetOrgAndSpace(orgName, secondSpaceName) 128 129 helpers.WithBananaPantsApp(func(appDir string) { 130 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 131 }) 132 helpers.TargetOrgAndSpace(orgName, spaceName) 133 }) 134 135 AfterEach(func() { 136 helpers.QuickDeleteOrg(orgName) 137 }) 138 139 It("copies the app to the provided space", func() { 140 username, _ := helpers.GetCredentials() 141 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--space", secondSpaceName) 142 Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, secondSpaceName, username)) 143 Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, secondSpaceName, username)) 144 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s...", targetAppName, orgName, secondSpaceName, username)) 145 Eventually(session).Should(Exit(0)) 146 147 resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) 148 Expect(err).ToNot(HaveOccurred()) 149 defer resp.Body.Close() 150 body, err := ioutil.ReadAll(resp.Body) 151 Expect(err).ToNot(HaveOccurred()) 152 Expect(string(body)).To(MatchRegexp("hello world")) 153 }) 154 }) 155 156 Describe("command behavior with a space flag and an org flag", func() { 157 BeforeEach(func() { 158 orgName = helpers.NewOrgName() 159 secondOrgName = helpers.NewOrgName() 160 spaceName = helpers.NewSpaceName() 161 secondSpaceName = helpers.NewSpaceName() 162 163 sourceAppName = helpers.PrefixedRandomName("hello") 164 targetAppName = helpers.PrefixedRandomName("banana") 165 166 helpers.SetupCF(orgName, spaceName) 167 168 helpers.WithHelloWorldApp(func(appDir string) { 169 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 170 }) 171 172 helpers.SetupCF(secondOrgName, secondSpaceName) 173 174 helpers.WithBananaPantsApp(func(appDir string) { 175 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 176 }) 177 178 helpers.TargetOrgAndSpace(orgName, spaceName) 179 }) 180 181 AfterEach(func() { 182 helpers.QuickDeleteOrg(orgName) 183 helpers.QuickDeleteOrg(secondOrgName) 184 }) 185 186 It("copies the app to the provided space", func() { 187 username, _ := helpers.GetCredentials() 188 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--organization", secondOrgName, "--space", secondSpaceName) 189 Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, secondOrgName, secondSpaceName, username)) 190 Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, secondOrgName, secondSpaceName, username)) 191 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s...", targetAppName, secondOrgName, secondSpaceName, username)) 192 Eventually(session).Should(Exit(0)) 193 194 resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) 195 Expect(err).ToNot(HaveOccurred()) 196 defer resp.Body.Close() 197 body, err := ioutil.ReadAll(resp.Body) 198 Expect(err).ToNot(HaveOccurred()) 199 Expect(string(body)).To(MatchRegexp("hello world")) 200 }) 201 }) 202 203 Describe("command behavior with an invalid org name", func() { 204 var invalidOrgName string 205 BeforeEach(func() { 206 orgName = helpers.NewOrgName() 207 invalidOrgName = helpers.NewOrgName() 208 spaceName = helpers.NewSpaceName() 209 210 sourceAppName = helpers.PrefixedRandomName("hello") 211 targetAppName = helpers.PrefixedRandomName("banana") 212 213 helpers.SetupCF(orgName, spaceName) 214 215 helpers.WithHelloWorldApp(func(appDir string) { 216 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 217 }) 218 219 helpers.WithBananaPantsApp(func(appDir string) { 220 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 221 }) 222 }) 223 224 AfterEach(func() { 225 helpers.QuickDeleteOrg(orgName) 226 }) 227 228 It("fails to copy the app to the provided space", func() { 229 username, _ := helpers.GetCredentials() 230 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--organization", invalidOrgName, "--space", spaceName) 231 Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, invalidOrgName, spaceName, username)) 232 Eventually(session.Err).Should(Say("Organization '%s' not found.", invalidOrgName)) 233 Eventually(session).Should(Say("FAILED")) 234 Eventually(session).Should(Exit(1)) 235 }) 236 }) 237 238 Describe("command behavior with an org name only (no space)", func() { 239 BeforeEach(func() { 240 orgName = helpers.NewOrgName() 241 secondOrgName = helpers.NewOrgName() 242 spaceName = helpers.NewSpaceName() 243 secondSpaceName = helpers.NewSpaceName() 244 245 sourceAppName = helpers.PrefixedRandomName("hello") 246 targetAppName = helpers.PrefixedRandomName("banana") 247 248 helpers.SetupCF(orgName, spaceName) 249 250 helpers.WithHelloWorldApp(func(appDir string) { 251 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 252 }) 253 254 helpers.SetupCF(secondOrgName, secondSpaceName) 255 256 helpers.WithBananaPantsApp(func(appDir string) { 257 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 258 }) 259 260 helpers.TargetOrgAndSpace(orgName, spaceName) 261 }) 262 263 AfterEach(func() { 264 helpers.QuickDeleteOrg(orgName) 265 }) 266 267 It("fails to copy the app to the provided space", func() { 268 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--organization", secondOrgName) 269 Eventually(session.Err).Should(Say("Incorrect Usage: '--organization, -o' and '--space, -s' must be used together.")) 270 Eventually(session).Should(Say("FAILED")) 271 helpText(session) 272 Eventually(session).Should(Exit(1)) 273 }) 274 }) 275 276 Describe("command behavior when the --no-restart flag is provided", func() { 277 BeforeEach(func() { 278 orgName = helpers.NewOrgName() 279 spaceName = helpers.NewSpaceName() 280 281 sourceAppName = helpers.PrefixedRandomName("hello") 282 targetAppName = helpers.PrefixedRandomName("banana") 283 284 helpers.SetupCF(orgName, spaceName) 285 286 helpers.WithHelloWorldApp(func(appDir string) { 287 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 288 }) 289 290 helpers.WithBananaPantsApp(func(appDir string) { 291 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 292 }) 293 }) 294 295 AfterEach(func() { 296 helpers.QuickDeleteOrg(orgName) 297 }) 298 299 It("copies the app to the provided space without starting it", func() { 300 username, _ := helpers.GetCredentials() 301 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--no-restart") 302 Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username)) 303 Eventually(session).Should(Say("OK")) 304 Eventually(session).Should(Exit(0)) 305 306 session = helpers.CF("apps") 307 Eventually(session).Should(Say(`%s\s+stopped`, targetAppName)) 308 Eventually(session).Should(Exit(0)) 309 310 // check that app was actually copied 311 Eventually(helpers.CF("start", targetAppName)).Should(Exit(0)) 312 resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) 313 Expect(err).ToNot(HaveOccurred()) 314 defer resp.Body.Close() 315 body, err := ioutil.ReadAll(resp.Body) 316 Expect(err).ToNot(HaveOccurred()) 317 Expect(string(body)).To(MatchRegexp("hello world")) 318 }) 319 }) 320 321 Describe("command behavior when the --strategy flag is set to rolling", func() { 322 BeforeEach(func() { 323 orgName = helpers.NewOrgName() 324 spaceName = helpers.NewSpaceName() 325 326 sourceAppName = helpers.PrefixedRandomName("hello") 327 targetAppName = helpers.PrefixedRandomName("banana") 328 329 helpers.SetupCF(orgName, spaceName) 330 331 helpers.WithHelloWorldApp(func(appDir string) { 332 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 333 }) 334 335 helpers.WithBananaPantsApp(func(appDir string) { 336 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 337 }) 338 }) 339 340 AfterEach(func() { 341 helpers.QuickDeleteOrg(orgName) 342 }) 343 344 It("copies the app to the provided space using a rolling deploy", func() { 345 username, _ := helpers.GetCredentials() 346 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--strategy", "rolling") 347 Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username)) 348 Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) 349 Eventually(session).Should(Say("Waiting for app to deploy...")) 350 Eventually(session).Should(Exit(0)) 351 352 Eventually(helpers.CF("start", targetAppName)).Should(Exit(0)) 353 resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) 354 Expect(err).ToNot(HaveOccurred()) 355 defer resp.Body.Close() 356 body, err := ioutil.ReadAll(resp.Body) 357 Expect(err).ToNot(HaveOccurred()) 358 Expect(string(body)).To(MatchRegexp("hello world")) 359 }) 360 }) 361 362 Describe("command behavior when the --no-wait flag is passed", func() { 363 BeforeEach(func() { 364 orgName = helpers.NewOrgName() 365 spaceName = helpers.NewSpaceName() 366 367 sourceAppName = helpers.PrefixedRandomName("hello") 368 targetAppName = helpers.PrefixedRandomName("banana") 369 370 helpers.SetupCF(orgName, spaceName) 371 372 helpers.WithHelloWorldApp(func(appDir string) { 373 Eventually(helpers.CF("push", sourceAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 374 }) 375 376 helpers.WithBananaPantsApp(func(appDir string) { 377 Eventually(helpers.CF("push", targetAppName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 378 }) 379 }) 380 381 AfterEach(func() { 382 helpers.QuickDeleteOrg(orgName) 383 }) 384 385 It("copies the app to the provided space", func() { 386 username, _ := helpers.GetCredentials() 387 session := helpers.CF("copy-source", sourceAppName, targetAppName, "--no-wait") 388 Eventually(session).Should(Say("Copying source from app %s to target app %s in org %s / space %s as %s...", sourceAppName, targetAppName, orgName, spaceName, username)) 389 Eventually(session).Should(Say("Staging app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) 390 Eventually(session).Should(Say("Restarting app %s in org %s / space %s as %s...", targetAppName, orgName, spaceName, username)) 391 Eventually(session).Should(Exit(0)) 392 393 Eventually(helpers.CF("start", targetAppName)).Should(Exit(0)) 394 resp, err := http.Get(fmt.Sprintf("http://%s.%s", targetAppName, helpers.DefaultSharedDomain())) 395 Expect(err).ToNot(HaveOccurred()) 396 defer resp.Body.Close() 397 body, err := ioutil.ReadAll(resp.Body) 398 Expect(err).ToNot(HaveOccurred()) 399 Expect(string(body)).To(MatchRegexp("hello world")) 400 }) 401 }) 402 }) 403 404 func helpText(session *Session) { 405 Eventually(session).Should(Say("NAME:")) 406 Eventually(session).Should(Say("copy-source - Copies the source code of an application to another existing application and restages that application")) 407 Eventually(session).Should(Say("USAGE:")) 408 Eventually(session).Should(Say(`cf copy-source SOURCE_APP DESTINATION_APP \[-s TARGET_SPACE \[-o TARGET_ORG\]\] \[--no-restart\] \[--strategy STRATEGY\] \[--no-wait\]`)) 409 Eventually(session).Should(Say("OPTIONS:")) 410 Eventually(session).Should(Say(`--strategy\s+Deployment strategy, either rolling or null`)) 411 Eventually(session).Should(Say(`--no-wait\s+ Exit when the first instance of the web process is healthy`)) 412 Eventually(session).Should(Say(`--no-restart\s+Do not restage the destination application`)) 413 Eventually(session).Should(Say(`--organization, -o\s+Org that contains the destination application`)) 414 Eventually(session).Should(Say(`--space, -s\s+Space that contains the destination application`)) 415 Eventually(session).Should(Say("ENVIRONMENT:")) 416 Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for staging, in minutes`)) 417 Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`)) 418 Eventually(session).Should(Say("SEE ALSO:")) 419 Eventually(session).Should(Say("apps, push, restage, restart, target")) 420 }