github.com/loafoe/cli@v7.1.0+incompatible/integration/v6/push/hostname_only_routing_test.go (about) 1 package push 2 3 import ( 4 "fmt" 5 "strings" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("push with hostname", func() { 15 var ( 16 appName string 17 route string 18 ) 19 20 BeforeEach(func() { 21 appName = helpers.NewAppName() 22 }) 23 24 When("the default domain is a HTTP domain", func() { 25 When("no host is provided / host defaults to app name", func() { 26 BeforeEach(func() { 27 route = fmt.Sprintf("%s.%s", strings.ToLower(appName), helpers.DefaultSharedDomain()) 28 }) 29 30 When("the default route does not exist", func() { 31 It("creates and maps the route", func() { 32 helpers.WithHelloWorldApp(func(dir string) { 33 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 34 Eventually(session).Should(Say("routes:")) 35 Eventually(session).Should(Say(`(?i)\+\s+%s`, route)) 36 Eventually(session).Should(Exit(0)) 37 }) 38 39 session := helpers.CF("app", appName) 40 Eventually(session).Should(Say(`name:\s+%s`, appName)) 41 Eventually(session).Should(Say(`routes:\s+%s`, route)) 42 Eventually(session).Should(Exit(0)) 43 }) 44 }) 45 46 Context("the default route exists and is unmapped", func() { 47 BeforeEach(func() { 48 Eventually(helpers.CF("create-route", space, helpers.DefaultSharedDomain(), "-n", strings.ToLower(appName))).Should(Exit(0)) 49 }) 50 51 It("maps the route", func() { 52 helpers.WithHelloWorldApp(func(dir string) { 53 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 54 Eventually(session).Should(Say("routes:")) 55 Eventually(session).Should(Say(`(?i)\+\s+%s`, route)) 56 Eventually(session).Should(Exit(0)) 57 }) 58 59 session := helpers.CF("app", appName) 60 Eventually(session).Should(Say(`name:\s+%s`, appName)) 61 Eventually(session).Should(Say(`routes:\s+%s`, route)) 62 Eventually(session).Should(Exit(0)) 63 }) 64 }) 65 66 When("the default route is mapped to the application", func() { 67 BeforeEach(func() { 68 helpers.WithHelloWorldApp(func(dir string) { 69 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start")).Should(Exit(0)) 70 }) 71 }) 72 73 It("does nothing", func() { 74 helpers.WithHelloWorldApp(func(dir string) { 75 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 76 Eventually(session).Should(Say("routes:")) 77 Eventually(session).Should(Say(`(?i)\s+%s`, route)) 78 Eventually(session).Should(Exit(0)) 79 }) 80 81 appGUID := helpers.AppGUID(appName) 82 session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s/routes", appGUID)) 83 Eventually(session).Should(Say(`"total_results":\s+1,`)) 84 Eventually(session).Should(Exit(0)) 85 }) 86 }) 87 }) 88 89 When("the host is provided", func() { 90 var hostname string 91 92 BeforeEach(func() { 93 hostname = strings.ToLower(helpers.NewAppName()) 94 route = fmt.Sprintf("%s.%s", hostname, helpers.DefaultSharedDomain()) 95 }) 96 97 When("the default route does not exist", func() { 98 It("creates and maps the route", func() { 99 helpers.WithHelloWorldApp(func(dir string) { 100 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start") 101 Eventually(session).Should(Say("routes:")) 102 Eventually(session).Should(Say(`(?i)\+\s+%s`, route)) 103 Eventually(session).Should(Exit(0)) 104 }) 105 106 session := helpers.CF("app", appName) 107 Eventually(session).Should(Say(`name:\s+%s`, appName)) 108 Eventually(session).Should(Say(`routes:\s+%s`, route)) 109 Eventually(session).Should(Exit(0)) 110 111 By("does not remap default route after") 112 helpers.WithHelloWorldApp(func(dir string) { 113 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--no-start") 114 Eventually(session).Should(Say("routes:")) 115 Consistently(session).ShouldNot(Say(`(?i)\+\s+.*%s.*`, helpers.DefaultSharedDomain())) 116 Eventually(session).Should(Exit(0)) 117 }) 118 }) 119 }) 120 121 Context("the default route exists and is unmapped", func() { 122 BeforeEach(func() { 123 Eventually(helpers.CF("create-route", space, helpers.DefaultSharedDomain(), "-n", strings.ToLower(appName))).Should(Exit(0)) 124 }) 125 126 It("creates and maps the route with the provided hostname", func() { 127 helpers.WithHelloWorldApp(func(dir string) { 128 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start") 129 Eventually(session).Should(Say("routes:")) 130 Eventually(session).Should(Say(`(?i)\+\s+%s`, route)) 131 Eventually(session).Should(Exit(0)) 132 }) 133 134 session := helpers.CF("app", appName) 135 Eventually(session).Should(Say(`name:\s+%s`, appName)) 136 Eventually(session).Should(Say(`routes:\s+%s`, route)) 137 Eventually(session).Should(Exit(0)) 138 }) 139 }) 140 141 When("the default route is mapped to the application", func() { 142 BeforeEach(func() { 143 helpers.WithHelloWorldApp(func(dir string) { 144 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start")).Should(Exit(0)) 145 }) 146 }) 147 148 It("does nothing", func() { 149 helpers.WithHelloWorldApp(func(dir string) { 150 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "--hostname", hostname, "--no-start") 151 Eventually(session).Should(Say("routes:")) 152 Eventually(session).Should(Say(`(?i)\s+%s`, route)) 153 Eventually(session).Should(Exit(0)) 154 }) 155 156 appGUID := helpers.AppGUID(appName) 157 session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s/routes", appGUID)) 158 Eventually(session).Should(Say(`"total_results":\s+1,`)) 159 Eventually(session).Should(Exit(0)) 160 }) 161 }) 162 }) 163 }) 164 165 When("using a tcp domain", func() { 166 var ( 167 domain helpers.Domain 168 domainName string 169 ) 170 171 BeforeEach(func() { 172 domainName = helpers.NewDomainName() 173 domain = helpers.NewDomain(organization, domainName) 174 domain.CreateWithRouterGroup(helpers.FindOrCreateTCPRouterGroup(GinkgoParallelNode())) 175 }) 176 177 AfterEach(func() { 178 domain.DeleteShared() 179 }) 180 181 It("returns an error", func() { 182 session := helpers.CF(PushCommandName, appName, "--hostname", "I-dont-care", "-d", domainName, "--no-start") 183 Eventually(session.Err).Should(Say("The route is invalid: a hostname cannot be used with a TCP domain.")) 184 Eventually(session).Should(Exit(1)) 185 }) 186 }) 187 })