github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/push/http_routes_in_manifest_test.go (about) 1 package push 2 3 import ( 4 "path/filepath" 5 "regexp" 6 7 "code.cloudfoundry.org/cli/integration/helpers" 8 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("HTTP routes in manifest", func() { 16 var ( 17 app string 18 domain helpers.Domain 19 subdomain helpers.Domain 20 route1 helpers.Route 21 route2 helpers.Route 22 routeWithPath helpers.Route 23 routeStar helpers.Route 24 ) 25 26 BeforeEach(func() { 27 app = helpers.NewAppName() 28 domain = helpers.NewDomain(organization, helpers.DomainName()) 29 subdomain = helpers.NewDomain(organization, "sub."+domain.Name) 30 route1 = helpers.NewRoute(space, domain.Name, helpers.PrefixedRandomName("r1"), "") 31 route2 = helpers.NewRoute(space, subdomain.Name, helpers.PrefixedRandomName("r2"), "") 32 routeWithPath = helpers.NewRoute(space, domain.Name, helpers.PrefixedRandomName("r3"), helpers.PrefixedRandomName("p1")) 33 routeStar = helpers.NewRoute(space, subdomain.Name, "*", "") 34 }) 35 36 Context("when the domain exist", func() { 37 BeforeEach(func() { 38 domain.Create() 39 subdomain.Create() 40 }) 41 42 Context("when the routes don't have a path", func() { 43 Context("when the routes are new", func() { 44 It("creates and maps the routes", func() { 45 helpers.WithHelloWorldApp(func(dir string) { 46 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 47 "applications": []map[string]interface{}{ 48 { 49 "name": app, 50 "routes": []map[string]string{ 51 {"route": route1.String()}, 52 {"route": route2.String()}, 53 {"route": routeStar.String()}, 54 }, 55 }, 56 }, 57 }) 58 59 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 60 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 61 62 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 63 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", app)) 64 Eventually(session).Should(Say("\\s+routes:")) 65 Eventually(session).Should(Say("(?i)\\+\\s+%s", regexp.QuoteMeta(routeStar.String()))) 66 Eventually(session).Should(Say("(?i)\\+\\s+%s", route1)) 67 Eventually(session).Should(Say("(?i)\\+\\s+%s", route2)) 68 Eventually(session).Should(Exit(0)) 69 }) 70 71 session := helpers.CF("app", app) 72 Eventually(session).Should(Say("name:\\s+%s", app)) 73 Eventually(session).Should(Say("routes:\\s+(%s, %s)|(%s, %s)", route1, route2, route2, route1)) 74 Eventually(session).Should(Exit(0)) 75 }) 76 77 Context("when --random-route is also specified", func() { 78 It("creates and maps the routes", func() { 79 helpers.WithHelloWorldApp(func(dir string) { 80 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 81 "applications": []map[string]interface{}{ 82 { 83 "name": app, 84 "random-route": true, 85 "routes": []map[string]string{ 86 {"route": route1.String()}, 87 {"route": route2.String()}, 88 }, 89 }, 90 }, 91 }) 92 93 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 94 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 95 96 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 97 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", app)) 98 Eventually(session).Should(Say("\\s+routes:")) 99 Eventually(session).Should(Say("(?i)\\+\\s+%s", route1)) 100 Eventually(session).Should(Say("(?i)\\+\\s+%s", route2)) 101 Eventually(session).Should(Exit(0)) 102 }) 103 104 session := helpers.CF("app", app) 105 Eventually(session).Should(Say("name:\\s+%s", app)) 106 Eventually(session).Should(Say("routes:\\s+(%s, %s)|(%s, %s)", route1, route2, route2, route1)) 107 Eventually(session).Should(Exit(0)) 108 }) 109 }) 110 }) 111 112 Context("when one of the routes exists", func() { 113 Context("when the route is in the current space", func() { 114 BeforeEach(func() { 115 route2.Create() 116 }) 117 118 It("creates and maps the new route; maps the old route", func() { 119 helpers.WithHelloWorldApp(func(dir string) { 120 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 121 "applications": []map[string]interface{}{ 122 { 123 "name": app, 124 "routes": []map[string]string{ 125 {"route": route1.String()}, 126 {"route": route2.String()}, 127 }, 128 }, 129 }, 130 }) 131 132 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 133 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 134 135 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 136 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", app)) 137 Eventually(session).Should(Say("\\s+routes:")) 138 Eventually(session).Should(Say("(?i)\\+\\s+%s", route1)) 139 Eventually(session).Should(Say("(?i)\\+\\s+%s", route2)) 140 Eventually(session).Should(Exit(0)) 141 }) 142 143 session := helpers.CF("app", app) 144 Eventually(session).Should(Say("name:\\s+%s", app)) 145 Eventually(session).Should(Say("routes:\\s+(%s, %s)|(%s, %s)", route1, route2, route2, route1)) 146 Eventually(session).Should(Exit(0)) 147 }) 148 }) 149 150 Context("when the route is in a different space", func() { 151 BeforeEach(func() { 152 otherSpace := helpers.NewSpaceName() 153 helpers.CreateSpace(otherSpace) 154 route2.Space = otherSpace 155 route2.Create() 156 }) 157 158 It("returns an error", func() { 159 helpers.WithHelloWorldApp(func(dir string) { 160 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 161 "applications": []map[string]interface{}{ 162 { 163 "name": app, 164 "routes": []map[string]string{ 165 {"route": route1.String()}, 166 {"route": route2.String()}, 167 }, 168 }, 169 }, 170 }) 171 172 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 173 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 174 Eventually(session.Err).Should(Say("The app cannot be mapped to route %s because the route is not in this space. Apps must be mapped to routes in the same space.", route2)) 175 Eventually(session).Should(Exit(1)) 176 }) 177 }) 178 }) 179 }) 180 181 Context("when the route contains a port", func() { 182 BeforeEach(func() { 183 route1.Port = 1234 184 }) 185 186 It("returns an error", func() { 187 helpers.WithHelloWorldApp(func(dir string) { 188 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 189 "applications": []map[string]interface{}{ 190 { 191 "name": app, 192 "routes": []map[string]string{ 193 {"route": route1.String()}, 194 {"route": route2.String()}, 195 }, 196 }, 197 }, 198 }) 199 200 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 201 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 202 Eventually(session.Err).Should(Say("Port not allowed in HTTP domain %s", domain.Name)) 203 Eventually(session).Should(Exit(1)) 204 }) 205 }) 206 }) 207 }) 208 209 Context("when the route has a path", func() { 210 211 Context("when the route is new", func() { 212 It("creates and maps the route", func() { 213 helpers.WithHelloWorldApp(func(dir string) { 214 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 215 "applications": []map[string]interface{}{ 216 { 217 "name": app, 218 "routes": []map[string]string{ 219 {"route": routeWithPath.String()}, 220 }, 221 }, 222 }, 223 }) 224 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 225 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 226 227 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 228 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", app)) 229 Eventually(session).Should(Say("\\s+routes:")) 230 Eventually(session).Should(Say("(?i)\\+\\s+%s", routeWithPath)) 231 Eventually(session).Should(Exit(0)) 232 }) 233 234 session := helpers.CF("app", app) 235 Eventually(session).Should(Say("name:\\s+%s", app)) 236 Eventually(session).Should(Say("routes:\\s+%s", routeWithPath)) 237 Eventually(session).Should(Exit(0)) 238 }) 239 240 // This test refers to this dev consideration [https://www.pivotaltracker.com/story/show/126256733/comments/181122853] 241 Context("when a route with the same hostname and domain exists", func() { 242 var routeWithoutPath helpers.Route 243 244 BeforeEach(func() { 245 routeWithoutPath = routeWithPath 246 routeWithoutPath.Path = "" 247 248 routeWithoutPath.Create() 249 }) 250 251 It("creates and maps the route", func() { 252 helpers.WithHelloWorldApp(func(dir string) { 253 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 254 "applications": []map[string]interface{}{ 255 { 256 "name": app, 257 "routes": []map[string]string{ 258 {"route": routeWithPath.String()}, 259 }, 260 }, 261 }, 262 }) 263 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 264 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 265 266 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 267 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", app)) 268 Eventually(session).Should(Say("\\s+routes:")) 269 Eventually(session).Should(Say("(?i)\\+\\s+%s", routeWithPath)) 270 Eventually(session).Should(Exit(0)) 271 }) 272 273 session := helpers.CF("app", app) 274 Eventually(session).Should(Say("name:\\s+%s", app)) 275 Eventually(session).Should(Say("routes:\\s+%s", routeWithPath)) 276 Eventually(session).Should(Exit(0)) 277 }) 278 }) 279 }) 280 281 Context("when the route exists", func() { 282 Context("when the route exists in the same space", func() { 283 BeforeEach(func() { 284 routeWithPath.Create() 285 }) 286 287 It("creates and maps the new route; maps the old route", func() { 288 helpers.WithHelloWorldApp(func(dir string) { 289 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 290 "applications": []map[string]interface{}{ 291 { 292 "name": app, 293 "routes": []map[string]string{ 294 {"route": routeWithPath.String()}, 295 }, 296 }, 297 }, 298 }) 299 300 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 301 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 302 303 Eventually(session).Should(Say("Creating app with these attributes\\.\\.\\.")) 304 Eventually(session).Should(Say("\\+\\s+name:\\s+%s", app)) 305 Eventually(session).Should(Say("\\s+routes:")) 306 Eventually(session).Should(Say("(?i)\\+\\s+%s", routeWithPath)) 307 Eventually(session).Should(Exit(0)) 308 }) 309 310 session := helpers.CF("app", app) 311 Eventually(session).Should(Say("name:\\s+%s", app)) 312 Eventually(session).Should(Say("routes:\\s+%s", routeWithPath)) 313 Eventually(session).Should(Exit(0)) 314 }) 315 }) 316 317 Context("when the route exists in another space", func() { 318 BeforeEach(func() { 319 otherSpace := helpers.NewSpaceName() 320 helpers.CreateSpace(otherSpace) 321 routeWithPath.Space = otherSpace 322 routeWithPath.Create() 323 }) 324 325 It("returns an error", func() { 326 helpers.WithHelloWorldApp(func(dir string) { 327 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 328 "applications": []map[string]interface{}{ 329 { 330 "name": app, 331 "routes": []map[string]string{ 332 {"route": routeWithPath.String()}, 333 }, 334 }, 335 }, 336 }) 337 338 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 339 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 340 Eventually(session.Err).Should(Say("The app cannot be mapped to route %s because the route is not in this space. Apps must be mapped to routes in the same space.", routeWithPath)) 341 Eventually(session).Should(Exit(1)) 342 }) 343 }) 344 }) 345 }) 346 }) 347 }) 348 349 Context("when the domain does not exist", func() { 350 It("returns an error", func() { 351 helpers.WithHelloWorldApp(func(dir string) { 352 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 353 "applications": []map[string]interface{}{ 354 { 355 "name": app, 356 "routes": []map[string]string{ 357 {"route": route1.String()}, 358 {"route": route2.String()}, 359 }, 360 }, 361 }, 362 }) 363 364 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start") 365 Eventually(session).Should(Say("Getting app info\\.\\.\\.")) 366 Eventually(session.Err).Should(Say("The route %s did not match any existing domains.", route1)) 367 Eventually(session).Should(Exit(1)) 368 }) 369 }) 370 }) 371 })