github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/actor/pushaction/service_binding_test.go (about) 1 package pushaction_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/pushaction" 7 "code.cloudfoundry.org/cli/actor/pushaction/pushactionfakes" 8 "code.cloudfoundry.org/cli/actor/v2action" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("Binding Services", func() { 15 var ( 16 actor *Actor 17 fakeV2Actor *pushactionfakes.FakeV2Actor 18 ) 19 20 BeforeEach(func() { 21 actor, fakeV2Actor, _, _ = getTestPushActor() 22 }) 23 24 Describe("BindServices", func() { 25 var ( 26 config ApplicationConfig 27 28 returnedConfig ApplicationConfig 29 boundServices bool 30 warnings Warnings 31 executeErr error 32 ) 33 34 BeforeEach(func() { 35 config = ApplicationConfig{} 36 config.DesiredApplication.GUID = "some-app-guid" 37 config.CurrentServices = map[string]v2action.ServiceInstance{"service_instance_1": {GUID: "instance_1_guid"}} 38 config.DesiredServices = map[string]v2action.ServiceInstance{ 39 "service_instance_1": {GUID: "instance_1_guid"}, 40 "service_instance_2": {GUID: "instance_2_guid"}, 41 "service_instance_3": {GUID: "instance_3_guid"}, 42 } 43 }) 44 45 JustBeforeEach(func() { 46 returnedConfig, boundServices, warnings, executeErr = actor.BindServices(config) 47 }) 48 49 When("binding services is successful", func() { 50 BeforeEach(func() { 51 fakeV2Actor.BindServiceByApplicationAndServiceInstanceReturnsOnCall(0, v2action.Warnings{"service-instance-warning-1"}, nil) 52 fakeV2Actor.BindServiceByApplicationAndServiceInstanceReturnsOnCall(1, v2action.Warnings{"service-instance-warning-2"}, nil) 53 }) 54 55 It("it updates CurrentServices to match DesiredServices", func() { 56 Expect(executeErr).ToNot(HaveOccurred()) 57 Expect(warnings).To(ConsistOf("service-instance-warning-1", "service-instance-warning-2")) 58 Expect(boundServices).To(BeTrue()) 59 Expect(returnedConfig.CurrentServices).To(Equal(map[string]v2action.ServiceInstance{ 60 "service_instance_1": {GUID: "instance_1_guid"}, 61 "service_instance_2": {GUID: "instance_2_guid"}, 62 "service_instance_3": {GUID: "instance_3_guid"}, 63 })) 64 65 var serviceInstanceGUIDs []string 66 Expect(fakeV2Actor.BindServiceByApplicationAndServiceInstanceCallCount()).To(Equal(2)) 67 appGUID, serviceInstanceGUID := fakeV2Actor.BindServiceByApplicationAndServiceInstanceArgsForCall(0) 68 Expect(appGUID).To(Equal("some-app-guid")) 69 serviceInstanceGUIDs = append(serviceInstanceGUIDs, serviceInstanceGUID) 70 71 appGUID, serviceInstanceGUID = fakeV2Actor.BindServiceByApplicationAndServiceInstanceArgsForCall(1) 72 Expect(appGUID).To(Equal("some-app-guid")) 73 serviceInstanceGUIDs = append(serviceInstanceGUIDs, serviceInstanceGUID) 74 75 Expect(serviceInstanceGUIDs).To(ConsistOf("instance_2_guid", "instance_3_guid")) 76 }) 77 }) 78 79 When("binding services fails", func() { 80 BeforeEach(func() { 81 fakeV2Actor.BindServiceByApplicationAndServiceInstanceReturns(v2action.Warnings{"service-instance-warning-1"}, errors.New("some-error")) 82 }) 83 84 It("it returns the error", func() { 85 Expect(executeErr).To(MatchError("some-error")) 86 Expect(warnings).To(ConsistOf("service-instance-warning-1")) 87 Expect(boundServices).To(BeFalse()) 88 }) 89 }) 90 }) 91 })