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