github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v2action/service_instance_user_provided_test.go (about) 1 package v2action_test 2 3 import ( 4 "encoding/json" 5 "errors" 6 7 . "code.cloudfoundry.org/cli/actor/v2action" 8 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/ginkgo/extensions/table" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("User-Provided Service Instance Actions", func() { 17 var ( 18 actor *Actor 19 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 20 ) 21 22 BeforeEach(func() { 23 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 24 actor = NewActor(fakeCloudControllerClient, nil, nil) 25 }) 26 27 Describe("Updating", func() { 28 const serviceInstanceGUID = "service-instance-guid" 29 30 DescribeTable("updating service instance data", 31 func(expectation string, instance UserProvidedServiceInstance) { 32 fakeCloudControllerClient.UpdateUserProvidedServiceInstanceReturns( 33 ccv2.Warnings{"warning-1", "warning-2"}, 34 nil, 35 ) 36 37 warnings, err := actor.UpdateUserProvidedServiceInstance(serviceInstanceGUID, instance) 38 Expect(err).NotTo(HaveOccurred()) 39 40 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 41 Expect(fakeCloudControllerClient.UpdateUserProvidedServiceInstanceCallCount()).To(Equal(1)) 42 guid, inst := fakeCloudControllerClient.UpdateUserProvidedServiceInstanceArgsForCall(0) 43 Expect(guid).To(Equal(serviceInstanceGUID)) 44 45 body, err := json.Marshal(inst) 46 Expect(err).NotTo(HaveOccurred()) 47 Expect(body).To(MatchJSON(expectation)) 48 }, 49 Entry( 50 "setting credentials", 51 `{"credentials": {"username": "super-secret-password"}}`, 52 UserProvidedServiceInstance{}.WithCredentials(map[string]interface{}{"username": "super-secret-password"}), 53 ), 54 Entry( 55 "removing credentials", 56 `{"credentials": {}}`, 57 UserProvidedServiceInstance{}.WithCredentials(nil), 58 ), 59 Entry( 60 "setting route service URL", 61 `{"route_service_url": "fake-route-url"}`, 62 UserProvidedServiceInstance{}.WithRouteServiceURL("fake-route-url"), 63 ), 64 Entry( 65 "removing route service URL", 66 `{"route_service_url": ""}`, 67 UserProvidedServiceInstance{}.WithRouteServiceURL(""), 68 ), 69 Entry( 70 "setting syslog drain URL", 71 `{"syslog_drain_url": "fake-syslog-drain-url"}`, 72 UserProvidedServiceInstance{}.WithSyslogDrainURL("fake-syslog-drain-url"), 73 ), 74 Entry( 75 "removing syslog drain URL", 76 `{"syslog_drain_url": ""}`, 77 UserProvidedServiceInstance{}.WithSyslogDrainURL(""), 78 ), 79 Entry( 80 "setting tags", 81 `{"tags": ["foo", "bar"]}`, 82 UserProvidedServiceInstance{}.WithTags([]string{"foo", "bar"}), 83 ), 84 Entry( 85 "removing tags", 86 `{"tags": []}`, 87 UserProvidedServiceInstance{}.WithTags(nil), 88 ), 89 Entry( 90 "updating everything", 91 `{ 92 "credentials": {"username": "super-secret-password"}, 93 "route_service_url": "fake-route-url", 94 "syslog_drain_url": "fake-syslog-drain-url", 95 "tags": ["foo", "bar"] 96 }`, 97 UserProvidedServiceInstance{}. 98 WithCredentials(map[string]interface{}{"username": "super-secret-password"}). 99 WithRouteServiceURL("fake-route-url"). 100 WithSyslogDrainURL("fake-syslog-drain-url"). 101 WithTags([]string{"foo", "bar"}), 102 ), 103 ) 104 105 When("the update fails", func() { 106 BeforeEach(func() { 107 fakeCloudControllerClient.UpdateUserProvidedServiceInstanceReturns( 108 ccv2.Warnings{"warning-1", "warning-2"}, 109 errors.New("update failed horribly!!!"), 110 ) 111 }) 112 113 It("returns the error and all the warnings", func() { 114 warnings, err := actor.UpdateUserProvidedServiceInstance(serviceInstanceGUID, UserProvidedServiceInstance{}) 115 Expect(err).To(MatchError("update failed horribly!!!")) 116 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 117 }) 118 }) 119 }) 120 })