github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/purge_service_offering_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("purge-service-offering command", func() {
    13  	Describe("help", func() {
    14  		When("the --help flag is set", func() {
    15  			It("displays command usage to output", func() {
    16  				session := helpers.CF("purge-service-offering", "--help")
    17  
    18  				Eventually(session).Should(Say("NAME:"))
    19  				Eventually(session).Should(Say("purge-service-offering - Recursively remove a service and child objects from Cloud Foundry database without making requests to a service broker"))
    20  				Eventually(session).Should(Say("USAGE:"))
    21  				Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-p PROVIDER\] \[-f\]`))
    22  				Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
    23  				Eventually(session).Should(Say("OPTIONS:"))
    24  				Eventually(session).Should(Say("-b\\s+Purge a service from a particular service broker. Required when service name is ambiguous"))
    25  				Eventually(session).Should(Say("-f\\s+Force deletion without confirmation"))
    26  				Eventually(session).Should(Say("-p\\s+Provider"))
    27  				Eventually(session).Should(Say("SEE ALSO:"))
    28  				Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers"))
    29  				Eventually(session).Should(Exit(0))
    30  			})
    31  		})
    32  
    33  		When("no args are passed", func() {
    34  			It("displays an error message with help text", func() {
    35  				session := helpers.CF("purge-service-offering")
    36  
    37  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SERVICE` was not provided"))
    38  				Eventually(session).Should(Say("NAME:"))
    39  				Eventually(session).Should(Say("purge-service-offering - Recursively remove a service and child objects from Cloud Foundry database without making requests to a service broker"))
    40  				Eventually(session).Should(Say("USAGE:"))
    41  				Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-p PROVIDER\] \[-f\]`))
    42  				Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
    43  				Eventually(session).Should(Say("OPTIONS:"))
    44  				Eventually(session).Should(Say("-b\\s+Purge a service from a particular service broker. Required when service name is ambiguous"))
    45  				Eventually(session).Should(Say("-f\\s+Force deletion without confirmation"))
    46  				Eventually(session).Should(Say("-p\\s+Provider"))
    47  				Eventually(session).Should(Say("SEE ALSO:"))
    48  				Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers"))
    49  				Eventually(session).Should(Exit(1))
    50  			})
    51  		})
    52  
    53  		When("more than required number of args are passed", func() {
    54  			It("displays an error message with help text and exits 1", func() {
    55  				session := helpers.CF("purge-service-offering", "service-name", "extra")
    56  
    57  				Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "extra"`))
    58  				Eventually(session).Should(Say("NAME:"))
    59  				Eventually(session).Should(Say("purge-service-offering - Recursively remove a service and child objects from Cloud Foundry database without making requests to a service broker"))
    60  				Eventually(session).Should(Say("USAGE:"))
    61  				Eventually(session).Should(Say(`cf purge-service-offering SERVICE \[-b BROKER\] \[-p PROVIDER\] \[-f\]`))
    62  				Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
    63  				Eventually(session).Should(Say("OPTIONS:"))
    64  				Eventually(session).Should(Say("-b\\s+Purge a service from a particular service broker. Required when service name is ambiguous"))
    65  				Eventually(session).Should(Say("-f\\s+Force deletion without confirmation"))
    66  				Eventually(session).Should(Say("-p\\s+Provider"))
    67  				Eventually(session).Should(Say("SEE ALSO:"))
    68  				Eventually(session).Should(Say("marketplace, purge-service-instance, service-brokers"))
    69  				Eventually(session).Should(Exit(1))
    70  			})
    71  		})
    72  	})
    73  
    74  	When("service name is passed", func() {
    75  		When("an API target is not set", func() {
    76  			BeforeEach(func() {
    77  				helpers.UnsetAPI()
    78  			})
    79  
    80  			It("displays an error message that no API endpoint is set", func() {
    81  				session := helpers.CF("purge-service-offering", "service-name")
    82  
    83  				Eventually(session).Should(Say("FAILED"))
    84  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    85  				Eventually(session).Should(Exit(1))
    86  			})
    87  		})
    88  
    89  		When("user is not logged in", func() {
    90  			BeforeEach(func() {
    91  				helpers.LogoutCF()
    92  			})
    93  
    94  			It("displays an error message that user is not logged in", func() {
    95  				session := helpers.CF("purge-service-offering", "service-name")
    96  
    97  				Eventually(session).Should(Say("FAILED"))
    98  				Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' or 'cf login --sso' to log in\.`))
    99  				Eventually(session).Should(Exit(1))
   100  			})
   101  		})
   102  
   103  		When("user is logged in", func() {
   104  			BeforeEach(func() {
   105  				helpers.LoginCF()
   106  			})
   107  
   108  			When("the service exists", func() {
   109  				var (
   110  					orgName   string
   111  					spaceName string
   112  					broker    *servicebrokerstub.ServiceBrokerStub
   113  					buffer    *Buffer
   114  				)
   115  
   116  				BeforeEach(func() {
   117  					buffer = NewBuffer()
   118  
   119  					orgName = helpers.NewOrgName()
   120  					spaceName = helpers.NewSpaceName()
   121  					helpers.SetupCF(orgName, spaceName)
   122  
   123  					broker = servicebrokerstub.Register()
   124  				})
   125  
   126  				AfterEach(func() {
   127  					broker.Forget()
   128  					helpers.QuickDeleteOrg(orgName)
   129  				})
   130  
   131  				When("the user enters 'y'", func() {
   132  					BeforeEach(func() {
   133  						_, err := buffer.Write([]byte("y\n"))
   134  						Expect(err).ToNot(HaveOccurred())
   135  					})
   136  
   137  					It("purges the service offering, asking for confirmation", func() {
   138  						session := helpers.CFWithStdin(buffer, "purge-service-offering", broker.FirstServiceOfferingName())
   139  
   140  						Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
   141  						Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.FirstServiceOfferingName()))
   142  						Eventually(session).Should(Say("Purging service %s...", broker.FirstServiceOfferingName()))
   143  						Eventually(session).Should(Say("OK"))
   144  						Eventually(session).Should(Exit(0))
   145  
   146  						session = helpers.CF("marketplace")
   147  						Eventually(session).Should(Say("OK"))
   148  						Consistently(session).ShouldNot(Say(broker.FirstServiceOfferingName()))
   149  						Eventually(session).Should(Exit(0))
   150  					})
   151  				})
   152  
   153  				When("the user enters something other than 'y' or 'yes'", func() {
   154  					BeforeEach(func() {
   155  						_, err := buffer.Write([]byte("wat\n\n"))
   156  						Expect(err).ToNot(HaveOccurred())
   157  					})
   158  
   159  					It("asks again", func() {
   160  						session := helpers.CFWithStdin(buffer, "purge-service-offering", broker.FirstServiceOfferingName())
   161  
   162  						Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
   163  						Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.FirstServiceOfferingName()))
   164  						Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`))
   165  						Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.FirstServiceOfferingName()))
   166  						Eventually(session).Should(Exit(0))
   167  					})
   168  				})
   169  
   170  				When("the user enters 'n' or 'no'", func() {
   171  					BeforeEach(func() {
   172  						_, err := buffer.Write([]byte("n\n"))
   173  						Expect(err).ToNot(HaveOccurred())
   174  					})
   175  
   176  					It("does not purge the service offering", func() {
   177  						session := helpers.CFWithStdin(buffer, "purge-service-offering", broker.FirstServiceOfferingName())
   178  
   179  						Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
   180  						Eventually(session).Should(Say("Really purge service offering %s from Cloud Foundry?", broker.FirstServiceOfferingName()))
   181  						Eventually(session).ShouldNot(Say("Purging service %s...", broker.FirstServiceOfferingName()))
   182  						Eventually(session).ShouldNot(Say("OK"))
   183  						Eventually(session).Should(Exit(0))
   184  					})
   185  				})
   186  
   187  				When("the -f flag is provided", func() {
   188  					It("purges the service offering without asking for confirmation", func() {
   189  						session := helpers.CF("purge-service-offering", broker.FirstServiceOfferingName(), "-f")
   190  
   191  						Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
   192  						Eventually(session).Should(Say("Purging service %s...", broker.FirstServiceOfferingName()))
   193  						Eventually(session).Should(Say("OK"))
   194  						Eventually(session).Should(Exit(0))
   195  					})
   196  				})
   197  			})
   198  
   199  			When("the service does not exist", func() {
   200  				It("prints a message the service offering does not exist, exiting 0", func() {
   201  					session := helpers.CF("purge-service-offering", "missing-service")
   202  
   203  					Eventually(session).Should(Say("Service offering 'missing-service' not found"))
   204  					Eventually(session).Should(Exit(0))
   205  				})
   206  			})
   207  
   208  			When("the -p flag is provided", func() {
   209  				It("prints a warning that this flag is no longer supported", func() {
   210  					session := helpers.CF("purge-service-offering", "some-service", "-p", "some-provider")
   211  
   212  					Eventually(session).Should(Say("FAILED"))
   213  					Eventually(session.Err).Should(Say("Flag '-p' is no longer supported"))
   214  					Eventually(session).ShouldNot(Say("Purging service"))
   215  					Eventually(session).ShouldNot(Say("OK"))
   216  					Eventually(session).Should(Exit(1))
   217  				})
   218  			})
   219  
   220  			When("the -b flag is provided", func() {
   221  				var (
   222  					orgName   string
   223  					spaceName string
   224  					broker1   *servicebrokerstub.ServiceBrokerStub
   225  					broker2   *servicebrokerstub.ServiceBrokerStub
   226  					buffer    *Buffer
   227  				)
   228  
   229  				It("fails when service broker is not registered yet", func() {
   230  					session := helpers.CF("purge-service-offering", "some-service", "-b", "non-existent-broker")
   231  
   232  					Eventually(session.Err).Should(Say("Service broker 'non-existent-broker' not found"))
   233  					Eventually(session.Err).Should(Say("TIP: Use 'cf service-brokers' to see a list of available brokers."))
   234  					Eventually(session).Should(Say("FAILED"))
   235  					Eventually(session).Should(Exit(1))
   236  				})
   237  
   238  				When("the service is provided by multiple brokers", func() {
   239  					BeforeEach(func() {
   240  						buffer = NewBuffer()
   241  						_, err := buffer.Write([]byte("y\n"))
   242  						Expect(err).ToNot(HaveOccurred())
   243  						orgName = helpers.NewOrgName()
   244  						spaceName = helpers.NewSpaceName()
   245  						helpers.SetupCF(orgName, spaceName)
   246  
   247  						broker1 = servicebrokerstub.Register()
   248  						broker2 = servicebrokerstub.New()
   249  						broker2.Services[0].Name = broker1.FirstServiceOfferingName()
   250  						broker2.Create().Register()
   251  
   252  						session := helpers.CF("enable-service-access", broker1.FirstServiceOfferingName(), "-b", broker1.Name)
   253  						Eventually(session).Should(Exit(0))
   254  						session = helpers.CF("enable-service-access", broker1.FirstServiceOfferingName(), "-b", broker2.Name)
   255  						Eventually(session).Should(Exit(0))
   256  					})
   257  
   258  					AfterEach(func() {
   259  						broker1.Forget()
   260  						broker2.Forget()
   261  						helpers.QuickDeleteOrg(orgName)
   262  					})
   263  
   264  					When("the user specifies the desired broker", func() {
   265  
   266  						It("purges the service offering, asking for confirmation", func() {
   267  							session := helpers.CFWithStdin(buffer, "purge-service-offering", broker1.FirstServiceOfferingName(), "-b", broker1.Name)
   268  
   269  							Eventually(session).Should(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
   270  							Eventually(session).Should(Say("Really purge service offering %s from broker %s from Cloud Foundry?", broker1.FirstServiceOfferingName(), broker1.Name))
   271  							Eventually(session).Should(Say("Purging service %s...", broker1.FirstServiceOfferingName()))
   272  							Eventually(session).Should(Say("OK"))
   273  							Eventually(session).Should(Exit(0))
   274  
   275  							session = helpers.CF("marketplace")
   276  							Eventually(session).Should(Say("OK"))
   277  							Consistently(session).ShouldNot(Say(`%s.+%s`, broker1.FirstServiceOfferingName(), broker1.Name))
   278  							Eventually(session).Should(Say(`%s.+%s`, broker1.FirstServiceOfferingName(), broker2.Name))
   279  							Eventually(session).Should(Exit(0))
   280  						})
   281  					})
   282  
   283  					When("the user does not specify the desired broker", func() {
   284  						It("does not purge the service offering", func() {
   285  							session := helpers.CFWithStdin(buffer, "purge-service-offering", broker1.FirstServiceOfferingName())
   286  
   287  							Eventually(session.Err).Should(Say("Service '%s' is provided by multiple service brokers. Specify a broker by using the '-b' flag.", broker1.FirstServiceOfferingName()))
   288  							Eventually(session).Should(Say("FAILED"))
   289  
   290  							Eventually(session).ShouldNot(Say("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database\\. All knowledge of the service will be removed from Cloud Foundry, including service instances and service bindings\\. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances\\. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup\\."))
   291  							Eventually(session).ShouldNot(Say("Purging service %s...", broker1.FirstServiceOfferingName()))
   292  							Eventually(session).ShouldNot(Say("OK"))
   293  							Eventually(session).Should(Exit(1))
   294  						})
   295  					})
   296  				})
   297  			})
   298  		})
   299  	})
   300  })