github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/shared/isolated/delete_service_command_test.go (about)

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