github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/router_group_test.go (about) 1 package v7action_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 . "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 9 "code.cloudfoundry.org/cli/api/router" 10 "code.cloudfoundry.org/cli/api/router/routererror" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Router Group Actions", func() { 16 var ( 17 actor *Actor 18 fakeRoutingClient *v7actionfakes.FakeRoutingClient 19 executeErr error 20 ) 21 22 BeforeEach(func() { 23 fakeRoutingClient = new(v7actionfakes.FakeRoutingClient) 24 actor = NewActor(nil, nil, nil, nil, fakeRoutingClient, nil) 25 }) 26 27 Describe("GetRouterGroups", func() { 28 var ( 29 routerGroups []RouterGroup 30 ) 31 32 When("the request succeeds", func() { 33 BeforeEach(func() { 34 fakeRoutingClient.GetRouterGroupsReturns( 35 []router.RouterGroup{ 36 {Name: "router-group-name-1"}, 37 {Name: "router-group-name-2"}, 38 }, 39 nil, 40 ) 41 }) 42 43 JustBeforeEach(func() { 44 routerGroups, executeErr = actor.GetRouterGroups() 45 Expect(executeErr).ToNot(HaveOccurred()) 46 }) 47 48 It("returns the router groups", func() { 49 Expect(routerGroups).To(Equal( 50 []RouterGroup{ 51 {Name: "router-group-name-1"}, 52 {Name: "router-group-name-2"}, 53 }, 54 )) 55 56 Expect(fakeRoutingClient.GetRouterGroupsCallCount()).To(Equal(1)) 57 }) 58 }) 59 60 When("the request errors", func() { 61 var expectedError error 62 63 BeforeEach(func() { 64 expectedError = errors.New("I am a Routing API Error") 65 66 fakeRoutingClient.GetRouterGroupsReturns( 67 nil, 68 expectedError, 69 ) 70 }) 71 72 JustBeforeEach(func() { 73 routerGroups, executeErr = actor.GetRouterGroups() 74 }) 75 76 It("returns the error", func() { 77 Expect(executeErr).To(MatchError(expectedError)) 78 }) 79 }) 80 }) 81 82 Describe("GetRouterGroupByName", func() { 83 var ( 84 routerGroup RouterGroup 85 name string 86 ) 87 88 When("the request succeeds", func() { 89 BeforeEach(func() { 90 name = "router-group-name-1" 91 92 fakeRoutingClient.GetRouterGroupByNameReturns( 93 router.RouterGroup{Name: name}, 94 nil, 95 ) 96 }) 97 98 JustBeforeEach(func() { 99 routerGroup, executeErr = actor.GetRouterGroupByName(name) 100 Expect(executeErr).ToNot(HaveOccurred()) 101 }) 102 103 It("returns the router groups", func() { 104 Expect(routerGroup).To(Equal( 105 RouterGroup{ 106 Name: "router-group-name-1", 107 }, 108 )) 109 110 Expect(fakeRoutingClient.GetRouterGroupByNameCallCount()).To(Equal(1)) 111 givenName := fakeRoutingClient.GetRouterGroupByNameArgsForCall(0) 112 Expect(givenName).To(Equal(name)) 113 }) 114 }) 115 116 When("there are no router groups found", func() { 117 BeforeEach(func() { 118 name = "router-group-name-1" 119 120 fakeRoutingClient.GetRouterGroupByNameReturns( 121 router.RouterGroup{}, 122 routererror.ResourceNotFoundError{}, 123 ) 124 }) 125 126 JustBeforeEach(func() { 127 routerGroup, executeErr = actor.GetRouterGroupByName(name) 128 }) 129 130 It("returns a helpful error", func() { 131 Expect(routerGroup).To(Equal(RouterGroup{})) 132 Expect(executeErr).To(MatchError(actionerror.RouterGroupNotFoundError{Name: name})) 133 }) 134 }) 135 136 When("the request errors", func() { 137 var expectedError error 138 139 BeforeEach(func() { 140 name = "router-group-name-1" 141 expectedError = errors.New("I am a CloudControllerClient Error") 142 fakeRoutingClient.GetRouterGroupByNameReturns( 143 router.RouterGroup{}, 144 expectedError, 145 ) 146 }) 147 148 JustBeforeEach(func() { 149 routerGroup, executeErr = actor.GetRouterGroupByName(name) 150 }) 151 152 It("returns the error", func() { 153 Expect(executeErr).To(MatchError(expectedError)) 154 }) 155 }) 156 }) 157 })