github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/delete_service_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("delete-service command", func() { 13 When("an api is targeted and the user is logged in", func() { 14 BeforeEach(func() { 15 helpers.LoginCF() 16 }) 17 18 When("the environment is not setup correctly", func() { 19 It("fails with the appropriate errors", func() { 20 By("checking the org is targeted correctly") 21 session := helpers.CF("delete-service", "service-name", "-f") 22 Eventually(session).Should(Say("FAILED")) 23 Eventually(session.Out).Should(Say("No org and space targeted, use 'cf target -o ORG -s SPACE' to target an org and space")) 24 Eventually(session).Should(Exit(1)) 25 26 By("checking the space is targeted correctly") 27 helpers.TargetOrg(ReadOnlyOrg) 28 session = helpers.CF("delete-service", "service-name", "-f") 29 Eventually(session).Should(Say("FAILED")) 30 Eventually(session.Out).Should(Say(`No space targeted, use 'cf target -s' to target a space\.`)) 31 Eventually(session).Should(Exit(1)) 32 }) 33 }) 34 35 When("an org and space are targeted", func() { 36 var ( 37 orgName string 38 spaceName string 39 ) 40 41 BeforeEach(func() { 42 orgName = helpers.NewOrgName() 43 spaceName = helpers.NewSpaceName() 44 helpers.CreateOrgAndSpace(orgName, spaceName) 45 helpers.TargetOrgAndSpace(orgName, spaceName) 46 }) 47 48 AfterEach(func() { 49 helpers.QuickDeleteOrg(orgName) 50 }) 51 52 When("there is a service instance and it is bound to an app", func() { 53 var ( 54 service string 55 servicePlan string 56 broker *servicebrokerstub.ServiceBrokerStub 57 58 serviceInstanceName string 59 appName string 60 ) 61 62 BeforeEach(func() { 63 broker = servicebrokerstub.EnableServiceAccess() 64 service = broker.FirstServiceOfferingName() 65 servicePlan = broker.FirstServicePlanName() 66 67 Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0)) 68 69 serviceInstanceName = helpers.PrefixedRandomName("SI") 70 Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName)).Should(Exit(0)) 71 72 appName = helpers.NewAppName() 73 helpers.WithHelloWorldApp(func(appDir string) { 74 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) 75 }) 76 77 Eventually(helpers.CF("bind-service", appName, serviceInstanceName)).Should(Exit(0)) 78 }) 79 80 AfterEach(func() { 81 Eventually(helpers.CF("unbind-service", appName, serviceInstanceName)).Should(Exit(0)) 82 Eventually(helpers.CF("delete", appName, "-f")).Should(Exit(0)) 83 Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0)) 84 broker.Forget() 85 }) 86 87 It("should display an error message that the service instance's keys, bindings, and shares must first be deleted", func() { 88 session := helpers.CF("delete-service", serviceInstanceName, "-f") 89 Eventually(session).Should(Say(`Cannot delete service instance. Service keys, bindings, and shares must first be deleted\.`)) 90 Eventually(session).Should(Exit(1)) 91 }) 92 }) 93 }) 94 }) 95 })