github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/isolated/route_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccversion" 7 . "github.com/LukasHeimann/cloudfoundrycli/v8/cf/util/testhelpers/matchers" 8 "github.com/LukasHeimann/cloudfoundrycli/v8/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("route command", func() { 16 Context("Help", func() { 17 It("appears in cf help -a", func() { 18 session := helpers.CF("help", "-a") 19 Eventually(session).Should(Exit(0)) 20 Expect(session).To(HaveCommandInCategoryWithDescription("route", "ROUTES", "Display route details and mapped destinations")) 21 }) 22 23 It("displays the help information", func() { 24 session := helpers.CF("route", "--help") 25 Eventually(session).Should(Say(`NAME:`)) 26 Eventually(session).Should(Say(`route - Display route details and mapped destinations`)) 27 Eventually(session).Should(Say(`\n`)) 28 29 Eventually(session).Should(Say(`USAGE:`)) 30 Eventually(session).Should(Say(`Display an HTTP route:`)) 31 Eventually(session).Should(Say(`cf route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`)) 32 Eventually(session).Should(Say(`Display a TCP route:`)) 33 Eventually(session).Should(Say(`cf route DOMAIN --port PORT\n`)) 34 Eventually(session).Should(Say(`\n`)) 35 36 Eventually(session).Should(Say(`EXAMPLES:`)) 37 Eventually(session).Should(Say(`cf route example.com # example.com`)) 38 Eventually(session).Should(Say(`cf route example.com -n myhost --path foo # myhost.example.com/foo`)) 39 Eventually(session).Should(Say(`cf route example.com --path foo # example.com/foo`)) 40 Eventually(session).Should(Say(`cf route example.com --port 5000 # example.com:5000`)) 41 Eventually(session).Should(Say(`\n`)) 42 43 Eventually(session).Should(Say(`OPTIONS:`)) 44 Eventually(session).Should(Say(`--hostname, -n\s+Hostname used to identify the HTTP route`)) 45 Eventually(session).Should(Say(`--path\s+Path used to identify the HTTP route`)) 46 Eventually(session).Should(Say(`--port\s+Port used to identify the TCP route`)) 47 Eventually(session).Should(Say(`\n`)) 48 49 Eventually(session).Should(Say(`SEE ALSO:`)) 50 Eventually(session).Should(Say(`create-route, delete-route, routes`)) 51 52 Eventually(session).Should(Exit(0)) 53 }) 54 }) 55 56 When("the environment is not setup correctly", func() { 57 It("fails with the appropriate errors", func() { 58 helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "route", "some-domain") 59 }) 60 }) 61 62 When("the environment is set up correctly", func() { 63 var ( 64 userName string 65 orgName string 66 spaceName string 67 ) 68 69 BeforeEach(func() { 70 orgName = helpers.NewOrgName() 71 spaceName = helpers.NewSpaceName() 72 73 helpers.SetupCF(orgName, spaceName) 74 userName, _ = helpers.GetCredentials() 75 }) 76 77 AfterEach(func() { 78 helpers.QuickDeleteOrg(orgName) 79 }) 80 81 When("the domain exists", func() { 82 var ( 83 domainName string 84 ) 85 86 BeforeEach(func() { 87 domainName = helpers.NewDomainName() 88 }) 89 90 When("the route exists", func() { 91 var ( 92 domain helpers.Domain 93 hostname string 94 path string 95 ) 96 97 When("it's an HTTP route", func() { 98 BeforeEach(func() { 99 domain = helpers.NewDomain(orgName, domainName) 100 hostname = "key-lime-pie" 101 path = "/some-path" 102 domain.CreatePrivate() 103 Eventually(helpers.CF("create-app", "killer")).Should(Exit(0)) 104 Eventually(helpers.CF("create-route", domain.Name, "--hostname", hostname, "--path", path)).Should(Exit(0)) 105 Eventually(helpers.CF("map-route", "killer", domain.Name, "--hostname", hostname, "--path", path)).Should(Exit(0)) 106 }) 107 108 AfterEach(func() { 109 domain.Delete() 110 }) 111 112 It("displays the route summary and exits without failing", func() { 113 session := helpers.CF("route", domainName, "--hostname", hostname, "--path", path) 114 Eventually(session).Should(Say(`Showing route %s\.%s%s in org %s / space %s as %s\.\.\.`, hostname, domainName, path, orgName, spaceName, userName)) 115 Eventually(session).Should(Say(`domain:\s+%s`, domainName)) 116 Eventually(session).Should(Say(`host:\s+%s`, hostname)) 117 Eventually(session).Should(Say(`port:\s+\n`)) 118 Eventually(session).Should(Say(`path:\s+%s`, path)) 119 Eventually(session).Should(Say(`protocol:\s+http`)) 120 Eventually(session).Should(Say(`\n`)) 121 Eventually(session).Should(Say(`Destinations:`)) 122 Eventually(session).Should(Say(`\s+app\s+process\s+port\s+app-protocol`)) 123 Eventually(session).Should(Exit(0)) 124 }) 125 126 It("displays the protocol in the route summary and exits without failing", func() { 127 helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3) 128 session := helpers.CF("route", domainName, "--hostname", hostname, "--path", path) 129 Eventually(session).Should(Say(`\s+killer\s+web\s+8080\s+http1`)) 130 Eventually(session).Should(Exit(0)) 131 }) 132 }) 133 134 When("it's a TCP route", func() { 135 var ( 136 routerGroup helpers.RouterGroup 137 port int 138 tcpDomain helpers.Domain 139 ) 140 141 BeforeEach(func() { 142 routerGroup = helpers.NewRouterGroup(helpers.NewRouterGroupName(), "1024-2048") 143 routerGroup.Create() 144 145 tcpDomain = helpers.NewDomain(orgName, helpers.NewDomainName("TCP-DOMAIN")) 146 tcpDomain.CreateWithRouterGroup(routerGroup.Name) 147 148 port = 1024 149 150 Eventually(helpers.CF("create-app", "killer")).Should(Exit(0)) 151 Eventually(helpers.CF("create-route", tcpDomain.Name, "--port", fmt.Sprintf("%d", port))).Should(Exit(0)) 152 Eventually(helpers.CF("map-route", "killer", tcpDomain.Name, "--port", "1024")).Should(Exit(0)) 153 }) 154 155 AfterEach(func() { 156 tcpDomain.DeleteShared() 157 routerGroup.Delete() 158 }) 159 160 It("displays the route summary and exits without failing", func() { 161 session := helpers.CF("route", tcpDomain.Name, "--port", fmt.Sprintf("%d", port)) 162 Eventually(session).Should(Say(`Showing route %s:%d in org %s / space %s as %s\.\.\.`, tcpDomain.Name, port, orgName, spaceName, userName)) 163 Eventually(session).Should(Say(`domain:\s+%s`, tcpDomain.Name)) 164 Eventually(session).Should(Say(`host:\s+\n`)) 165 Eventually(session).Should(Say(`port:\s+%d`, port)) 166 Eventually(session).Should(Say(`path:\s+\n`)) 167 Eventually(session).Should(Say(`protocol:\s+tcp`)) 168 Eventually(session).Should(Say(`\n`)) 169 Eventually(session).Should(Say(`Destinations:`)) 170 Eventually(session).Should(Say(`\s+app\s+process\s+port\s+app-protocol`)) 171 Eventually(session).Should(Exit(0)) 172 }) 173 174 It("displays the protocol in the route summary and exits without failing", func() { 175 helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3) 176 session := helpers.CF("route", tcpDomain.Name, "--port", fmt.Sprintf("%d", port)) 177 Eventually(session).Should(Say(`\s+killer\s+web\s+8080\s+tcp`)) 178 Eventually(session).Should(Exit(0)) 179 }) 180 }) 181 }) 182 183 When("the route does not exist", func() { 184 var domain helpers.Domain 185 186 BeforeEach(func() { 187 domain = helpers.NewDomain(orgName, domainName) 188 domain.Create() 189 }) 190 191 AfterEach(func() { 192 domain.Delete() 193 }) 194 195 When("no flags are used", func() { 196 It("checks the route", func() { 197 session := helpers.CF("route", domainName) 198 Eventually(session).Should(Say(`Showing route %s in org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 199 Eventually(session.Err).Should(Say(`Route with host '', domain '%s', and path '/' not found\.`, domainName)) 200 Eventually(session).Should(Exit(1)) 201 }) 202 }) 203 204 When("passing in a hostname", func() { 205 It("checks the route with the hostname", func() { 206 hostname := "tiramisu" 207 session := helpers.CF("route", domainName, "-n", hostname) 208 Eventually(session).Should(Say(`Showing route %s.%s in org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName)) 209 Eventually(session.Err).Should(Say(`Route with host '%s', domain '%s', and path '/' not found\.`, hostname, domainName)) 210 Eventually(session).Should(Exit(1)) 211 }) 212 }) 213 214 When("passing in hostname and path with a leading '/'", func() { 215 It("checks the route with hostname and path", func() { 216 hostname := "tiramisu" 217 pathString := "/recipes" 218 session := helpers.CF("route", domainName, "-n", hostname, "--path", pathString) 219 Eventually(session).Should(Say(`Showing route %s.%s%s in org %s / space %s as %s\.\.\.`, hostname, domainName, pathString, orgName, spaceName, userName)) 220 Eventually(session.Err).Should(Say(`Route with host '%s', domain '%s', and path '%s' not found`, hostname, domainName, pathString)) 221 Eventually(session).Should(Exit(1)) 222 }) 223 }) 224 }) 225 }) 226 227 When("the domain does not exist", func() { 228 It("displays error and exits 1", func() { 229 session := helpers.CF("route", "some-domain") 230 Eventually(session).Should(Say(`FAILED`)) 231 Eventually(session.Err).Should(Say(`Domain 'some-domain' not found.`)) 232 Eventually(session).Should(Exit(1)) 233 }) 234 }) 235 236 When("the domain is not specified", func() { 237 It("displays error and exits 1", func() { 238 session := helpers.CF("route") 239 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n")) 240 Eventually(session.Err).Should(Say("\n")) 241 Eventually(session).Should(Say("NAME:\n")) 242 Eventually(session).Should(Exit(1)) 243 }) 244 }) 245 }) 246 })