github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/helpers/service_binding.go (about) 1 package helpers 2 3 import ( 4 "time" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 // PollLastOperationUntilSuccess polls the last operation performed on a service instance bound to a given app until 13 // success. An expectation will fail if the last operation does not succeed or polling takes over 5 minutes. 14 func PollLastOperationUntilSuccess(client *ccv2.Client, appName string, serviceInstanceName string) { 15 apps, _, err := client.GetApplications(ccv2.Filter{ 16 Type: constant.NameFilter, 17 Operator: constant.EqualOperator, 18 Values: []string{appName}, 19 }) 20 Expect(err).ToNot(HaveOccurred()) 21 Expect(apps).To(HaveLen(1)) 22 23 serviceInstances, _, err := client.GetServiceInstances(ccv2.Filter{ 24 Type: constant.NameFilter, 25 Operator: constant.EqualOperator, 26 Values: []string{serviceInstanceName}, 27 }) 28 Expect(err).ToNot(HaveOccurred()) 29 Expect(serviceInstances).To(HaveLen(1)) 30 31 bindings, _, err := client.GetServiceBindings(ccv2.Filter{ 32 Type: constant.AppGUIDFilter, 33 Operator: constant.EqualOperator, 34 Values: []string{apps[0].GUID}, 35 }, ccv2.Filter{ 36 Type: constant.ServiceInstanceGUIDFilter, 37 Operator: constant.EqualOperator, 38 Values: []string{serviceInstances[0].GUID}, 39 }) 40 Expect(err).ToNot(HaveOccurred()) 41 Expect(bindings).To(HaveLen(1)) 42 binding := bindings[0] 43 44 startTime := time.Now() 45 for binding.LastOperation.State == constant.LastOperationInProgress { 46 if time.Now().After(startTime.Add(5 * time.Minute)) { 47 Fail("Service Binding in progress for more than 5 minutes - failing") 48 } 49 time.Sleep(time.Second) 50 bindings, _, err := client.GetServiceBindings(ccv2.Filter{ 51 Type: constant.AppGUIDFilter, 52 Operator: constant.EqualOperator, 53 Values: []string{apps[0].GUID}, 54 }, ccv2.Filter{ 55 Type: constant.ServiceInstanceGUIDFilter, 56 Operator: constant.EqualOperator, 57 Values: []string{serviceInstances[0].GUID}, 58 }) 59 Expect(err).ToNot(HaveOccurred()) 60 Expect(bindings).To(HaveLen(1)) 61 binding = bindings[0] 62 } 63 Expect(binding.LastOperation.State).To(Equal(constant.LastOperationSucceeded)) 64 }