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