github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/global/service_command_test.go (about)

     1  package global
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     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("service command", func() {
    13  	var serviceInstanceName string
    14  
    15  	BeforeEach(func() {
    16  		serviceInstanceName = helpers.PrefixedRandomName("SI")
    17  	})
    18  
    19  	Describe("help", func() {
    20  		When("--help flag is set", func() {
    21  			It("displays command usage to output", func() {
    22  				session := helpers.CF("service", "--help")
    23  				Eventually(session).Should(Say("NAME:"))
    24  				Eventually(session).Should(Say(`\s+service - Show service instance info`))
    25  				Eventually(session).Should(Say("USAGE:"))
    26  				Eventually(session).Should(Say(`\s+cf service SERVICE_INSTANCE`))
    27  				Eventually(session).Should(Say("OPTIONS:"))
    28  				Eventually(session).Should(Say(`\s+\-\-guid\s+Retrieve and display the given service's guid\. All other output for the service is suppressed\.`))
    29  				Eventually(session).Should(Say("SEE ALSO:"))
    30  				Eventually(session).Should(Say(`\s+bind-service, rename-service, update-service`))
    31  				Eventually(session).Should(Exit(0))
    32  			})
    33  		})
    34  	})
    35  
    36  	When("the environment is not setup correctly", func() {
    37  		It("fails with the appropriate errors", func() {
    38  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "service", "some-service")
    39  		})
    40  	})
    41  
    42  	When("an api is targeted, the user is logged in, and an org and space are targeted", func() {
    43  		var (
    44  			orgName   string
    45  			spaceName string
    46  			userName  string
    47  		)
    48  
    49  		BeforeEach(func() {
    50  			orgName = helpers.NewOrgName()
    51  			spaceName = helpers.NewSpaceName()
    52  			helpers.SetupCF(orgName, spaceName)
    53  
    54  			userName, _ = helpers.GetCredentials()
    55  		})
    56  
    57  		AfterEach(func() {
    58  			helpers.QuickDeleteOrg(orgName)
    59  		})
    60  
    61  		When("the service instance does not exist", func() {
    62  			It("returns an error and exits 1", func() {
    63  				session := helpers.CF("service", serviceInstanceName)
    64  				Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
    65  				Eventually(session).Should(Say(""))
    66  				Eventually(session).Should(Say("FAILED"))
    67  				Eventually(session.Err).Should(Say("Service instance %s not found", serviceInstanceName))
    68  				Eventually(session).Should(Exit(1))
    69  			})
    70  		})
    71  
    72  		When("the service instance belongs to this space", func() {
    73  			When("the service instance is a user provided service instance", func() {
    74  				BeforeEach(func() {
    75  					Eventually(helpers.CF("create-user-provided-service", serviceInstanceName)).Should(Exit(0))
    76  				})
    77  
    78  				AfterEach(func() {
    79  					Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0))
    80  				})
    81  
    82  				When("the --guid flag is provided", func() {
    83  					It("displays the service instance GUID", func() {
    84  						session := helpers.CF("service", serviceInstanceName, "--guid")
    85  						Consistently(session).ShouldNot(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
    86  						Eventually(session).Should(Say(helpers.UserProvidedServiceInstanceGUID(serviceInstanceName)))
    87  						Eventually(session).Should(Exit(0))
    88  					})
    89  				})
    90  
    91  				When("no apps are bound to the service instance", func() {
    92  					It("displays service instance info", func() {
    93  						session := helpers.CF("service", serviceInstanceName)
    94  						Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
    95  						Eventually(session).Should(Say(""))
    96  						Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName))
    97  						Eventually(session).Should(Say(`service:\s+user-provided`))
    98  						Eventually(session).Should(Say(""))
    99  						Eventually(session).Should(Say("There are no bound apps for this service."))
   100  						Eventually(session).Should(Say(""))
   101  						Eventually(session).Should(Exit(0))
   102  					})
   103  				})
   104  
   105  				When("apps are bound to the service instance", func() {
   106  					var (
   107  						appName1 string
   108  						appName2 string
   109  					)
   110  
   111  					BeforeEach(func() {
   112  						appName1 = helpers.PrefixedRandomName("1-INTEGRATION-APP")
   113  						appName2 = helpers.PrefixedRandomName("2-INTEGRATION-APP")
   114  
   115  						helpers.WithHelloWorldApp(func(appDir string) {
   116  							Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   117  							Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   118  						})
   119  					})
   120  
   121  					AfterEach(func() {
   122  						Eventually(helpers.CF("delete", appName1, "-f")).Should(Exit(0))
   123  						Eventually(helpers.CF("delete", appName2, "-f")).Should(Exit(0))
   124  					})
   125  
   126  					When("the service bindings do not have binding names", func() {
   127  						BeforeEach(func() {
   128  							Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0))
   129  							Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0))
   130  						})
   131  
   132  						AfterEach(func() {
   133  							Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0))
   134  							Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0))
   135  						})
   136  
   137  						It("displays service instance info", func() {
   138  							session := helpers.CF("service", serviceInstanceName)
   139  							Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
   140  							Eventually(session).Should(Say(""))
   141  							Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName))
   142  							Eventually(session).Should(Say(`service:\s+user-provided`))
   143  							Eventually(session).Should(Say(""))
   144  							Eventually(session).Should(Say("bound apps:"))
   145  							Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`))
   146  							Eventually(session).Should(Say(appName1))
   147  							Eventually(session).Should(Say(appName2))
   148  
   149  							Eventually(session).Should(Exit(0))
   150  						})
   151  					})
   152  
   153  					When("the service bindings have binding names", func() {
   154  						var (
   155  							bindingName1 string
   156  							bindingName2 string
   157  						)
   158  
   159  						BeforeEach(func() {
   160  							helpers.SkipIfVersionLessThan(ccversion.MinVersionBindingNameV2)
   161  							bindingName1 = helpers.PrefixedRandomName("BINDING-NAME")
   162  							bindingName2 = helpers.PrefixedRandomName("BINDING-NAME")
   163  							Eventually(helpers.CF("bind-service", appName1, serviceInstanceName, "--binding-name", bindingName1)).Should(Exit(0))
   164  							Eventually(helpers.CF("bind-service", appName2, serviceInstanceName, "--binding-name", bindingName2)).Should(Exit(0))
   165  						})
   166  
   167  						AfterEach(func() {
   168  							Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0))
   169  							Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0))
   170  						})
   171  
   172  						It("displays service instance info", func() {
   173  							session := helpers.CF("service", serviceInstanceName)
   174  							Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
   175  							Eventually(session).Should(Say(""))
   176  							Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName))
   177  							Eventually(session).Should(Say(`service:\s+user-provided`))
   178  							Eventually(session).Should(Say(""))
   179  							Eventually(session).Should(Say("bound apps:"))
   180  							Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`))
   181  							Eventually(session).Should(Say(`%s\s+%s`, appName1, bindingName1))
   182  							Eventually(session).Should(Say(`%s\s+%s`, appName2, bindingName2))
   183  							Eventually(session).Should(Say(""))
   184  							Eventually(session).Should(Exit(0))
   185  						})
   186  					})
   187  				})
   188  
   189  				When("we update the user provided service instance with tags", func() {
   190  					BeforeEach(func() {
   191  						helpers.SkipIfVersionLessThan(ccversion.MinVersionUserProvidedServiceTagsV2)
   192  						Eventually(helpers.CF("update-user-provided-service", serviceInstanceName,
   193  							"-t", "foo, bar")).Should(Exit(0))
   194  					})
   195  
   196  					It("displays service instance info", func() {
   197  						session := helpers.CF("service", serviceInstanceName)
   198  						Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
   199  						Eventually(session).Should(Say(`tags:\s+foo, bar`))
   200  						Eventually(session).Should(Exit(0))
   201  					})
   202  				})
   203  			})
   204  
   205  			When("a user-provided service instance is created with tags", func() {
   206  				BeforeEach(func() {
   207  					helpers.SkipIfVersionLessThan(ccversion.MinVersionUserProvidedServiceTagsV2)
   208  					Eventually(helpers.CF("create-user-provided-service", serviceInstanceName, "-t", "database, email")).Should(Exit(0))
   209  				})
   210  
   211  				It("displays tag info", func() {
   212  					session := helpers.CF("service", serviceInstanceName)
   213  					Eventually(session).Should(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
   214  					Eventually(session).Should(Say(`tags:\s+database, email`))
   215  					Eventually(session).Should(Exit(0))
   216  				})
   217  			})
   218  
   219  			When("the service instance is a managed service instance", func() {
   220  				var (
   221  					domain      string
   222  					service     string
   223  					servicePlan string
   224  					broker      helpers.ServiceBroker
   225  				)
   226  
   227  				BeforeEach(func() {
   228  					domain = helpers.DefaultSharedDomain()
   229  					service = helpers.PrefixedRandomName("SERVICE")
   230  					servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN")
   231  
   232  					broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan)
   233  					broker.Push()
   234  					broker.Configure(true)
   235  					broker.Create()
   236  
   237  					Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
   238  					Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName, "-t", "database, email")).Should(Exit(0))
   239  				})
   240  
   241  				AfterEach(func() {
   242  					Eventually(helpers.CF("delete-service", serviceInstanceName, "-f")).Should(Exit(0))
   243  					broker.Destroy()
   244  				})
   245  
   246  				When("the --guid flag is provided", func() {
   247  					It("displays the service instance GUID", func() {
   248  						session := helpers.CF("service", serviceInstanceName, "--guid")
   249  						Consistently(session).ShouldNot(Say("Showing info of service %s in org %s / space %s as %s", serviceInstanceName, orgName, spaceName, userName))
   250  						Eventually(session).Should(Say(helpers.ManagedServiceInstanceGUID(serviceInstanceName)))
   251  						Eventually(session).Should(Exit(0))
   252  					})
   253  				})
   254  
   255  				When("apps are bound to the service instance", func() {
   256  					var (
   257  						appName1 string
   258  						appName2 string
   259  					)
   260  
   261  					BeforeEach(func() {
   262  						appName1 = helpers.PrefixedRandomName("1-INTEGRATION-APP")
   263  						appName2 = helpers.PrefixedRandomName("2-INTEGRATION-APP")
   264  
   265  						helpers.WithHelloWorldApp(func(appDir string) {
   266  							Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   267  							Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   268  						})
   269  					})
   270  
   271  					AfterEach(func() {
   272  						Eventually(helpers.CF("delete", appName1, "-f")).Should(Exit(0))
   273  						Eventually(helpers.CF("delete", appName2, "-f")).Should(Exit(0))
   274  					})
   275  
   276  					When("the service bindings do not have binding names", func() {
   277  						BeforeEach(func() {
   278  							Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0))
   279  							Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0))
   280  						})
   281  
   282  						AfterEach(func() {
   283  							Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0))
   284  							Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0))
   285  						})
   286  
   287  						It("displays service instance info", func() {
   288  							session := helpers.CF("service", serviceInstanceName)
   289  							Eventually(session).Should(Say(`Showing info of service %s in org %s / space %s as %s\.\.\.`, serviceInstanceName, orgName, spaceName, userName))
   290  							Eventually(session).Should(Say("\n\n"))
   291  							Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName))
   292  							Consistently(session).ShouldNot(Say("shared from:"))
   293  							Eventually(session).Should(Say(`service:\s+%s`, service))
   294  							Eventually(session).Should(Say(`tags:\s+database, email`))
   295  							Eventually(session).Should(Say(`plan:\s+%s`, servicePlan))
   296  							Eventually(session).Should(Say(`description:\s+fake service`))
   297  							Eventually(session).Should(Say(`documentation:\s+http://documentation\.url`))
   298  							Eventually(session).Should(Say(`dashboard:\s+http://example\.com`))
   299  							Eventually(session).Should(Say("\n\n"))
   300  							Consistently(session).ShouldNot(Say("shared with spaces:"))
   301  							Eventually(session).Should(Say(`Showing status of last operation from service %s\.\.\.`, serviceInstanceName))
   302  							Eventually(session).Should(Say("\n\n"))
   303  							Eventually(session).Should(Say(`status:\s+create succeeded`))
   304  							Eventually(session).Should(Say("message:"))
   305  							Eventually(session).Should(Say(`started:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`))
   306  							Eventually(session).Should(Say(`updated:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`))
   307  							Eventually(session).Should(Say("\n\n"))
   308  							Eventually(session).Should(Say("bound apps:"))
   309  							Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`))
   310  							Eventually(session).Should(Say(appName1))
   311  							Eventually(session).Should(Say(appName2))
   312  
   313  							Eventually(session).Should(Exit(0))
   314  						})
   315  					})
   316  
   317  					When("the service bindings have binding names", func() {
   318  						var (
   319  							bindingName1 string
   320  							bindingName2 string
   321  						)
   322  
   323  						BeforeEach(func() {
   324  							helpers.SkipIfVersionLessThan(ccversion.MinVersionBindingNameV2)
   325  							bindingName1 = helpers.PrefixedRandomName("BINDING-NAME")
   326  							bindingName2 = helpers.PrefixedRandomName("BINDING-NAME")
   327  							Eventually(helpers.CF("bind-service", appName1, serviceInstanceName, "--binding-name", bindingName1)).Should(Exit(0))
   328  							Eventually(helpers.CF("bind-service", appName2, serviceInstanceName, "--binding-name", bindingName2)).Should(Exit(0))
   329  						})
   330  
   331  						AfterEach(func() {
   332  							Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0))
   333  							Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0))
   334  						})
   335  
   336  						It("displays service instance info", func() {
   337  							session := helpers.CF("service", serviceInstanceName)
   338  							Eventually(session).Should(Say(`Showing info of service %s in org %s / space %s as %s\.\.\.`, serviceInstanceName, orgName, spaceName, userName))
   339  							Eventually(session).Should(Say("\n\n"))
   340  							Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName))
   341  							Consistently(session).ShouldNot(Say("shared from:"))
   342  							Eventually(session).Should(Say(`service:\s+%s`, service))
   343  							Eventually(session).Should(Say(`tags:\s+database, email`))
   344  							Eventually(session).Should(Say(`plan:\s+%s`, servicePlan))
   345  							Eventually(session).Should(Say(`description:\s+fake service`))
   346  							Eventually(session).Should(Say(`documentation:\s+http://documentation\.url`))
   347  							Eventually(session).Should(Say(`dashboard:\s+http://example\.com`))
   348  							Eventually(session).Should(Say("\n\n"))
   349  							Consistently(session).ShouldNot(Say("shared with spaces:"))
   350  							Eventually(session).Should(Say(`Showing status of last operation from service %s\.\.\.`, serviceInstanceName))
   351  							Eventually(session).Should(Say("\n\n"))
   352  							Eventually(session).Should(Say(`status:\s+create succeeded`))
   353  							Eventually(session).Should(Say("message:"))
   354  							Eventually(session).Should(Say(`started:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`))
   355  							Eventually(session).Should(Say(`updated:\s+\d{4}-[01]\d-[0-3]\dT[0-2][0-9]:[0-5]\d:[0-5]\dZ`))
   356  							Eventually(session).Should(Say("\n\n"))
   357  							Eventually(session).Should(Say("bound apps:"))
   358  							Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`))
   359  							Eventually(session).Should(Say(`%s\s+%s`, appName1, bindingName1))
   360  							Eventually(session).Should(Say(`%s\s+%s`, appName2, bindingName2))
   361  
   362  							Eventually(session).Should(Exit(0))
   363  						})
   364  					})
   365  
   366  					When("the binding has a state", func() {
   367  						var (
   368  							bindingName1 string
   369  							bindingName2 string
   370  						)
   371  
   372  						BeforeEach(func() {
   373  							helpers.SkipIfVersionLessThan(ccversion.MinVersionAsyncBindingsV2)
   374  							bindingName1 = helpers.PrefixedRandomName("BINDING-NAME")
   375  							bindingName2 = helpers.PrefixedRandomName("BINDING-NAME")
   376  							Eventually(helpers.CF("bind-service", appName1, serviceInstanceName, "--binding-name", bindingName1)).Should(Exit(0))
   377  							Eventually(helpers.CF("bind-service", appName2, serviceInstanceName, "--binding-name", bindingName2)).Should(Exit(0))
   378  						})
   379  
   380  						AfterEach(func() {
   381  							Eventually(helpers.CF("unbind-service", appName1, serviceInstanceName)).Should(Exit(0))
   382  							Eventually(helpers.CF("unbind-service", appName2, serviceInstanceName)).Should(Exit(0))
   383  						})
   384  
   385  						It("displays it in the status field", func() {
   386  							session := helpers.CF("service", serviceInstanceName)
   387  							Eventually(session).Should(Say(`name:\s+%s`, serviceInstanceName))
   388  							Eventually(session).Should(Say("bound apps:"))
   389  							Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`))
   390  							Eventually(session).Should(Say(`%s\s+%s\s+create succeeded`, appName1, bindingName1))
   391  							Eventually(session).Should(Say(`%s\s+%s\s+create succeeded`, appName2, bindingName2))
   392  
   393  							Eventually(session).Should(Exit(0))
   394  						})
   395  					})
   396  				})
   397  			})
   398  		})
   399  	})
   400  
   401  	Context("service instance sharing when there are multiple spaces", func() {
   402  		var (
   403  			orgName         string
   404  			sourceSpaceName string
   405  
   406  			service     string
   407  			servicePlan string
   408  			broker      helpers.ServiceBroker
   409  		)
   410  
   411  		BeforeEach(func() {
   412  			helpers.SkipIfVersionLessThan(ccversion.MinVersionShareServiceV3)
   413  			orgName = helpers.NewOrgName()
   414  			sourceSpaceName = helpers.NewSpaceName()
   415  			helpers.SetupCF(orgName, sourceSpaceName)
   416  
   417  			domain := helpers.DefaultSharedDomain()
   418  			service = helpers.PrefixedRandomName("SERVICE")
   419  			servicePlan = helpers.PrefixedRandomName("SERVICE-PLAN")
   420  			broker = helpers.NewServiceBroker(helpers.NewServiceBrokerName(), helpers.NewAssets().ServiceBroker, domain, service, servicePlan)
   421  			broker.Push()
   422  			broker.Configure(true)
   423  			broker.Create()
   424  
   425  			Eventually(helpers.CF("enable-service-access", service)).Should(Exit(0))
   426  			Eventually(helpers.CF("create-service", service, servicePlan, serviceInstanceName)).Should(Exit(0))
   427  		})
   428  
   429  		AfterEach(func() {
   430  			// need to login as admin
   431  			helpers.LoginCF()
   432  			helpers.TargetOrgAndSpace(orgName, sourceSpaceName)
   433  			broker.Destroy()
   434  			helpers.QuickDeleteOrg(orgName)
   435  		})
   436  
   437  		Context("service has no type of shares", func() {
   438  			When("the service is shareable", func() {
   439  				It("should not display shared from or shared with information, but DOES display not currently shared info", func() {
   440  					session := helpers.CF("service", serviceInstanceName)
   441  					Eventually(session).Should(Say("This service is not currently shared."))
   442  					Eventually(session).Should(Exit(0))
   443  				})
   444  			})
   445  		})
   446  
   447  		Context("service is shared between two spaces", func() {
   448  			var (
   449  				targetSpaceName string
   450  			)
   451  
   452  			BeforeEach(func() {
   453  				targetSpaceName = helpers.NewSpaceName()
   454  				helpers.CreateOrgAndSpace(orgName, targetSpaceName)
   455  				helpers.TargetOrgAndSpace(orgName, sourceSpaceName)
   456  				Eventually(helpers.CF("share-service", serviceInstanceName, "-s", targetSpaceName)).Should(Exit(0))
   457  			})
   458  
   459  			When("the user is targeted to the source space", func() {
   460  				When("there are externally bound apps to the service", func() {
   461  					BeforeEach(func() {
   462  						helpers.TargetOrgAndSpace(orgName, targetSpaceName)
   463  						helpers.WithHelloWorldApp(func(appDir string) {
   464  							appName1 := helpers.NewAppName()
   465  							Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   466  							Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0))
   467  
   468  							appName2 := helpers.NewAppName()
   469  							Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   470  							Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0))
   471  						})
   472  						helpers.TargetOrgAndSpace(orgName, sourceSpaceName)
   473  					})
   474  
   475  					It("should display the number of bound apps next to the target space name", func() {
   476  						session := helpers.CF("service", serviceInstanceName)
   477  						Eventually(session).Should(Say("shared with spaces:"))
   478  						Eventually(session).Should(Say(`org\s+space\s+bindings`))
   479  						Eventually(session).Should(Say(`%s\s+%s\s+2`, orgName, targetSpaceName))
   480  						Eventually(session).Should(Exit(0))
   481  					})
   482  				})
   483  
   484  				When("there are no externally bound apps to the service", func() {
   485  					It("should NOT display the number of bound apps next to the target space name", func() {
   486  						session := helpers.CF("service", serviceInstanceName)
   487  						Eventually(session).Should(Say("shared with spaces:"))
   488  						Eventually(session).Should(Say(`org\s+space\s+bindings`))
   489  						Eventually(session).Should(Exit(0))
   490  					})
   491  				})
   492  
   493  				When("the service is no longer shareable", func() {
   494  					Context("due to global settings", func() {
   495  						BeforeEach(func() {
   496  							helpers.DisableFeatureFlag("service_instance_sharing")
   497  						})
   498  
   499  						AfterEach(func() {
   500  							helpers.EnableFeatureFlag("service_instance_sharing")
   501  						})
   502  
   503  						It("should display that the service instance feature flag is disabled", func() {
   504  							session := helpers.CF("service", serviceInstanceName)
   505  							Eventually(session).Should(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform.`))
   506  							Eventually(session).Should(Exit(0))
   507  						})
   508  					})
   509  
   510  					Context("due to service broker settings", func() {
   511  						BeforeEach(func() {
   512  							broker.Configure(false)
   513  							broker.Update()
   514  						})
   515  
   516  						It("should display that service instance sharing is disabled for this service", func() {
   517  							session := helpers.CF("service", serviceInstanceName)
   518  							Eventually(session).Should(Say("Service instance sharing is disabled for this service."))
   519  							Eventually(session).Should(Exit(0))
   520  						})
   521  					})
   522  
   523  					Context("due to global settings AND service broker settings", func() {
   524  						BeforeEach(func() {
   525  							helpers.DisableFeatureFlag("service_instance_sharing")
   526  							broker.Configure(false)
   527  							broker.Update()
   528  						})
   529  
   530  						AfterEach(func() {
   531  							helpers.EnableFeatureFlag("service_instance_sharing")
   532  						})
   533  
   534  						It("should display that service instance sharing is disabled for this service", func() {
   535  							session := helpers.CF("service", serviceInstanceName)
   536  							Eventually(session).Should(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform. Also, service instance sharing is disabled for this service.`))
   537  							Eventually(session).Should(Exit(0))
   538  						})
   539  					})
   540  				})
   541  			})
   542  
   543  			When("the user is targeted to the target space", func() {
   544  				var appName1, appName2 string
   545  
   546  				BeforeEach(func() {
   547  					// We test that the app names are listed in alphanumeric sort order
   548  					appName1 = helpers.PrefixedRandomName("2-INTEGRATION-APP")
   549  					appName2 = helpers.PrefixedRandomName("1-INTEGRATION-APP")
   550  					helpers.TargetOrgAndSpace(orgName, targetSpaceName)
   551  					helpers.WithHelloWorldApp(func(appDir string) {
   552  						Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   553  						Eventually(helpers.CF("bind-service", appName1, serviceInstanceName)).Should(Exit(0))
   554  
   555  						Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
   556  						Eventually(helpers.CF("bind-service", appName2, serviceInstanceName)).Should(Exit(0))
   557  					})
   558  				})
   559  
   560  				When("there are bound apps to the service with no binding names", func() {
   561  					It("should display the bound apps in alphanumeric sort order", func() {
   562  						session := helpers.CF("service", serviceInstanceName)
   563  						Eventually(session).Should(Say(`shared from org/space:\s+%s / %s`, orgName, sourceSpaceName))
   564  						Eventually(session).Should(Say("\n\n"))
   565  						Eventually(session).Should(Say("bound apps:"))
   566  						Eventually(session).Should(Say(`name\s+binding name\s+status\s+message`))
   567  						Eventually(session).Should(Say(appName2))
   568  						Eventually(session).Should(Say(appName1))
   569  						Eventually(session).Should(Exit(0))
   570  					})
   571  				})
   572  			})
   573  		})
   574  	})
   575  })