github.com/arunkumar7540/cli@v6.45.0+incompatible/actor/v7action/service_broker_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v7action"
     7  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Service Broker Actions", func() {
    15  	var (
    16  		actor                     *Actor
    17  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    22  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil)
    23  	})
    24  
    25  	Describe("GetServiceBrokers", func() {
    26  		var (
    27  			serviceBrokers []ServiceBroker
    28  			warnings       Warnings
    29  			executionError error
    30  		)
    31  
    32  		JustBeforeEach(func() {
    33  			serviceBrokers, warnings, executionError = actor.GetServiceBrokers()
    34  		})
    35  
    36  		When("the cloud controller request is successful", func() {
    37  			When("the cloud controller returns service brokers", func() {
    38  				BeforeEach(func() {
    39  					fakeCloudControllerClient.GetServiceBrokersReturns([]ccv3.ServiceBroker{
    40  						{
    41  							GUID: "service-broker-guid-1",
    42  							Name: "service-broker-1",
    43  							URL:  "service-broker-url-1",
    44  						},
    45  						{
    46  							GUID: "service-broker-guid-2",
    47  							Name: "service-broker-2",
    48  							URL:  "service-broker-url-2",
    49  						},
    50  					}, ccv3.Warnings{"some-service-broker-warning"}, nil)
    51  				})
    52  
    53  				It("returns the service brokers and warnings", func() {
    54  					Expect(executionError).NotTo(HaveOccurred())
    55  
    56  					Expect(serviceBrokers).To(ConsistOf(
    57  						ServiceBroker{Name: "service-broker-1", GUID: "service-broker-guid-1", URL: "service-broker-url-1"},
    58  						ServiceBroker{Name: "service-broker-2", GUID: "service-broker-guid-2", URL: "service-broker-url-2"},
    59  					))
    60  					Expect(warnings).To(ConsistOf("some-service-broker-warning"))
    61  					Expect(fakeCloudControllerClient.GetServiceBrokersCallCount()).To(Equal(1))
    62  				})
    63  			})
    64  		})
    65  
    66  		When("the cloud controller returns an error", func() {
    67  			BeforeEach(func() {
    68  				fakeCloudControllerClient.GetServiceBrokersReturns(
    69  					nil,
    70  					ccv3.Warnings{"some-service-broker-warning"},
    71  					errors.New("no service broker"))
    72  			})
    73  
    74  			It("returns an error and warnings", func() {
    75  				Expect(executionError).To(MatchError("no service broker"))
    76  				Expect(warnings).To(ConsistOf("some-service-broker-warning"))
    77  			})
    78  		})
    79  	})
    80  
    81  	Describe("CreateServiceBroker", func() {
    82  		var (
    83  			warnings       Warnings
    84  			executionError error
    85  
    86  			credentials = ServiceBrokerCredentials{
    87  				Name:      "name",
    88  				URL:       "url",
    89  				Username:  "username",
    90  				Password:  "password",
    91  				SpaceGUID: "space-guid",
    92  			}
    93  		)
    94  
    95  		JustBeforeEach(func() {
    96  			warnings, executionError = actor.CreateServiceBroker(credentials)
    97  		})
    98  
    99  		When("the client request is successful", func() {
   100  			BeforeEach(func() {
   101  				fakeCloudControllerClient.CreateServiceBrokerReturns(ccv3.Warnings{"some-creation-warning"}, nil)
   102  			})
   103  
   104  			It("succeeds and returns warnings", func() {
   105  				Expect(executionError).NotTo(HaveOccurred())
   106  
   107  				Expect(warnings).To(ConsistOf("some-creation-warning"))
   108  			})
   109  
   110  			It("passes the service broker credentials to the client", func() {
   111  				Expect(fakeCloudControllerClient.CreateServiceBrokerCallCount()).To(Equal(1))
   112  				Expect(fakeCloudControllerClient.CreateServiceBrokerArgsForCall(0)).
   113  					To(Equal(ccv3.ServiceBrokerCredentials(credentials)))
   114  			})
   115  		})
   116  
   117  		When("the client returns an error", func() {
   118  			BeforeEach(func() {
   119  				fakeCloudControllerClient.CreateServiceBrokerReturns(ccv3.Warnings{"some-other-warning"}, errors.New("invalid broker"))
   120  			})
   121  
   122  			It("fails and returns warnings", func() {
   123  				Expect(executionError).To(MatchError("invalid broker"))
   124  
   125  				Expect(warnings).To(ConsistOf("some-other-warning"))
   126  			})
   127  		})
   128  	})
   129  })