github.com/loafoe/cli@v7.1.0+incompatible/integration/helpers/servicebrokerstub/cf.go (about) 1 package servicebrokerstub 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 func (s *ServiceBrokerStub) register(spaceScoped bool) { 12 var params []string 13 14 switch s.registered { 15 case true: 16 params = []string{"update-service-broker"} 17 case false: 18 params = []string{"create-service-broker"} 19 } 20 21 params = append(params, s.Name, s.Username, s.Password, s.URL) 22 23 if spaceScoped { 24 params = append(params, "--space-scoped") 25 } 26 27 Eventually(helpers.CF(params...)).Should(Exit(0)) 28 } 29 30 func (s *ServiceBrokerStub) deregister() { 31 s.purgeServiceOfferings(true) 32 Eventually(helpers.CF("delete-service-broker", "-f", s.Name)).Should(Exit(0)) 33 } 34 35 func (s *ServiceBrokerStub) registerViaV2() { 36 broker := map[string]interface{}{ 37 "name": s.Name, 38 "broker_url": s.URL, 39 "auth_username": s.Username, 40 "auth_password": s.Password, 41 } 42 data, err := json.Marshal(broker) 43 Expect(err).NotTo(HaveOccurred()) 44 45 Eventually(helpers.CF("curl", "-X", "POST", "/v2/service_brokers", "-d", string(data))).Should(Exit(0)) 46 } 47 48 func (s *ServiceBrokerStub) enableServiceAccess() { 49 for _, offering := range s.Services { 50 session := helpers.CF("enable-service-access", offering.Name, "-b", s.Name) 51 Eventually(session).Should(Exit(0)) 52 } 53 } 54 55 func (s *ServiceBrokerStub) purgeServiceOfferings(ignoreFailures bool) { 56 for _, service := range s.Services { 57 session := helpers.CF("purge-service-offering", service.Name, "-b", s.Name, "-f") 58 session.Wait() 59 60 if !ignoreFailures { 61 Expect(session).To(Exit(0)) 62 } 63 } 64 }