github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/push/random_route_test.go (about) 1 package push 2 3 import ( 4 "fmt" 5 "path" 6 "time" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("random route", func() { 16 const randomRouteRegexp = `(?m)routes:\s+%s-[\w]+-[\w]+(-[\w]+)?\.%s$` 17 18 var ( 19 appName string 20 ) 21 22 BeforeEach(func() { 23 appName = fmt.Sprintf("app%d", time.Now().Nanosecond()) 24 }) 25 26 When("passed the --random-route flag", func() { 27 When("the app does not already exist", func() { 28 It("generates a random route for the app", func() { 29 helpers.WithHelloWorldApp(func(dir string) { 30 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--random-route", "--no-manifest", "--no-start") 31 Eventually(session).Should(Say(randomRouteRegexp, appName, helpers.DefaultSharedDomain())) 32 Eventually(session).Should(Exit(0)) 33 }) 34 35 appSession := helpers.CF("app", appName) 36 Eventually(appSession).Should(Say(`name:\s+%s`, appName)) 37 Eventually(appSession).Should(Say(randomRouteRegexp, appName, helpers.DefaultSharedDomain())) 38 Eventually(appSession).Should(Exit(0)) 39 }) 40 }) 41 42 When("the app exists and has an existing route", func() { 43 BeforeEach(func() { 44 helpers.WithHelloWorldApp(func(dir string) { 45 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-manifest", "--no-start") 46 Eventually(session).Should(Exit(0)) 47 }) 48 }) 49 50 It("does not generate a random route for the app", func() { 51 helpers.WithHelloWorldApp(func(dir string) { 52 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--random-route", "--no-manifest", "--no-start") 53 Eventually(session).Should(Say(`(?m)routes:\s+%s\.%s$`, appName, helpers.DefaultSharedDomain())) 54 Eventually(session).Should(Exit(0)) 55 }) 56 }) 57 }) 58 }) 59 60 When("passed the random-route manifest property as 'true' and no --random-route flag", func() { 61 var manifest map[string]interface{} 62 63 BeforeEach(func() { 64 manifest = map[string]interface{}{ 65 "applications": []map[string]interface{}{ 66 { 67 "name": appName, 68 "random-route": true, 69 }, 70 }, 71 } 72 helpers.WithHelloWorldApp(func(dir string) { 73 helpers.WriteManifest(path.Join(dir, "manifest.yml"), manifest) 74 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 75 Eventually(session).Should(Say(randomRouteRegexp, appName, helpers.DefaultSharedDomain())) 76 Eventually(session).Should(Exit(0)) 77 }) 78 }) 79 80 It("generates a random route for the app", func() { 81 session := helpers.CF("app", appName) 82 Eventually(session).Should(Say(`name:\s+%s`, appName)) 83 Eventually(session).Should(Say(randomRouteRegexp, appName, helpers.DefaultSharedDomain())) 84 Eventually(session).Should(Exit(0)) 85 }) 86 87 When("the app has an existing route", func() { 88 It("does not generate a random route for the app", func() { 89 helpers.WithHelloWorldApp(func(dir string) { 90 helpers.WriteManifest(path.Join(dir, "manifest.yml"), manifest) 91 92 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 93 Eventually(session).ShouldNot(Say(`\+\s+%s-[\w]+`, appName)) 94 Eventually(session).Should(Exit(0)) 95 }) 96 }) 97 }) 98 }) 99 100 When("passed the random-route manifest property as 'false' and with --random-route flag", func() { 101 var manifest map[string]interface{} 102 103 BeforeEach(func() { 104 manifest = map[string]interface{}{ 105 "applications": []map[string]interface{}{ 106 { 107 "name": appName, 108 "random-route": false, 109 }, 110 }, 111 } 112 113 helpers.WithHelloWorldApp(func(dir string) { 114 helpers.WriteManifest(path.Join(dir, "manifest.yml"), manifest) 115 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start", "--random-route") 116 Eventually(session).Should(Say(randomRouteRegexp, appName, helpers.DefaultSharedDomain())) 117 Eventually(session).Should(Exit(0)) 118 }) 119 }) 120 121 It("generates a random route for the app", func() { 122 session := helpers.CF("app", appName) 123 Eventually(session).Should(Say(`name:\s+%s`, appName)) 124 Eventually(session).Should(Say(randomRouteRegexp, appName, helpers.DefaultSharedDomain())) 125 Eventually(session).Should(Exit(0)) 126 }) 127 }) 128 })