github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/api/cloudcontroller/ccv2/route_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 7 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("Route", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client = NewTestClient() 18 }) 19 20 Describe("BindRouteToApplication", func() { 21 Context("when route binding is successful", func() { 22 BeforeEach(func() { 23 response := ` 24 { 25 "metadata": { 26 "guid": "some-route-guid" 27 }, 28 "entity": { 29 "domain_guid": "some-domain-guid", 30 "host": "some-host", 31 "path": "some-path", 32 "port": 42, 33 "space_guid": "some-space-guid" 34 } 35 }` 36 server.AppendHandlers( 37 CombineHandlers( 38 VerifyRequest(http.MethodPut, "/v2/routes/some-route-guid/apps/some-app-guid"), 39 RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 40 ), 41 ) 42 }) 43 44 It("returns the route and warnings", func() { 45 route, warnings, err := client.BindRouteToApplication("some-route-guid", "some-app-guid") 46 Expect(err).ToNot(HaveOccurred()) 47 Expect(warnings).To(ConsistOf("this is a warning")) 48 49 Expect(route).To(Equal(Route{ 50 DomainGUID: "some-domain-guid", 51 GUID: "some-route-guid", 52 Host: "some-host", 53 Path: "some-path", 54 Port: 42, 55 SpaceGUID: "some-space-guid", 56 })) 57 }) 58 }) 59 60 Context("when the cc returns an error", func() { 61 BeforeEach(func() { 62 response := `{ 63 "code": 10001, 64 "description": "Some Error", 65 "error_code": "CF-SomeError" 66 }` 67 server.AppendHandlers( 68 CombineHandlers( 69 VerifyRequest(http.MethodPut, "/v2/routes/some-route-guid/apps/some-app-guid"), 70 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 71 ), 72 ) 73 }) 74 75 It("returns an error", func() { 76 _, warnings, err := client.BindRouteToApplication("some-route-guid", "some-app-guid") 77 Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{ 78 ResponseCode: http.StatusTeapot, 79 V2ErrorResponse: ccerror.V2ErrorResponse{ 80 Code: 10001, 81 Description: "Some Error", 82 ErrorCode: "CF-SomeError", 83 }, 84 })) 85 Expect(warnings).To(ConsistOf("this is a warning")) 86 }) 87 }) 88 }) 89 90 Describe("CreateRoute", func() { 91 Context("when route creation is successful", func() { 92 Context("when generate route is true", func() { 93 BeforeEach(func() { 94 response := ` 95 { 96 "metadata": { 97 "guid": "some-route-guid" 98 }, 99 "entity": { 100 "domain_guid": "some-domain-guid", 101 "host": "some-host", 102 "path": "some-path", 103 "port": 100000, 104 "space_guid": "some-space-guid" 105 } 106 }` 107 requestBody := map[string]interface{}{ 108 "domain_guid": "some-domain-guid", 109 "host": "some-host", 110 "path": "some-path", 111 "port": 42, 112 "space_guid": "some-space-guid", 113 } 114 server.AppendHandlers( 115 CombineHandlers( 116 VerifyRequest(http.MethodPost, "/v2/routes", "generate_port=true"), 117 VerifyJSONRepresenting(requestBody), 118 RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 119 ), 120 ) 121 }) 122 123 It("creates the route with a random port", func() { 124 route, warnings, err := client.CreateRoute(Route{ 125 DomainGUID: "some-domain-guid", 126 Host: "some-host", 127 Path: "some-path", 128 Port: 42, 129 SpaceGUID: "some-space-guid", 130 }, true) 131 132 Expect(err).ToNot(HaveOccurred()) 133 Expect(warnings).To(ConsistOf("this is a warning")) 134 Expect(route).To(Equal(Route{ 135 DomainGUID: "some-domain-guid", 136 GUID: "some-route-guid", 137 Host: "some-host", 138 Path: "some-path", 139 Port: 100000, 140 SpaceGUID: "some-space-guid", 141 })) 142 }) 143 }) 144 145 Context("when generate route is false", func() { 146 BeforeEach(func() { 147 response := ` 148 { 149 "metadata": { 150 "guid": "some-route-guid" 151 }, 152 "entity": { 153 "domain_guid": "some-domain-guid", 154 "host": "some-host", 155 "path": "some-path", 156 "port": 42, 157 "space_guid": "some-space-guid" 158 } 159 }` 160 requestBody := map[string]interface{}{ 161 "domain_guid": "some-domain-guid", 162 "host": "some-host", 163 "path": "some-path", 164 "port": 42, 165 "space_guid": "some-space-guid", 166 } 167 server.AppendHandlers( 168 CombineHandlers( 169 VerifyRequest(http.MethodPost, "/v2/routes"), 170 VerifyJSONRepresenting(requestBody), 171 RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 172 ), 173 ) 174 }) 175 176 It("creates the route with the given port", func() { 177 route, warnings, err := client.CreateRoute(Route{ 178 DomainGUID: "some-domain-guid", 179 Host: "some-host", 180 Path: "some-path", 181 Port: 42, 182 SpaceGUID: "some-space-guid", 183 }, false) 184 185 Expect(err).ToNot(HaveOccurred()) 186 Expect(warnings).To(ConsistOf("this is a warning")) 187 Expect(route).To(Equal(Route{ 188 DomainGUID: "some-domain-guid", 189 GUID: "some-route-guid", 190 Host: "some-host", 191 Path: "some-path", 192 Port: 42, 193 SpaceGUID: "some-space-guid", 194 })) 195 }) 196 }) 197 198 Context("when sending a basic route", func() { 199 BeforeEach(func() { 200 response := ` 201 { 202 "metadata": { 203 "guid": "some-route-guid" 204 }, 205 "entity": { 206 "domain_guid": "some-domain-guid", 207 "space_guid": "some-space-guid" 208 } 209 }` 210 requestBody := map[string]interface{}{ 211 "domain_guid": "some-domain-guid", 212 "space_guid": "some-space-guid", 213 } 214 server.AppendHandlers( 215 CombineHandlers( 216 VerifyRequest(http.MethodPost, "/v2/routes"), 217 VerifyJSONRepresenting(requestBody), 218 RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 219 ), 220 ) 221 }) 222 223 It("creates the route with only the space and domain guids", func() { 224 route, warnings, err := client.CreateRoute(Route{ 225 DomainGUID: "some-domain-guid", 226 SpaceGUID: "some-space-guid", 227 }, false) 228 229 Expect(err).ToNot(HaveOccurred()) 230 Expect(warnings).To(ConsistOf("this is a warning")) 231 Expect(route).To(Equal(Route{ 232 DomainGUID: "some-domain-guid", 233 GUID: "some-route-guid", 234 SpaceGUID: "some-space-guid", 235 })) 236 }) 237 }) 238 }) 239 240 Context("when the cc returns an error", func() { 241 BeforeEach(func() { 242 response := `{ 243 "code": 10001, 244 "description": "Some Error", 245 "error_code": "CF-SomeError" 246 }` 247 server.AppendHandlers( 248 CombineHandlers( 249 VerifyRequest(http.MethodPost, "/v2/routes"), 250 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 251 ), 252 ) 253 }) 254 255 It("returns an error", func() { 256 _, warnings, err := client.CreateRoute(Route{}, false) 257 Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{ 258 ResponseCode: http.StatusTeapot, 259 V2ErrorResponse: ccerror.V2ErrorResponse{ 260 Code: 10001, 261 Description: "Some Error", 262 ErrorCode: "CF-SomeError", 263 }, 264 })) 265 Expect(warnings).To(ConsistOf("this is a warning")) 266 }) 267 }) 268 }) 269 270 Describe("GetRoutes", func() { 271 Context("when there are routes", func() { 272 BeforeEach(func() { 273 response1 := `{ 274 "next_url": "/v2/routes?q=organization_guid:some-org-guid&page=2", 275 "resources": [ 276 { 277 "metadata": { 278 "guid": "route-guid-1", 279 "updated_at": null 280 }, 281 "entity": { 282 "host": "host-1", 283 "path": "path", 284 "port": null, 285 "domain_guid": "some-http-domain", 286 "space_guid": "some-space-guid-1" 287 } 288 }, 289 { 290 "metadata": { 291 "guid": "route-guid-2", 292 "updated_at": null 293 }, 294 "entity": { 295 "host": "host-2", 296 "path": "", 297 "port": 3333, 298 "domain_guid": "some-tcp-domain", 299 "space_guid": "some-space-guid-1" 300 } 301 } 302 ] 303 }` 304 response2 := `{ 305 "next_url": null, 306 "resources": [ 307 { 308 "metadata": { 309 "guid": "route-guid-3", 310 "updated_at": null 311 }, 312 "entity": { 313 "host": "host-3", 314 "path": "path", 315 "port": null, 316 "domain_guid": "some-http-domain", 317 "space_guid": "some-space-guid-2" 318 } 319 }, 320 { 321 "metadata": { 322 "guid": "route-guid-4", 323 "updated_at": null 324 }, 325 "entity": { 326 "host": "host-4", 327 "path": "", 328 "port": 333, 329 "domain_guid": "some-tcp-domain", 330 "space_guid": "some-space-guid-2" 331 } 332 } 333 ] 334 }` 335 server.AppendHandlers( 336 CombineHandlers( 337 VerifyRequest(http.MethodGet, "/v2/routes", "q=organization_guid:some-org-guid"), 338 RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 339 ), 340 ) 341 server.AppendHandlers( 342 CombineHandlers( 343 VerifyRequest(http.MethodGet, "/v2/routes", "q=organization_guid:some-org-guid&page=2"), 344 RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}), 345 ), 346 ) 347 }) 348 349 It("returns all the routes and all warnings", func() { 350 routes, warnings, err := client.GetRoutes([]Query{{ 351 Filter: OrganizationGUIDFilter, 352 Operator: EqualOperator, 353 Value: "some-org-guid", 354 }}) 355 Expect(err).NotTo(HaveOccurred()) 356 Expect(routes).To(ConsistOf([]Route{ 357 { 358 GUID: "route-guid-1", 359 Host: "host-1", 360 Path: "path", 361 Port: 0, 362 DomainGUID: "some-http-domain", 363 SpaceGUID: "some-space-guid-1", 364 }, 365 { 366 GUID: "route-guid-2", 367 Host: "host-2", 368 Path: "", 369 Port: 3333, 370 DomainGUID: "some-tcp-domain", 371 SpaceGUID: "some-space-guid-1", 372 }, 373 { 374 GUID: "route-guid-3", 375 Host: "host-3", 376 Path: "path", 377 Port: 0, 378 DomainGUID: "some-http-domain", 379 SpaceGUID: "some-space-guid-2", 380 }, 381 { 382 GUID: "route-guid-4", 383 Host: "host-4", 384 Path: "", 385 Port: 333, 386 DomainGUID: "some-tcp-domain", 387 SpaceGUID: "some-space-guid-2", 388 }, 389 })) 390 Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"})) 391 }) 392 }) 393 394 Context("when the cc returns an error", func() { 395 BeforeEach(func() { 396 response := `{ 397 "code": 10001, 398 "description": "Some Error", 399 "error_code": "CF-SomeError" 400 }` 401 server.AppendHandlers( 402 CombineHandlers( 403 VerifyRequest(http.MethodGet, "/v2/routes"), 404 RespondWith(http.StatusTeapot, response), 405 ), 406 ) 407 }) 408 409 It("returns an error", func() { 410 _, _, err := client.GetRoutes(nil) 411 Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{ 412 ResponseCode: http.StatusTeapot, 413 V2ErrorResponse: ccerror.V2ErrorResponse{ 414 Code: 10001, 415 Description: "Some Error", 416 ErrorCode: "CF-SomeError", 417 }, 418 })) 419 }) 420 }) 421 }) 422 423 Describe("GetApplicationRoutes", func() { 424 Context("when there are routes in this space", func() { 425 BeforeEach(func() { 426 response1 := `{ 427 "next_url": "/v2/apps/some-app-guid/routes?q=organization_guid:some-org-guid&page=2", 428 "resources": [ 429 { 430 "metadata": { 431 "guid": "route-guid-1", 432 "updated_at": null 433 }, 434 "entity": { 435 "host": "host-1", 436 "path": "path", 437 "port": null, 438 "domain_guid": "some-http-domain", 439 "space_guid": "some-space-guid-1" 440 } 441 }, 442 { 443 "metadata": { 444 "guid": "route-guid-2", 445 "updated_at": null 446 }, 447 "entity": { 448 "host": "host-2", 449 "path": "", 450 "port": 3333, 451 "domain_guid": "some-tcp-domain", 452 "space_guid": "some-space-guid-1" 453 } 454 } 455 ] 456 }` 457 response2 := `{ 458 "next_url": null, 459 "resources": [ 460 { 461 "metadata": { 462 "guid": "route-guid-3", 463 "updated_at": null 464 }, 465 "entity": { 466 "host": "host-3", 467 "path": "path", 468 "port": null, 469 "domain_guid": "some-http-domain", 470 "space_guid": "some-space-guid-1" 471 } 472 }, 473 { 474 "metadata": { 475 "guid": "route-guid-4", 476 "updated_at": null 477 }, 478 "entity": { 479 "host": "host-4", 480 "path": "", 481 "port": 333, 482 "domain_guid": "some-tcp-domain", 483 "space_guid": "some-space-guid-1" 484 } 485 } 486 ] 487 }` 488 server.AppendHandlers( 489 CombineHandlers( 490 VerifyRequest(http.MethodGet, "/v2/apps/some-app-guid/routes", "q=organization_guid:some-org-guid"), 491 RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 492 ), 493 ) 494 server.AppendHandlers( 495 CombineHandlers( 496 VerifyRequest(http.MethodGet, "/v2/apps/some-app-guid/routes", "q=organization_guid:some-org-guid&page=2"), 497 RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}), 498 ), 499 ) 500 }) 501 502 It("returns all the routes and all warnings", func() { 503 routes, warnings, err := client.GetApplicationRoutes("some-app-guid", []Query{{ 504 Filter: OrganizationGUIDFilter, 505 Operator: EqualOperator, 506 Value: "some-org-guid", 507 }}) 508 Expect(err).NotTo(HaveOccurred()) 509 Expect(routes).To(ConsistOf([]Route{ 510 { 511 GUID: "route-guid-1", 512 Host: "host-1", 513 Path: "path", 514 Port: 0, 515 DomainGUID: "some-http-domain", 516 SpaceGUID: "some-space-guid-1", 517 }, 518 { 519 GUID: "route-guid-2", 520 Host: "host-2", 521 Path: "", 522 Port: 3333, 523 DomainGUID: "some-tcp-domain", 524 SpaceGUID: "some-space-guid-1", 525 }, 526 { 527 GUID: "route-guid-3", 528 Host: "host-3", 529 Path: "path", 530 Port: 0, 531 DomainGUID: "some-http-domain", 532 SpaceGUID: "some-space-guid-1", 533 }, 534 { 535 GUID: "route-guid-4", 536 Host: "host-4", 537 Path: "", 538 Port: 333, 539 DomainGUID: "some-tcp-domain", 540 SpaceGUID: "some-space-guid-1", 541 }, 542 })) 543 Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"})) 544 }) 545 }) 546 547 Context("when there are no routes bound to the app", func() { 548 BeforeEach(func() { 549 response := `{ 550 "next_url": "", 551 "resources": [] 552 }` 553 server.AppendHandlers( 554 CombineHandlers( 555 VerifyRequest(http.MethodGet, "/v2/apps/some-app-guid/routes"), 556 RespondWith(http.StatusOK, response), 557 ), 558 ) 559 }) 560 561 It("returns an empty list of routes", func() { 562 routes, _, err := client.GetApplicationRoutes("some-app-guid", nil) 563 Expect(err).NotTo(HaveOccurred()) 564 Expect(routes).To(BeEmpty()) 565 }) 566 }) 567 568 Context("when the app is not found", func() { 569 BeforeEach(func() { 570 response := `{ 571 "code": 10000, 572 "description": "The app could not be found: some-app-guid", 573 "error_code": "CF-AppNotFound" 574 }` 575 server.AppendHandlers( 576 CombineHandlers( 577 VerifyRequest(http.MethodGet, "/v2/apps/some-app-guid/routes"), 578 RespondWith(http.StatusNotFound, response), 579 ), 580 ) 581 }) 582 583 It("returns an error", func() { 584 routes, _, err := client.GetApplicationRoutes("some-app-guid", nil) 585 Expect(err).To(MatchError(ccerror.ResourceNotFoundError{ 586 Message: "The app could not be found: some-app-guid", 587 })) 588 Expect(routes).To(BeEmpty()) 589 }) 590 }) 591 }) 592 593 Describe("GetSpaceRoutes", func() { 594 Context("when there are routes in this space", func() { 595 BeforeEach(func() { 596 response1 := `{ 597 "next_url": "/v2/spaces/some-space-guid/routes?q=space_guid:some-space-guid&page=2", 598 "resources": [ 599 { 600 "metadata": { 601 "guid": "route-guid-1", 602 "updated_at": null 603 }, 604 "entity": { 605 "host": "host-1", 606 "path": "path", 607 "port": null, 608 "domain_guid": "some-http-domain", 609 "space_guid": "some-space-guid-1" 610 } 611 }, 612 { 613 "metadata": { 614 "guid": "route-guid-2", 615 "updated_at": null 616 }, 617 "entity": { 618 "host": "host-2", 619 "path": "", 620 "port": 3333, 621 "domain_guid": "some-tcp-domain", 622 "space_guid": "some-space-guid-1" 623 } 624 } 625 ] 626 }` 627 response2 := `{ 628 "next_url": null, 629 "resources": [ 630 { 631 "metadata": { 632 "guid": "route-guid-3", 633 "updated_at": null 634 }, 635 "entity": { 636 "host": "host-3", 637 "path": "path", 638 "port": null, 639 "domain_guid": "some-http-domain", 640 "space_guid": "some-space-guid-1" 641 } 642 }, 643 { 644 "metadata": { 645 "guid": "route-guid-4", 646 "updated_at": null 647 }, 648 "entity": { 649 "host": "host-4", 650 "path": "", 651 "port": 333, 652 "domain_guid": "some-tcp-domain", 653 "space_guid": "some-space-guid-1" 654 } 655 } 656 ] 657 }` 658 server.AppendHandlers( 659 CombineHandlers( 660 VerifyRequest(http.MethodGet, "/v2/spaces/some-space-guid/routes", "q=space_guid:some-space-guid"), 661 RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 662 ), 663 ) 664 server.AppendHandlers( 665 CombineHandlers( 666 VerifyRequest(http.MethodGet, "/v2/spaces/some-space-guid/routes", "q=space_guid:some-space-guid&page=2"), 667 RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}), 668 ), 669 ) 670 }) 671 672 It("returns all the routes and all warnings", func() { 673 routes, warnings, err := client.GetSpaceRoutes("some-space-guid", []Query{{ 674 Filter: SpaceGUIDFilter, 675 Operator: EqualOperator, 676 Value: "some-space-guid", 677 }}) 678 Expect(err).NotTo(HaveOccurred()) 679 Expect(routes).To(ConsistOf([]Route{ 680 { 681 GUID: "route-guid-1", 682 Host: "host-1", 683 Path: "path", 684 Port: 0, 685 DomainGUID: "some-http-domain", 686 SpaceGUID: "some-space-guid-1", 687 }, 688 { 689 GUID: "route-guid-2", 690 Host: "host-2", 691 Path: "", 692 Port: 3333, 693 DomainGUID: "some-tcp-domain", 694 SpaceGUID: "some-space-guid-1", 695 }, 696 { 697 GUID: "route-guid-3", 698 Host: "host-3", 699 Path: "path", 700 Port: 0, 701 DomainGUID: "some-http-domain", 702 SpaceGUID: "some-space-guid-1", 703 }, 704 { 705 GUID: "route-guid-4", 706 Host: "host-4", 707 Path: "", 708 Port: 333, 709 DomainGUID: "some-tcp-domain", 710 SpaceGUID: "some-space-guid-1", 711 }, 712 })) 713 Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"})) 714 }) 715 }) 716 717 Context("when there are no routes in this space", func() { 718 BeforeEach(func() { 719 response := `{ 720 "next_url": "", 721 "resources": [] 722 }` 723 server.AppendHandlers( 724 CombineHandlers( 725 VerifyRequest(http.MethodGet, "/v2/spaces/some-space-guid/routes"), 726 RespondWith(http.StatusOK, response), 727 ), 728 ) 729 }) 730 731 It("returns an empty list of routes", func() { 732 routes, _, err := client.GetSpaceRoutes("some-space-guid", nil) 733 Expect(err).NotTo(HaveOccurred()) 734 Expect(routes).To(BeEmpty()) 735 }) 736 }) 737 738 Context("when the space is not found", func() { 739 BeforeEach(func() { 740 response := `{ 741 "code": 40004, 742 "description": "The app space could not be found: some-space-guid", 743 "error_code": "CF-SpaceNotFound" 744 }` 745 server.AppendHandlers( 746 CombineHandlers( 747 VerifyRequest(http.MethodGet, "/v2/spaces/some-space-guid/routes"), 748 RespondWith(http.StatusNotFound, response), 749 ), 750 ) 751 }) 752 753 It("returns an error", func() { 754 routes, _, err := client.GetSpaceRoutes("some-space-guid", nil) 755 Expect(err).To(MatchError(ccerror.ResourceNotFoundError{ 756 Message: "The app space could not be found: some-space-guid", 757 })) 758 Expect(routes).To(BeEmpty()) 759 }) 760 }) 761 }) 762 763 Describe("DeleteRoute", func() { 764 Context("when the route exists", func() { 765 BeforeEach(func() { 766 server.AppendHandlers( 767 CombineHandlers( 768 VerifyRequest(http.MethodDelete, "/v2/routes/some-route-guid"), 769 RespondWith(http.StatusNoContent, "{}", http.Header{"X-Cf-Warnings": {"this is a warning"}}), 770 ), 771 ) 772 }) 773 774 It("deletes the route and returns all warnings", func() { 775 warnings, err := client.DeleteRoute("some-route-guid") 776 Expect(err).NotTo(HaveOccurred()) 777 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 778 }) 779 }) 780 781 Context("when the route does not exist", func() { 782 BeforeEach(func() { 783 response := `{ 784 "code": 210002, 785 "description": "The route could not be found: some-route-guid", 786 "error_code": "CF-RouteNotFound" 787 }` 788 server.AppendHandlers( 789 CombineHandlers( 790 VerifyRequest(http.MethodDelete, "/v2/routes/some-route-guid"), 791 RespondWith(http.StatusNotFound, response), 792 ), 793 ) 794 }) 795 796 It("returns an error", func() { 797 _, err := client.DeleteRoute("some-route-guid") 798 Expect(err).To(MatchError(ccerror.ResourceNotFoundError{ 799 Message: "The route could not be found: some-route-guid", 800 })) 801 }) 802 }) 803 }) 804 805 Describe("CheckRoute", func() { 806 Context("API Version < 2.55.0", func() { 807 // Figure it out 808 }) 809 810 Context("API Version >= 2.55.0", func() { 811 BeforeEach(func() { 812 client = NewClientWithCustomAPIVersion("2.55.0") 813 }) 814 815 Context("with minimum params", func() { 816 BeforeEach(func() { 817 server.AppendHandlers( 818 CombineHandlers( 819 VerifyRequest(http.MethodGet, "/v2/routes/reserved/domain/some-domain-guid"), 820 RespondWith(http.StatusNoContent, "{}", http.Header{"X-Cf-Warnings": {"this is a warning"}}), 821 ), 822 ) 823 }) 824 825 It("does not contain any params", func() { 826 _, warnings, err := client.CheckRoute(Route{DomainGUID: "some-domain-guid"}) 827 Expect(err).NotTo(HaveOccurred()) 828 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 829 }) 830 }) 831 832 Context("with all the params", func() { 833 BeforeEach(func() { 834 server.AppendHandlers( 835 CombineHandlers( 836 VerifyRequest(http.MethodGet, "/v2/routes/reserved/domain/some-domain-guid", "host=some-host&path=some-path&port=42"), 837 RespondWith(http.StatusNoContent, "{}", http.Header{"X-Cf-Warnings": {"this is a warning"}}), 838 ), 839 ) 840 }) 841 842 It("contains all requested parameters", func() { 843 exists, warnings, err := client.CheckRoute(Route{ 844 Host: "some-host", 845 DomainGUID: "some-domain-guid", 846 Path: "some-path", 847 Port: 42, 848 }) 849 Expect(err).NotTo(HaveOccurred()) 850 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 851 Expect(exists).To(BeTrue()) 852 }) 853 }) 854 855 Context("when the route exists", func() { 856 BeforeEach(func() { 857 server.AppendHandlers( 858 CombineHandlers( 859 VerifyRequest(http.MethodGet, "/v2/routes/reserved/domain/some-domain-guid", "host=some-host"), 860 RespondWith(http.StatusNoContent, "{}", http.Header{"X-Cf-Warnings": {"this is a warning"}}), 861 ), 862 ) 863 }) 864 865 It("returns true", func() { 866 exists, warnings, err := client.CheckRoute(Route{Host: "some-host", DomainGUID: "some-domain-guid"}) 867 Expect(err).NotTo(HaveOccurred()) 868 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 869 Expect(exists).To(BeTrue()) 870 }) 871 }) 872 873 Context("when the route does not exist", func() { 874 BeforeEach(func() { 875 server.AppendHandlers( 876 CombineHandlers( 877 VerifyRequest(http.MethodGet, "/v2/routes/reserved/domain/some-domain-guid", "host=some-host"), 878 RespondWith(http.StatusNotFound, "{}", http.Header{"X-Cf-Warnings": {"this is a warning"}}), 879 ), 880 ) 881 }) 882 883 It("returns false", func() { 884 exists, warnings, err := client.CheckRoute(Route{Host: "some-host", DomainGUID: "some-domain-guid"}) 885 Expect(err).NotTo(HaveOccurred()) 886 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 887 Expect(exists).To(BeFalse()) 888 }) 889 }) 890 891 Context("when the CC errors", func() { 892 BeforeEach(func() { 893 response := `{ 894 "code": 777, 895 "description": "The route could not be found: some-route-guid", 896 "error_code": "CF-WUT" 897 }` 898 server.AppendHandlers( 899 CombineHandlers( 900 VerifyRequest(http.MethodGet, "/v2/routes/reserved/domain/some-domain-guid", "host=some-host"), 901 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 902 ), 903 ) 904 }) 905 906 It("returns the error", func() { 907 _, warnings, err := client.CheckRoute(Route{Host: "some-host", DomainGUID: "some-domain-guid"}) 908 Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{ 909 V2ErrorResponse: ccerror.V2ErrorResponse{ 910 Code: 777, 911 Description: "The route could not be found: some-route-guid", 912 ErrorCode: "CF-WUT", 913 }, 914 ResponseCode: http.StatusTeapot, 915 })) 916 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 917 }) 918 }) 919 }) 920 }) 921 })