github.com/LukasHeimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/service_offering_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/cloudcontroller/ccerror"
    10  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    11  	"code.cloudfoundry.org/cli/resources"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/ginkgo/extensions/table"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("Service Offering Actions", func() {
    18  	var (
    19  		actor                     *Actor
    20  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    21  	)
    22  
    23  	BeforeEach(func() {
    24  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    25  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil)
    26  	})
    27  
    28  	Describe("PurgeServiceOfferingByNameAndBroker", func() {
    29  		Describe("steps", func() {
    30  			const fakeServiceOfferingGUID = "fake-service-offering-guid"
    31  			var (
    32  				warnings     Warnings
    33  				executeError error
    34  			)
    35  
    36  			BeforeEach(func() {
    37  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
    38  					resources.ServiceOffering{GUID: fakeServiceOfferingGUID},
    39  					ccv3.Warnings{"a warning"},
    40  					nil,
    41  				)
    42  
    43  				fakeCloudControllerClient.PurgeServiceOfferingReturns(
    44  					ccv3.Warnings{"another warning"},
    45  					nil,
    46  				)
    47  
    48  				warnings, executeError = actor.PurgeServiceOfferingByNameAndBroker("fake-service-offering", "fake-service-broker")
    49  			})
    50  
    51  			It("requests the service offering guid", func() {
    52  				Expect(fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerCallCount()).To(Equal(1))
    53  				actualOffering, actualBroker := fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerArgsForCall(0)
    54  				Expect(actualOffering).To(Equal("fake-service-offering"))
    55  				Expect(actualBroker).To(Equal("fake-service-broker"))
    56  			})
    57  
    58  			It("requests the purge of the service offering", func() {
    59  				Expect(fakeCloudControllerClient.PurgeServiceOfferingCallCount()).To(Equal(1))
    60  				actualGUID := fakeCloudControllerClient.PurgeServiceOfferingArgsForCall(0)
    61  				Expect(actualGUID).To(Equal(fakeServiceOfferingGUID))
    62  			})
    63  
    64  			It("return all warinings and no errors", func() {
    65  				Expect(executeError).NotTo(HaveOccurred())
    66  				Expect(warnings).To(ConsistOf("a warning", "another warning"))
    67  			})
    68  		})
    69  
    70  		DescribeTable(
    71  			"when getting the service offering fails ",
    72  			func(clientError, expectedError error) {
    73  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(resources.ServiceOffering{}, ccv3.Warnings{"a warning"}, clientError)
    74  
    75  				warnings, err := actor.PurgeServiceOfferingByNameAndBroker("fake-service-offering", "fake-service-broker")
    76  				Expect(err).To(MatchError(expectedError))
    77  				Expect(warnings).To(ConsistOf("a warning"))
    78  			},
    79  			Entry(
    80  				"ServiceOfferingNameAmbiguityError",
    81  				ccerror.ServiceOfferingNameAmbiguityError{
    82  					ServiceOfferingName: "foo",
    83  					ServiceBrokerNames:  []string{"bar", "baz"},
    84  				},
    85  				actionerror.ServiceOfferingNameAmbiguityError{
    86  					ServiceOfferingNameAmbiguityError: ccerror.ServiceOfferingNameAmbiguityError{
    87  						ServiceOfferingName: "foo",
    88  						ServiceBrokerNames:  []string{"bar", "baz"},
    89  					},
    90  				},
    91  			),
    92  			Entry(
    93  				"other error",
    94  				errors.New("boom"),
    95  				errors.New("boom"),
    96  			),
    97  		)
    98  
    99  		When("purging the service offering fails", func() {
   100  			BeforeEach(func() {
   101  				fakeCloudControllerClient.GetServiceOfferingByNameAndBrokerReturns(
   102  					resources.ServiceOffering{GUID: "fake-service-offering-guid"},
   103  					ccv3.Warnings{"a warning"},
   104  					nil,
   105  				)
   106  
   107  				fakeCloudControllerClient.PurgeServiceOfferingReturns(
   108  					ccv3.Warnings{"another warning"},
   109  					errors.New("ouch"),
   110  				)
   111  			})
   112  
   113  			It("return all warinings and errors", func() {
   114  				warnings, err := actor.PurgeServiceOfferingByNameAndBroker("fake-service-offering", "fake-service-broker")
   115  
   116  				Expect(err).To(MatchError(errors.New("ouch")))
   117  				Expect(warnings).To(ConsistOf("a warning", "another warning"))
   118  			})
   119  		})
   120  	})
   121  })