github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/v2action/router_group_test.go (about)

     1  package v2action_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v2action"
     7  	"code.cloudfoundry.org/cli/actor/v2action/v2actionfakes"
     8  	"code.cloudfoundry.org/cli/api/router"
     9  	routererror "code.cloudfoundry.org/cli/api/router/routererror"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Router Group Actions", func() {
    15  	var (
    16  		actor            *Actor
    17  		fakeRouterClient *v2actionfakes.FakeRouterClient
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		fakeRouterClient = new(v2actionfakes.FakeRouterClient)
    22  		actor = NewActor(nil, nil, nil)
    23  	})
    24  
    25  	Describe("GetRouterGroupByName", func() {
    26  		var (
    27  			routerGroupName string
    28  			routerGroup     RouterGroup
    29  			executeErr      error
    30  		)
    31  
    32  		JustBeforeEach(func() {
    33  			routerGroup, executeErr = actor.GetRouterGroupByName(routerGroupName, fakeRouterClient)
    34  		})
    35  
    36  		When("the router group exists", func() {
    37  			BeforeEach(func() {
    38  				routerGroupName = "some-router-group-name"
    39  				fakeRouterClient.GetRouterGroupByNameReturns(
    40  					router.RouterGroup{Name: routerGroupName},
    41  					nil)
    42  			})
    43  
    44  			It("should return the router group and not an error", func() {
    45  				Expect(executeErr).ToNot(HaveOccurred())
    46  				Expect(routerGroup).To(Equal(RouterGroup{Name: routerGroupName}))
    47  				Expect(fakeRouterClient.GetRouterGroupByNameCallCount()).To(Equal(1))
    48  			})
    49  		})
    50  
    51  		When("the router client returns an error", func() {
    52  			When("it returns a ResourceNotFoundError", func() {
    53  				BeforeEach(func() {
    54  					routerGroupName = "tcp-default"
    55  					fakeRouterClient.GetRouterGroupByNameReturns(router.RouterGroup{Name: routerGroupName}, routererror.ResourceNotFoundError{Message: "Router Group not found"})
    56  				})
    57  
    58  				It("should return an error", func() {
    59  					Expect(executeErr).To(MatchError(fmt.Sprintf("Router group '%s' not found.", routerGroupName)))
    60  					Expect(fakeRouterClient.GetRouterGroupByNameCallCount()).To(Equal(1))
    61  				})
    62  			})
    63  			When("it returns a UnauthorizedError", func() {
    64  				BeforeEach(func() {
    65  					routerGroupName = "tcp-default"
    66  					fakeRouterClient.GetRouterGroupByNameReturns(router.RouterGroup{Name: routerGroupName}, routererror.InvalidAuthTokenError{Message: "You are not authorized to peform the requested action"})
    67  				})
    68  
    69  				It("should return an error", func() {
    70  					Expect(executeErr).To(MatchError("You are not authorized to peform the requested action"))
    71  					Expect(fakeRouterClient.GetRouterGroupByNameCallCount()).To(Equal(1))
    72  				})
    73  			})
    74  		})
    75  	})
    76  })