github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/actor/v2action/service_broker_test.go (about) 1 package v2action_test 2 3 import ( 4 "errors" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 9 . "code.cloudfoundry.org/cli/actor/v2action" 10 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 11 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 12 ) 13 14 var _ = Describe("Service Broker", func() { 15 var ( 16 actor *Actor 17 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 18 ) 19 20 BeforeEach(func() { 21 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 22 actor = NewActor(fakeCloudControllerClient, nil, nil) 23 }) 24 25 Describe("CreateServiceBroker", func() { 26 var ( 27 executeErr error 28 warnings Warnings 29 serviceBroker ServiceBroker 30 ) 31 32 JustBeforeEach(func() { 33 serviceBroker, warnings, executeErr = actor.CreateServiceBroker("broker-name", "username", "password", "https://broker.com", "a-space-guid") 34 }) 35 36 When("there are no errors", func() { 37 BeforeEach(func() { 38 fakeCloudControllerClient.CreateServiceBrokerReturns(ccv2.ServiceBroker{GUID: "some-broker-guid"}, []string{"a-warning", "another-warning"}, nil) 39 }) 40 41 It("creates the service broker with the correct values", func() { 42 Expect(fakeCloudControllerClient.CreateServiceBrokerCallCount()).To(Equal(1)) 43 brokerName, username, password, url, space := fakeCloudControllerClient.CreateServiceBrokerArgsForCall(0) 44 Expect(brokerName).To(Equal("broker-name")) 45 Expect(username).To(Equal("username")) 46 Expect(password).To(Equal("password")) 47 Expect(url).To(Equal("https://broker.com")) 48 Expect(space).To(Equal("a-space-guid")) 49 50 Expect(warnings).To(Equal(Warnings{"a-warning", "another-warning"})) 51 Expect(executeErr).NotTo(HaveOccurred()) 52 Expect(serviceBroker.GUID).To(Equal("some-broker-guid")) 53 }) 54 }) 55 56 When("there is an error", func() { 57 BeforeEach(func() { 58 fakeCloudControllerClient.CreateServiceBrokerReturns(ccv2.ServiceBroker{}, []string{"one-warning", "two-warnings"}, errors.New("error creating broker")) 59 }) 60 61 It("returns the errors and warnings", func() { 62 Expect(warnings).To(Equal(Warnings{"one-warning", "two-warnings"})) 63 Expect(executeErr).To(MatchError("error creating broker")) 64 }) 65 }) 66 }) 67 })