github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/integration/v7/isolated/delete_service_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"time"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	"code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("delete-service command", func() {
    15  	const command = "delete-service"
    16  
    17  	Describe("help", func() {
    18  		matchHelpMessage := SatisfyAll(
    19  			Say(`NAME:\n`),
    20  			Say(`\s+%s - Delete a service instance\n`, command),
    21  			Say(`\n`),
    22  			Say(`USAGE:\n`),
    23  			Say(`\s+cf delete-service SERVICE_INSTANCE \[-f\] \[-w\]\n`),
    24  			Say(`\n`),
    25  			Say(`ALIAS:\n`),
    26  			Say(`\s+ds\n`),
    27  			Say(`\n`),
    28  			Say(`OPTIONS:\n`),
    29  			Say(`\s+--force, -f\s+Force deletion without confirmation\n`),
    30  			Say(`\s+--wait, -w\s+Wait for the operation to complete\n`),
    31  			Say(`\n`),
    32  			Say(`SEE ALSO:\n`),
    33  			Say(`\s+services, unbind-service\n`),
    34  		)
    35  
    36  		When("--help is specified", func() {
    37  			It("exits successfully and print the help message", func() {
    38  				session := helpers.CF(command, "--help")
    39  				Eventually(session).Should(Exit(0))
    40  
    41  				Expect(session.Out).To(matchHelpMessage)
    42  				Expect(string(session.Err.Contents())).To(BeEmpty())
    43  			})
    44  		})
    45  
    46  		When("the service instance name is omitted", func() {
    47  			It("fails and prints the help message", func() {
    48  				session := helpers.CF(command)
    49  
    50  				Eventually(session).Should(Exit(1))
    51  				Expect(session.Out).To(matchHelpMessage)
    52  				Expect(session.Err).To(Say("Incorrect Usage: the required argument `SERVICE_INSTANCE` was not provided\n"))
    53  			})
    54  		})
    55  
    56  		When("an extra parameter is provided", func() {
    57  			It("fails and prints the help message", func() {
    58  				session := helpers.CF(command, "service-instance-name", "invalid-extra-parameter")
    59  
    60  				Eventually(session).Should(Exit(1))
    61  				Expect(session.Out).To(matchHelpMessage)
    62  				Expect(session.Err).To(Say(`Incorrect Usage: unexpected argument "invalid-extra-parameter"`))
    63  			})
    64  		})
    65  
    66  		When("an extra flag is provided", func() {
    67  			It("fails and prints the help message", func() {
    68  				session := helpers.CF(command, "service-instance-name", "--invalid")
    69  
    70  				Eventually(session).Should(Exit(1))
    71  				Expect(session.Out).To(matchHelpMessage)
    72  				Expect(session.Err).To(Say("Incorrect Usage: unknown flag `invalid'"))
    73  			})
    74  		})
    75  	})
    76  
    77  	When("the environment is not setup correctly", func() {
    78  		It("fails with the appropriate errors", func() {
    79  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, command, "service-instance-name")
    80  		})
    81  	})
    82  
    83  	When("targeting a space", func() {
    84  		var (
    85  			serviceInstanceName string
    86  			orgName             string
    87  			spaceName           string
    88  			username            string
    89  		)
    90  
    91  		BeforeEach(func() {
    92  			orgName = helpers.NewOrgName()
    93  			spaceName = helpers.NewSpaceName()
    94  			helpers.SetupCF(orgName, spaceName)
    95  
    96  			username, _ = helpers.GetCredentials()
    97  			serviceInstanceName = helpers.NewServiceInstanceName()
    98  		})
    99  
   100  		AfterEach(func() {
   101  			helpers.QuickDeleteOrg(orgName)
   102  		})
   103  
   104  		When("the service instance does not exist", func() {
   105  			It("prints a message and exits successfully", func() {
   106  				session := helpers.CF(command, "-f", serviceInstanceName)
   107  				Eventually(session).Should(Exit(0))
   108  
   109  				Expect(session.Out).To(SatisfyAll(
   110  					Say("Deleting service instance %s in org %s / space %s as %s...", serviceInstanceName, orgName, spaceName, username),
   111  					Say("\n"),
   112  					Say("Service instance %s did not exist.\n", serviceInstanceName),
   113  				))
   114  
   115  				Expect(string(session.Err.Contents())).To(BeEmpty())
   116  			})
   117  		})
   118  
   119  		When("the service instance is user-provided", func() {
   120  			BeforeEach(func() {
   121  				session := helpers.CF("cups", serviceInstanceName)
   122  				Eventually(session).Should(Exit(0))
   123  			})
   124  
   125  			It("prints a message and exits successfully", func() {
   126  				session := helpers.CF(command, "-f", serviceInstanceName)
   127  				Eventually(session).Should(Exit(0))
   128  
   129  				Expect(session.Out).To(SatisfyAll(
   130  					Say("Deleting service instance %s in org %s / space %s as %s...", serviceInstanceName, orgName, spaceName, username),
   131  					Say("\n"),
   132  					Say("Service instance %s deleted.\n", serviceInstanceName),
   133  				))
   134  
   135  				Expect(string(session.Err.Contents())).To(BeEmpty())
   136  
   137  				session = helpers.CF("services").Wait()
   138  				Expect(session.Out).NotTo(Say(serviceInstanceName))
   139  			})
   140  		})
   141  
   142  		When("the service instance is managed by a synchronous broker", func() {
   143  			var broker *servicebrokerstub.ServiceBrokerStub
   144  
   145  			BeforeEach(func() {
   146  				broker = servicebrokerstub.EnableServiceAccess()
   147  				helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstanceName)
   148  			})
   149  
   150  			AfterEach(func() {
   151  				broker.Forget()
   152  			})
   153  
   154  			It("prints a message and exits successfully", func() {
   155  				session := helpers.CF(command, "-f", serviceInstanceName)
   156  				Eventually(session).Should(Exit(0))
   157  
   158  				Expect(session.Out).To(SatisfyAll(
   159  					Say("Deleting service instance %s in org %s / space %s as %s...", serviceInstanceName, orgName, spaceName, username),
   160  					Say("\n"),
   161  					Say(`Service instance %s deleted\.\n`, serviceInstanceName),
   162  				))
   163  
   164  				Expect(string(session.Err.Contents())).To(BeEmpty())
   165  			})
   166  
   167  			When("the wait flag is specified", func() {
   168  				It("waits for the delete operation", func() {
   169  					session := helpers.CF(command, "-f", "-w", serviceInstanceName)
   170  					Eventually(session).Should(Exit(0))
   171  
   172  					Expect(session.Out).To(SatisfyAll(
   173  						Say("Deleting service instance %s in org %s / space %s as %s...", serviceInstanceName, orgName, spaceName, username),
   174  						Say("\n"),
   175  						Say("Waiting for the operation to complete."),
   176  						Say("\n"),
   177  						Say("Service instance %s deleted.\n", serviceInstanceName),
   178  					))
   179  
   180  					Expect(string(session.Err.Contents())).To(BeEmpty())
   181  
   182  					session = helpers.CF("services").Wait()
   183  					Expect(session.Out).NotTo(Say(serviceInstanceName))
   184  				})
   185  			})
   186  		})
   187  
   188  		When("the service instance is managed by an asynchronous broker", func() {
   189  			var broker *servicebrokerstub.ServiceBrokerStub
   190  
   191  			BeforeEach(func() {
   192  				broker = servicebrokerstub.New().WithAsyncDelay(time.Second).EnableServiceAccess()
   193  				helpers.CreateManagedServiceInstance(broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), serviceInstanceName)
   194  			})
   195  
   196  			AfterEach(func() {
   197  				broker.Forget()
   198  			})
   199  
   200  			It("prints a message and exits successfully", func() {
   201  				session := helpers.CF(command, "-f", serviceInstanceName)
   202  				Eventually(session).Should(Exit(0))
   203  
   204  				Expect(session.Out).To(SatisfyAll(
   205  					Say("Deleting service instance %s in org %s / space %s as %s...", serviceInstanceName, orgName, spaceName, username),
   206  					Say("\n"),
   207  					Say("Delete in progress. Use 'cf services' or 'cf service %s' to check operation status.\n", serviceInstanceName),
   208  				))
   209  
   210  				Expect(string(session.Err.Contents())).To(BeEmpty())
   211  			})
   212  
   213  			When("the wait flag is specified", func() {
   214  				It("waits for the delete operation", func() {
   215  					session := helpers.CF(command, "-f", "-w", serviceInstanceName)
   216  					Eventually(session).Should(Exit(0))
   217  
   218  					Expect(session.Out).To(SatisfyAll(
   219  						Say("Deleting service instance %s in org %s / space %s as %s...", serviceInstanceName, orgName, spaceName, username),
   220  						Say("\n"),
   221  						Say("Waiting for the operation to complete."),
   222  						Say("\n"),
   223  						Say("Service instance %s deleted.\n", serviceInstanceName),
   224  					))
   225  
   226  					Expect(string(session.Err.Contents())).To(BeEmpty())
   227  
   228  					session = helpers.CF("services").Wait()
   229  					Expect(session.Out).NotTo(Say(serviceInstanceName))
   230  				})
   231  			})
   232  		})
   233  	})
   234  })