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