github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/api/router/router_group_test.go (about) 1 package router_test 2 3 import ( 4 "net/http" 5 6 . "code.cloudfoundry.org/cli/api/router" 7 "code.cloudfoundry.org/cli/api/router/routererror" 8 "code.cloudfoundry.org/cli/api/router/wrapper" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("Router Groups", func() { 15 Describe("GetRouterGroupsByName", func() { 16 var ( 17 client *Client 18 fakeConfig Config 19 routerGroup RouterGroup 20 executeErr error 21 routerGroupName string 22 ) 23 24 JustBeforeEach(func() { 25 fakeConfig = NewTestConfig() 26 fakeConfig.Wrappers = append([]ConnectionWrapper{wrapper.NewErrorWrapper()}, fakeConfig.Wrappers...) 27 client = NewTestRouterClient(fakeConfig) 28 routerGroup, executeErr = client.GetRouterGroupByName(routerGroupName) 29 }) 30 31 When("the request fails", func() { 32 BeforeEach(func() { 33 response := `{"name":"ResourceNotFoundError","message":"Router Group 'not-a-real-router-group' not found"}` 34 server.AppendHandlers( 35 CombineHandlers( 36 VerifyRequest(http.MethodGet, "/routing/v1/router_groups"), 37 VerifyHeaderKV("Content-Type", "application/json"), 38 RespondWith(http.StatusNotFound, response), 39 )) 40 }) 41 42 It("returns the error", func() { 43 Expect(executeErr).To(HaveOccurred()) 44 expectedErr := routererror.ResourceNotFoundError{ 45 Message: "Router Group 'not-a-real-router-group' not found", 46 } 47 Expect(executeErr).To(MatchError(expectedErr)) 48 Expect(routerGroup).To(Equal(RouterGroup{})) 49 }) 50 }) 51 52 When("the request succeeds", func() { 53 BeforeEach(func() { 54 response := `[ 55 { 56 "guid":"some-router-group-guid-1", 57 "name":"some-router-group", 58 "type":"tcp", 59 "reservable_ports":"1024-1123" 60 } 61 ]` 62 63 server.AppendHandlers( 64 CombineHandlers( 65 VerifyRequest(http.MethodGet, "/routing/v1/router_groups", "name=some-router-group"), 66 VerifyHeaderKV("Content-Type", "application/json"), 67 RespondWith(http.StatusOK, response), 68 )) 69 routerGroupName = "some-router-group" 70 }) 71 72 It("returns the list of router groups and no errors", func() { 73 Expect(executeErr).NotTo(HaveOccurred()) 74 Expect(routerGroup).To(Equal(RouterGroup{ 75 GUID: "some-router-group-guid-1", 76 Name: "some-router-group", 77 Type: "tcp", 78 ReservablePorts: "1024-1123", 79 })) 80 }) 81 }) 82 }) 83 })