github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/actor/v2action/service_test.go (about)

     1  package v2action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v2action"
     7  	"code.cloudfoundry.org/cli/actor/v2action/v2actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("Service Actions", func() {
    14  	var (
    15  		actor                     *Actor
    16  		fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient)
    21  		actor = NewActor(fakeCloudControllerClient, nil, nil)
    22  	})
    23  
    24  	Describe("GetService", func() {
    25  		var (
    26  			service         Service
    27  			serviceWarnings Warnings
    28  			serviceErr      error
    29  		)
    30  
    31  		JustBeforeEach(func() {
    32  			service, serviceWarnings, serviceErr = actor.GetService("some-service-guid")
    33  		})
    34  
    35  		Context("when no errors are encountered getting the service", func() {
    36  			var returnedService ccv2.Service
    37  
    38  			BeforeEach(func() {
    39  				returnedService = ccv2.Service{
    40  					GUID:             "some-service-guid",
    41  					Label:            "some-service",
    42  					Description:      "some-description",
    43  					DocumentationURL: "some-url",
    44  				}
    45  				fakeCloudControllerClient.GetServiceReturns(
    46  					returnedService,
    47  					ccv2.Warnings{"get-service-warning"},
    48  					nil)
    49  			})
    50  
    51  			It("returns the service and all warnings", func() {
    52  				Expect(serviceErr).ToNot(HaveOccurred())
    53  				Expect(service).To(Equal(Service(returnedService)))
    54  				Expect(serviceWarnings).To(ConsistOf("get-service-warning"))
    55  
    56  				Expect(fakeCloudControllerClient.GetServiceCallCount()).To(Equal(1))
    57  				Expect(fakeCloudControllerClient.GetServiceArgsForCall(0)).To(Equal("some-service-guid"))
    58  			})
    59  		})
    60  
    61  		Context("when an error is encountered getting the service", func() {
    62  			var expectedErr error
    63  
    64  			BeforeEach(func() {
    65  				expectedErr = errors.New("some-error")
    66  				fakeCloudControllerClient.GetServiceReturns(
    67  					ccv2.Service{},
    68  					ccv2.Warnings{"get-service-warning"},
    69  					expectedErr)
    70  			})
    71  
    72  			It("returns the errors and all warnings", func() {
    73  				Expect(serviceErr).To(MatchError(expectedErr))
    74  				Expect(serviceWarnings).To(ConsistOf("get-service-warning"))
    75  
    76  				Expect(fakeCloudControllerClient.GetServiceCallCount()).To(Equal(1))
    77  				Expect(fakeCloudControllerClient.GetServiceArgsForCall(0)).To(Equal("some-service-guid"))
    78  			})
    79  		})
    80  	})
    81  })