github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/isolated/routes_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 9 "github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers" 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("routes command", func() { 17 18 appProtocolValue := "http1" 19 const tableHeaders = `space\s+host\s+domain\s+port\s+path\s+protocol\s+app-protocol\s+apps\s+service instance` 20 Context("Help", func() { 21 It("appears in cf help -a", func() { 22 session := helpers.CF("help", "-a") 23 Eventually(session).Should(Exit(0)) 24 Expect(session).To(HaveCommandInCategoryWithDescription("routes", "ROUTES", "List all routes in the current space or the current organization")) 25 }) 26 27 It("displays the help information", func() { 28 session := helpers.CF("routes", "--help") 29 Eventually(session).Should(Say(`NAME:`)) 30 Eventually(session).Should(Say(`routes - List all routes in the current space or the current organization\n`)) 31 Eventually(session).Should(Say(`\n`)) 32 33 Eventually(session).Should(Say(`USAGE:`)) 34 Eventually(session).Should(Say(`cf routes \[--org-level\]\n`)) 35 Eventually(session).Should(Say(`\n`)) 36 37 Eventually(session).Should(Say(`OPTIONS:`)) 38 Eventually(session).Should(Say(`--org-level\s+List all the routes for all spaces of current organization`)) 39 Eventually(session).Should(Say(`\n`)) 40 41 Eventually(session).Should(Say(`SEE ALSO:`)) 42 Eventually(session).Should(Say(`check-route, create-route, domains, map-route, unmap-route`)) 43 44 Eventually(session).Should(Exit(0)) 45 }) 46 }) 47 48 When("the environment is not setup correctly", func() { 49 It("fails with the appropriate errors", func() { 50 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "routes") 51 }) 52 }) 53 54 When("the environment is set up correctly", func() { 55 var ( 56 orgName string 57 spaceName string 58 userName string 59 appName1 string 60 appName2 string 61 ) 62 63 BeforeEach(func() { 64 orgName = helpers.NewOrgName() 65 spaceName = helpers.NewSpaceName() 66 67 helpers.SetupCF(orgName, spaceName) 68 userName, _ = helpers.GetCredentials() 69 if !helpers.IsVersionMet(ccversion.MinVersionHTTP2RoutingV3) { 70 appProtocolValue = "" 71 } 72 73 }) 74 75 AfterEach(func() { 76 helpers.QuickDeleteOrg(orgName) 77 }) 78 79 When("routes exist", func() { 80 var ( 81 domainName string 82 domain helpers.Domain 83 84 otherSpaceName string 85 serviceInstanceName string 86 ) 87 88 BeforeEach(func() { 89 otherSpaceName = helpers.GenerateHigherName(helpers.NewSpaceName, spaceName) 90 91 domainName = helpers.NewDomainName() 92 93 domain = helpers.NewDomain(orgName, domainName) 94 appName1 = helpers.NewAppName() 95 Eventually(helpers.CF("create-app", appName1)).Should(Exit(0)) 96 domain.CreatePrivate() 97 Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1")).Should(Exit(0)) 98 Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1a")).Should(Exit(0)) 99 Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1b")).Should(Exit(0)) 100 Eventually(helpers.CF("set-label", "route", "route1b."+domainName, "env=prod")).Should(Exit(0)) 101 102 serviceInstanceName = helpers.NewServiceInstanceName() 103 routeServiceURL := helpers.RandomURL() 104 Eventually(helpers.CF("cups", serviceInstanceName, "-r", routeServiceURL)).Should(Exit(0)) 105 Eventually(helpers.CF("bind-route-service", domainName, "--hostname", "route1", serviceInstanceName, "--wait")).Should(Exit(0)) 106 107 helpers.SetupCF(orgName, otherSpaceName) 108 appName2 = helpers.NewAppName() 109 Eventually(helpers.CF("create-app", appName2)).Should(Exit(0)) 110 Eventually(helpers.CF("map-route", appName2, domainName, "--hostname", "route2", "--path", "dodo")).Should(Exit(0)) 111 112 helpers.SetupCF(orgName, spaceName) 113 }) 114 115 AfterEach(func() { 116 domain.Delete() 117 helpers.QuickDeleteSpace(otherSpaceName) 118 }) 119 120 It("lists all the routes", func() { 121 session := helpers.CF("routes") 122 Eventually(session).Should(Exit(0)) 123 Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName)) 124 Expect(session).To(Say(tableHeaders)) 125 Expect(session).To(Say(`%s\s+route1\s+%s\s+http\s+%s\s+%s\s+%s\n`, spaceName, domainName, appProtocolValue, appName1, serviceInstanceName)) 126 Expect(session).To(Say(`%s\s+route1a\s+%s\s+http\s+%s\s+%s\s+\n`, spaceName, domainName, appProtocolValue, appName1)) 127 Expect(session).To(Say(`%s\s+route1b\s+%s\s+http\s+%s\s+%s\s+\n`, spaceName, domainName, appProtocolValue, appName1)) 128 Expect(session).ToNot(Say(`%s\s+route2\s+%s\s+http\s+%s\s+%s\s+\n`, spaceName, domainName, appProtocolValue, appName2)) 129 }) 130 131 It("lists all the routes by label", func() { 132 session := helpers.CF("routes", "--labels", "env in (prod)") 133 Eventually(session).Should(Exit(0)) 134 Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName)) 135 Expect(session).To(Say(tableHeaders)) 136 Expect(session).ToNot(Say(`%s\s+route1\s+%s\s+http\s+%s\s+%s\s+%s\n`, spaceName, domainName, appProtocolValue, appName1, serviceInstanceName)) 137 Expect(session).ToNot(Say(`%s\s+route1a\s+%s\s+http\s+%s\s+%s\s+\n`, spaceName, domainName, appProtocolValue, appName1)) 138 Expect(session).To(Say(`%s\s+route1b\s+%s\s+http\s+%s\s+%s\s+\n`, spaceName, domainName, appProtocolValue, appName1)) 139 Expect(session).ToNot(Say(`%s\s+route2\s+%s\s+http\s+%s\s+%s\s+\n`, spaceName, domainName, appProtocolValue, appName2)) 140 }) 141 142 When("fetching routes by org", func() { 143 It("lists all the routes in the org", func() { 144 session := helpers.CF("routes", "--org-level") 145 Eventually(session).Should(Exit(0)) 146 Expect(session).To(Say(`Getting routes for org %s as %s\.\.\.`, orgName, userName)) 147 Expect(session).To(Say(tableHeaders)) 148 Expect(session).To(Say(`%s\s+route1\s+%s\s+http\s+%s\s+%s\s+%s\n`, spaceName, domainName, appProtocolValue, appName1, serviceInstanceName)) 149 Expect(session).To(Say(`%s\s+route2\s+%s\s+\/dodo\s+http\s+%s\s+%s\s+\n`, otherSpaceName, domainName, appProtocolValue, appName2)) 150 }) 151 }) 152 }) 153 154 When("http1 and http2 routes exist", func() { 155 var ( 156 domainName string 157 domain helpers.Domain 158 ) 159 160 BeforeEach(func() { 161 helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3) 162 domainName = helpers.NewDomainName() 163 164 domain = helpers.NewDomain(orgName, domainName) 165 166 appName1 = helpers.NewAppName() 167 Eventually(helpers.CF("create-app", appName1)).Should(Exit(0)) 168 appName2 = helpers.NewAppName() 169 Eventually(helpers.CF("create-app", appName2)).Should(Exit(0)) 170 171 domain.CreatePrivate() 172 173 Eventually(helpers.CF("map-route", appName1, domainName, "--hostname", "route1")).Should(Exit(0)) 174 Eventually(helpers.CF("map-route", appName2, domainName, "--hostname", "route2")).Should(Exit(0)) 175 Eventually(helpers.CF("map-route", appName2, domainName, "--hostname", "route1", "--app-protocol", "http2")).Should(Exit(0)) 176 177 helpers.SetupCF(orgName, spaceName) 178 }) 179 180 AfterEach(func() { 181 domain.Delete() 182 }) 183 184 It("lists all the routes", func() { 185 session := helpers.CF("routes") 186 Eventually(session).Should(Exit(0)) 187 Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName)) 188 Expect(session).To(Say(tableHeaders)) 189 Expect(session).To(Say(`%s\s+route1\s+%s\s+http\s+http1, http2\s+%s\s+\n`, spaceName, domainName, fmt.Sprintf("%s, %s", appName1, appName2))) 190 Expect(session).To(Say(`%s\s+route2\s+%s\s+http\s+http1\s+%s\s+\n`, spaceName, domainName, appName2)) 191 }) 192 }) 193 194 When("when shared tcp routes exist", func() { 195 var ( 196 domainName string 197 domain helpers.Domain 198 routerGroup helpers.RouterGroup 199 ) 200 201 BeforeEach(func() { 202 domainName = helpers.NewDomainName() 203 204 domain = helpers.NewDomain(orgName, domainName) 205 206 routerGroup = helpers.NewRouterGroup( 207 helpers.NewRouterGroupName(), 208 "1024-2048", 209 ) 210 routerGroup.Create() 211 domain.CreateWithRouterGroup(routerGroup.Name) 212 213 Eventually(helpers.CF("create-route", domainName, "--port", "1028")).Should(Exit(0)) 214 }) 215 216 AfterEach(func() { 217 domain.DeleteShared() 218 routerGroup.Delete() 219 }) 220 221 It("lists all the routes", func() { 222 session := helpers.CF("routes") 223 Eventually(session).Should(Exit(0)) 224 225 Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName)) 226 Expect(session).To(Say(tableHeaders)) 227 Expect(session).To(Say(`%s\s+%s[^:]\s+%d\s+tcp`, spaceName, domainName, 1028)) 228 }) 229 }) 230 231 When("no routes exist", func() { 232 It("outputs a message about no routes existing", func() { 233 session := helpers.CF("routes") 234 Eventually(session).Should(Exit(0)) 235 Expect(session).To(Say(`Getting routes for org %s / space %s as %s\.\.\.`, orgName, spaceName, userName)) 236 Expect(session).To(Say("No routes found")) 237 }) 238 }) 239 }) 240 })