github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/command/v2/service_command_test.go (about)

     1  package v2_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	"code.cloudfoundry.org/cli/actor/v2action"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
    10  	"code.cloudfoundry.org/cli/command/commandfakes"
    11  	. "code.cloudfoundry.org/cli/command/v2"
    12  	"code.cloudfoundry.org/cli/command/v2/v2fakes"
    13  	"code.cloudfoundry.org/cli/util/configv3"
    14  	"code.cloudfoundry.org/cli/util/ui"
    15  	. "github.com/onsi/ginkgo"
    16  	. "github.com/onsi/gomega"
    17  	. "github.com/onsi/gomega/gbytes"
    18  )
    19  
    20  var _ = Describe("service Command", func() {
    21  	var (
    22  		cmd             ServiceCommand
    23  		testUI          *ui.UI
    24  		fakeConfig      *commandfakes.FakeConfig
    25  		fakeSharedActor *commandfakes.FakeSharedActor
    26  		fakeActor       *v2fakes.FakeServiceActor
    27  		binaryName      string
    28  		executeErr      error
    29  	)
    30  
    31  	BeforeEach(func() {
    32  		testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
    33  		fakeConfig = new(commandfakes.FakeConfig)
    34  		fakeSharedActor = new(commandfakes.FakeSharedActor)
    35  		fakeActor = new(v2fakes.FakeServiceActor)
    36  
    37  		cmd = ServiceCommand{
    38  			UI:          testUI,
    39  			Config:      fakeConfig,
    40  			SharedActor: fakeSharedActor,
    41  			Actor:       fakeActor,
    42  		}
    43  
    44  		binaryName = "faceman"
    45  		fakeConfig.BinaryNameReturns(binaryName)
    46  
    47  		cmd.RequiredArgs.ServiceInstance = "some-service-instance"
    48  	})
    49  
    50  	JustBeforeEach(func() {
    51  		executeErr = cmd.Execute(nil)
    52  	})
    53  
    54  	Context("when an error is encountered checking if the environment is setup correctly", func() {
    55  		BeforeEach(func() {
    56  			fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName})
    57  		})
    58  
    59  		It("returns an error", func() {
    60  			Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName}))
    61  
    62  			Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1))
    63  			checkTargetedOrgArg, checkTargetedSpaceArg := fakeSharedActor.CheckTargetArgsForCall(0)
    64  			Expect(checkTargetedOrgArg).To(BeTrue())
    65  			Expect(checkTargetedSpaceArg).To(BeTrue())
    66  		})
    67  	})
    68  
    69  	Context("when the user is logged in and an org and space are targeted", func() {
    70  		BeforeEach(func() {
    71  			fakeConfig.TargetedOrganizationReturns(configv3.Organization{
    72  				Name: "some-org",
    73  			})
    74  			fakeConfig.TargetedSpaceReturns(configv3.Space{
    75  				GUID: "some-space-guid",
    76  				Name: "some-space",
    77  			})
    78  		})
    79  
    80  		Context("when getting the current user fails", func() {
    81  			BeforeEach(func() {
    82  				fakeConfig.CurrentUserReturns(configv3.User{}, errors.New("get-user-error"))
    83  			})
    84  
    85  			It("returns the error", func() {
    86  				Expect(executeErr).To(MatchError("get-user-error"))
    87  				Expect(fakeConfig.CurrentUserCallCount()).To(Equal(1))
    88  			})
    89  		})
    90  
    91  		Context("when getting the current user succeeds", func() {
    92  			BeforeEach(func() {
    93  				fakeConfig.CurrentUserReturns(configv3.User{Name: "some-user"}, nil)
    94  			})
    95  
    96  			Context("when the '--guid' flag is provided", func() {
    97  				BeforeEach(func() {
    98  					cmd.GUID = true
    99  				})
   100  
   101  				Context("when the service instance does not exist", func() {
   102  					BeforeEach(func() {
   103  						fakeActor.GetServiceInstanceByNameAndSpaceReturns(
   104  							v2action.ServiceInstance{},
   105  							v2action.Warnings{"get-service-instance-warning"},
   106  							actionerror.ServiceInstanceNotFoundError{
   107  								GUID: "non-existant-service-instance-guid",
   108  								Name: "non-existant-service-instance",
   109  							})
   110  					})
   111  
   112  					It("returns ServiceInstanceNotFoundError", func() {
   113  						Expect(executeErr).To(MatchError(actionerror.ServiceInstanceNotFoundError{
   114  							GUID: "non-existant-service-instance-guid",
   115  							Name: "non-existant-service-instance",
   116  						}))
   117  
   118  						Expect(testUI.Err).To(Say("get-service-instance-warning"))
   119  
   120  						Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1))
   121  						serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceByNameAndSpaceArgsForCall(0)
   122  						Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   123  						Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   124  
   125  						Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(0))
   126  					})
   127  				})
   128  
   129  				Context("when an error is encountered getting the service instance", func() {
   130  					var expectedErr error
   131  
   132  					BeforeEach(func() {
   133  						expectedErr = errors.New("get-service-instance-error")
   134  						fakeActor.GetServiceInstanceByNameAndSpaceReturns(
   135  							v2action.ServiceInstance{},
   136  							v2action.Warnings{"get-service-instance-warning"},
   137  							expectedErr,
   138  						)
   139  					})
   140  
   141  					It("returns the error", func() {
   142  						Expect(executeErr).To(MatchError(expectedErr))
   143  
   144  						Expect(testUI.Err).To(Say("get-service-instance-warning"))
   145  
   146  						Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1))
   147  						serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceByNameAndSpaceArgsForCall(0)
   148  						Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   149  						Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   150  
   151  						Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(0))
   152  					})
   153  				})
   154  
   155  				Context("when no errors are encountered getting the service instance", func() {
   156  					BeforeEach(func() {
   157  						fakeActor.GetServiceInstanceByNameAndSpaceReturns(
   158  							v2action.ServiceInstance{
   159  								GUID: "some-service-instance-guid",
   160  								Name: "some-service-instance",
   161  							},
   162  							v2action.Warnings{"get-service-instance-warning"},
   163  							nil,
   164  						)
   165  					})
   166  
   167  					It("displays the service instance guid", func() {
   168  						Expect(executeErr).ToNot(HaveOccurred())
   169  
   170  						Expect(testUI.Out).To(Say("some-service-instance-guid"))
   171  						Expect(testUI.Err).To(Say("get-service-instance-warning"))
   172  
   173  						Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1))
   174  						serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceByNameAndSpaceArgsForCall(0)
   175  						Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   176  						Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   177  
   178  						Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(0))
   179  					})
   180  				})
   181  			})
   182  
   183  			Context("when the '--guid' flag is not provided", func() {
   184  				Context("when the service instance does not exist", func() {
   185  					BeforeEach(func() {
   186  						fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   187  							v2action.ServiceInstanceSummary{},
   188  							v2action.Warnings{"get-service-instance-summary-warning"},
   189  							actionerror.ServiceInstanceNotFoundError{
   190  								GUID: "non-existant-service-instance-guid",
   191  								Name: "non-existant-service-instance",
   192  							})
   193  					})
   194  
   195  					It("returns ServiceInstanceNotFoundError", func() {
   196  						Expect(executeErr).To(MatchError(actionerror.ServiceInstanceNotFoundError{
   197  							GUID: "non-existant-service-instance-guid",
   198  							Name: "non-existant-service-instance",
   199  						}))
   200  
   201  						Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   202  
   203  						Expect(testUI.Err).To(Say("get-service-instance-summary-warning"))
   204  
   205  						Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   206  						serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   207  						Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   208  						Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   209  
   210  						Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   211  					})
   212  				})
   213  
   214  				Context("when an error is encountered getting the service instance summary", func() {
   215  					var expectedErr error
   216  
   217  					BeforeEach(func() {
   218  						expectedErr = errors.New("get-service-instance-summary-error")
   219  						fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   220  							v2action.ServiceInstanceSummary{},
   221  							v2action.Warnings{"get-service-instance-summary-warning"},
   222  							expectedErr)
   223  					})
   224  
   225  					It("returns the error", func() {
   226  						Expect(executeErr).To(MatchError(expectedErr))
   227  
   228  						Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   229  
   230  						Expect(testUI.Err).To(Say("get-service-instance-summary-warning"))
   231  
   232  						Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   233  						serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   234  						Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   235  						Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   236  
   237  						Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   238  					})
   239  				})
   240  
   241  				Context("when no errors are encountered getting the service instance summary", func() {
   242  					Context("when the service instance is a managed service instance", func() {
   243  						var returnedSummary v2action.ServiceInstanceSummary
   244  
   245  						BeforeEach(func() {
   246  							returnedSummary = v2action.ServiceInstanceSummary{
   247  								ServiceInstance: v2action.ServiceInstance{
   248  									Name:         "some-service-instance",
   249  									Type:         constant.ServiceInstanceTypeManagedService,
   250  									Tags:         []string{"tag-1", "tag-2", "tag-3"},
   251  									DashboardURL: "some-dashboard",
   252  									LastOperation: ccv2.LastOperation{
   253  										Type:        "some-type",
   254  										State:       "some-state",
   255  										Description: "some-last-operation-description",
   256  										UpdatedAt:   "some-updated-at-time",
   257  										CreatedAt:   "some-created-at-time",
   258  									},
   259  								},
   260  								ServicePlan: v2action.ServicePlan{Name: "some-plan"},
   261  								Service: v2action.Service{
   262  									Label:            "some-service",
   263  									Description:      "some-description",
   264  									DocumentationURL: "some-docs-url",
   265  								},
   266  							}
   267  
   268  							fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   269  								returnedSummary,
   270  								v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   271  								nil)
   272  						})
   273  
   274  						Context("when the service instance is not shared and is not shareable", func() {
   275  							BeforeEach(func() {
   276  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsNotShared
   277  								returnedSummary.Service.Extra.Shareable = false
   278  								returnedSummary.BoundApplications = []v2action.BoundApplication{
   279  									{
   280  										AppName:            "app-1",
   281  										ServiceBindingName: "binding-name-1",
   282  									},
   283  									{
   284  										AppName:            "app-2",
   285  										ServiceBindingName: "binding-name-2",
   286  									},
   287  									{
   288  										AppName:            "app-3",
   289  										ServiceBindingName: "binding-name-3",
   290  									},
   291  								}
   292  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   293  									returnedSummary,
   294  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   295  									nil)
   296  
   297  							})
   298  
   299  							It("displays the service instance summary, all warnings and bound applications in the correct position", func() {
   300  								Expect(executeErr).ToNot(HaveOccurred())
   301  
   302  								Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   303  								Expect(testUI.Out).To(Say("\n\n"))
   304  								Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   305  								Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   306  								Expect(testUI.Out).To(Say("service:\\s+some-service"))
   307  								Expect(testUI.Out).To(Say("tags:\\s+tag-1, tag-2, tag-3"))
   308  								Expect(testUI.Out).To(Say("plan:\\s+some-plan"))
   309  								Expect(testUI.Out).To(Say("description:\\s+some-description"))
   310  								Expect(testUI.Out).To(Say("documentation:\\s+some-docs-url"))
   311  								Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   312  								Expect(testUI.Out).To(Say("\n\n"))
   313  								Expect(testUI.Out).ToNot(Say("shared with spaces:"))
   314  								Expect(testUI.Out).ToNot(Say("org\\s+space\\s+bindings"))
   315  								Expect(testUI.Out).ToNot(Say("This service is not currently shared."))
   316  
   317  								Expect(testUI.Out).To(Say("bound apps:"))
   318  								Expect(testUI.Out).To(Say("name\\s+binding name"))
   319  								Expect(testUI.Out).To(Say("app-1\\s+binding-name-1"))
   320  								Expect(testUI.Out).To(Say("app-2\\s+binding-name-2"))
   321  								Expect(testUI.Out).To(Say("app-3\\s+binding-name-3"))
   322  								Expect(testUI.Out).To(Say("\n\n"))
   323  
   324  								Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   325  								Expect(testUI.Out).To(Say("\n\n"))
   326  								Expect(testUI.Out).To(Say("status:\\s+some-type some-state"))
   327  								Expect(testUI.Out).To(Say("message:\\s+some-last-operation-description"))
   328  								Expect(testUI.Out).To(Say("started:\\s+some-created-at-time"))
   329  								Expect(testUI.Out).To(Say("updated:\\s+some-updated-at-time"))
   330  
   331  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   332  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   333  
   334  								Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   335  								serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   336  								Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   337  								Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   338  
   339  								Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   340  							})
   341  						})
   342  
   343  						Context("when the service instance is not shared and is shareable", func() {
   344  							BeforeEach(func() {
   345  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsNotShared
   346  								returnedSummary.ServiceInstanceSharingFeatureFlag = true
   347  								returnedSummary.Service.Extra.Shareable = true
   348  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   349  									returnedSummary,
   350  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   351  									nil)
   352  							})
   353  
   354  							It("displays the service instance summary and all warnings", func() {
   355  								Expect(executeErr).ToNot(HaveOccurred())
   356  
   357  								Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   358  								Expect(testUI.Out).To(Say("\n\n"))
   359  								Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   360  								Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   361  								Expect(testUI.Out).To(Say("service:\\s+some-service"))
   362  								Expect(testUI.Out).To(Say("tags:\\s+tag-1, tag-2, tag-3"))
   363  								Expect(testUI.Out).To(Say("plan:\\s+some-plan"))
   364  								Expect(testUI.Out).To(Say("description:\\s+some-description"))
   365  								Expect(testUI.Out).To(Say("documentation:\\s+some-docs-url"))
   366  								Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   367  								Expect(testUI.Out).To(Say("\n\n"))
   368  								Expect(testUI.Out).ToNot(Say("shared with spaces:"))
   369  								Expect(testUI.Out).ToNot(Say("org\\s+space\\s+bindings"))
   370  								Expect(testUI.Out).To(Say("This service is not currently shared."))
   371  								Expect(testUI.Out).To(Say("\n\n"))
   372  								Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   373  								Expect(testUI.Out).To(Say("\n\n"))
   374  								Expect(testUI.Out).To(Say("status:\\s+some-type some-state"))
   375  								Expect(testUI.Out).To(Say("message:\\s+some-last-operation-description"))
   376  								Expect(testUI.Out).To(Say("started:\\s+some-created-at-time"))
   377  								Expect(testUI.Out).To(Say("updated:\\s+some-updated-at-time"))
   378  
   379  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   380  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   381  
   382  								Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   383  								serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   384  								Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   385  								Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   386  
   387  								Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   388  							})
   389  						})
   390  
   391  						Context("when the service instance is shared from another space", func() {
   392  							BeforeEach(func() {
   393  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsSharedFrom
   394  								returnedSummary.ServiceInstanceSharedFrom = v2action.ServiceInstanceSharedFrom{
   395  									SpaceGUID:        "some-space-guid",
   396  									SpaceName:        "some-space-name",
   397  									OrganizationName: "some-org-name",
   398  								}
   399  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   400  									returnedSummary,
   401  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   402  									nil)
   403  							})
   404  
   405  							It("displays the shared from info and does not display the shared to info", func() {
   406  								Expect(executeErr).ToNot(HaveOccurred())
   407  
   408  								Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   409  								Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   410  								Expect(testUI.Out).To(Say("shared from org/space:\\s+some-org-name / some-space-name"))
   411  								Expect(testUI.Out).To(Say("service:\\s+some-service"))
   412  								Expect(testUI.Out).ToNot(Say("shared with spaces:"))
   413  
   414  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   415  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   416  							})
   417  						})
   418  
   419  						Context("when the service instance is shared to other spaces", func() {
   420  							BeforeEach(func() {
   421  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsSharedTo
   422  								returnedSummary.ServiceInstanceSharedTos = []v2action.ServiceInstanceSharedTo{
   423  									{
   424  										SpaceGUID:        "another-space-guid",
   425  										SpaceName:        "another-space-name",
   426  										OrganizationName: "another-org-name",
   427  										BoundAppCount:    2,
   428  									},
   429  									{
   430  										SpaceGUID:        "yet-another-space-guid",
   431  										SpaceName:        "yet-another-space-name",
   432  										OrganizationName: "yet-another-org-name",
   433  										BoundAppCount:    3,
   434  									},
   435  								}
   436  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   437  									returnedSummary,
   438  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   439  									nil)
   440  							})
   441  
   442  							Context("when the service instance is still shareable", func() {
   443  								It("displays the shared to info and does not display the shared from info", func() {
   444  									Expect(executeErr).ToNot(HaveOccurred())
   445  
   446  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   447  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   448  									Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   449  									Expect(testUI.Out).To(Say("shared with spaces:"))
   450  									Expect(testUI.Out).To(Say("org\\s+space\\s+bindings"))
   451  									Expect(testUI.Out).To(Say("another-org-name\\s+another-space-name\\s+2"))
   452  									Expect(testUI.Out).To(Say("yet-another-org-name\\s+yet-another-space-name\\s+3"))
   453  									Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   454  
   455  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   456  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   457  								})
   458  							})
   459  
   460  							Context("when the service instance is no longer shareable due to global settings only", func() {
   461  								BeforeEach(func() {
   462  									returnedSummary.ServiceInstanceSharingFeatureFlag = false
   463  									returnedSummary.Service.Extra.Shareable = true
   464  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   465  										returnedSummary,
   466  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   467  										nil)
   468  								})
   469  
   470  								It("displays the shared to info and message that the service instance feature flag is disabled", func() {
   471  									Expect(executeErr).ToNot(HaveOccurred())
   472  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   473  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   474  									Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   475  									Expect(testUI.Out).To(Say("\n\n"))
   476  									Expect(testUI.Out).To(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform.`))
   477  									Expect(testUI.Out).To(Say("\n\n"))
   478  									Expect(testUI.Out).To(Say("shared with spaces:"))
   479  									Expect(testUI.Out).To(Say("org\\s+space\\s+bindings"))
   480  									Expect(testUI.Out).To(Say("another-org-name\\s+another-space-name\\s+2"))
   481  									Expect(testUI.Out).To(Say("yet-another-org-name\\s+yet-another-space-name\\s+3"))
   482  									Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   483  
   484  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   485  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   486  								})
   487  							})
   488  
   489  							Context("when the service instance is no longer shareable due to service broker settings only", func() {
   490  								BeforeEach(func() {
   491  									returnedSummary.ServiceInstanceSharingFeatureFlag = true
   492  									returnedSummary.Service.Extra.Shareable = false
   493  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   494  										returnedSummary,
   495  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   496  										nil)
   497  								})
   498  
   499  								It("displays the shared to info and message that service instance sharing is disabled for the service", func() {
   500  									Expect(executeErr).ToNot(HaveOccurred())
   501  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   502  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   503  									Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   504  									Expect(testUI.Out).To(Say("\n\n"))
   505  									Expect(testUI.Out).To(Say("Service instance sharing is disabled for this service."))
   506  									Expect(testUI.Out).To(Say("\n\n"))
   507  									Expect(testUI.Out).To(Say("shared with spaces:"))
   508  									Expect(testUI.Out).To(Say("org\\s+space\\s+bindings"))
   509  									Expect(testUI.Out).To(Say("another-org-name\\s+another-space-name\\s+2"))
   510  									Expect(testUI.Out).To(Say("yet-another-org-name\\s+yet-another-space-name\\s+3"))
   511  									Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   512  
   513  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   514  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   515  								})
   516  							})
   517  							Context("when the service instance is no longer shareable due to  global settings AND service broker settings", func() {
   518  								BeforeEach(func() {
   519  									returnedSummary.ServiceInstanceSharingFeatureFlag = false
   520  									returnedSummary.Service.Extra.Shareable = false
   521  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   522  										returnedSummary,
   523  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   524  										nil)
   525  								})
   526  
   527  								It("displays the shared to info, the message that the service instance feature flag is disabled and that service instance sharing is disabled for the service", func() {
   528  									Expect(executeErr).ToNot(HaveOccurred())
   529  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   530  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   531  									Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   532  									Expect(testUI.Out).To(Say("\n\n"))
   533  									Expect(testUI.Out).To(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform. Also, service instance sharing is disabled for this service.`))
   534  									Expect(testUI.Out).To(Say("\n\n"))
   535  									Expect(testUI.Out).To(Say("shared with spaces:"))
   536  									Expect(testUI.Out).To(Say("org\\s+space\\s+bindings"))
   537  									Expect(testUI.Out).To(Say("another-org-name\\s+another-space-name\\s+2"))
   538  									Expect(testUI.Out).To(Say("yet-another-org-name\\s+yet-another-space-name\\s+3"))
   539  									Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   540  
   541  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   542  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   543  								})
   544  							})
   545  						})
   546  
   547  						Context("when the service instance has bound apps", func() {
   548  							Context("when the service bindings have binding names", func() {
   549  								BeforeEach(func() {
   550  									returnedSummary.BoundApplications = []v2action.BoundApplication{
   551  										{
   552  											AppName:            "app-1",
   553  											ServiceBindingName: "binding-name-1",
   554  										},
   555  										{
   556  											AppName:            "app-2",
   557  											ServiceBindingName: "binding-name-2",
   558  										},
   559  										{
   560  											AppName:            "app-3",
   561  											ServiceBindingName: "binding-name-3",
   562  										},
   563  									}
   564  
   565  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   566  										returnedSummary,
   567  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   568  										nil)
   569  								})
   570  
   571  								It("displays the bound apps table with service binding names", func() {
   572  									Expect(executeErr).ToNot(HaveOccurred())
   573  
   574  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   575  									Expect(testUI.Out).To(Say("\n\n"))
   576  									Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   577  									Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   578  									Expect(testUI.Out).To(Say("\n\n"))
   579  									Expect(testUI.Out).To(Say("bound apps:"))
   580  									Expect(testUI.Out).To(Say("name\\s+binding name"))
   581  									Expect(testUI.Out).To(Say("app-1\\s+binding-name-1"))
   582  									Expect(testUI.Out).To(Say("app-2\\s+binding-name-2"))
   583  									Expect(testUI.Out).To(Say("app-3\\s+binding-name-3"))
   584  									Expect(testUI.Out).To(Say("\n\n"))
   585  									Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   586  
   587  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   588  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   589  
   590  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   591  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   592  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   593  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   594  
   595  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   596  								})
   597  							})
   598  
   599  							Context("when the service bindings do not have binding names", func() {
   600  								BeforeEach(func() {
   601  									returnedSummary.BoundApplications = []v2action.BoundApplication{
   602  										{AppName: "app-1"},
   603  										{AppName: "app-2"},
   604  										{AppName: "app-3"},
   605  									}
   606  
   607  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   608  										returnedSummary,
   609  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   610  										nil)
   611  								})
   612  
   613  								It("displays the bound apps table with NO service binding names", func() {
   614  									Expect(executeErr).ToNot(HaveOccurred())
   615  
   616  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   617  									Expect(testUI.Out).To(Say("\n\n"))
   618  									Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   619  									Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   620  									Expect(testUI.Out).To(Say("\n\n"))
   621  									Expect(testUI.Out).To(Say("bound apps:"))
   622  									Expect(testUI.Out).To(Say("name\\s+binding name"))
   623  									Expect(testUI.Out).To(Say("app-1"))
   624  									Expect(testUI.Out).To(Say("app-2"))
   625  									Expect(testUI.Out).To(Say("app-3"))
   626  									Expect(testUI.Out).To(Say("\n\n"))
   627  									Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   628  
   629  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   630  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   631  
   632  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   633  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   634  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   635  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   636  
   637  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   638  								})
   639  							})
   640  						})
   641  
   642  						Context("when the service instance does not have bound apps", func() {
   643  							It("displays a message indicating that there are no bound apps", func() {
   644  								Expect(executeErr).ToNot(HaveOccurred())
   645  
   646  								Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   647  								Expect(testUI.Out).To(Say("\n\n"))
   648  								Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   649  								Expect(testUI.Out).To(Say("dashboard:\\s+some-dashboard"))
   650  								Expect(testUI.Out).To(Say("\n\n"))
   651  								Expect(testUI.Out).To(Say("There are no bound apps for this service."))
   652  								Expect(testUI.Out).To(Say("\n\n"))
   653  								Expect(testUI.Out).To(Say("Showing status of last operation from service some-service-instance\\.\\.\\."))
   654  
   655  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   656  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   657  
   658  								Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   659  								serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   660  								Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   661  								Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   662  
   663  								Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   664  							})
   665  
   666  						})
   667  					})
   668  
   669  					Context("when the service instance is a user provided service instance", func() {
   670  						BeforeEach(func() {
   671  							fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   672  								v2action.ServiceInstanceSummary{
   673  									ServiceInstance: v2action.ServiceInstance{
   674  										Name: "some-service-instance",
   675  										Type: constant.ServiceInstanceTypeUserProvidedService,
   676  									},
   677  								},
   678  								v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   679  								nil,
   680  							)
   681  						})
   682  
   683  						It("displays a smaller service instance summary than for managed service instances", func() {
   684  							Expect(executeErr).ToNot(HaveOccurred())
   685  
   686  							Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   687  							Expect(testUI.Out).To(Say(""))
   688  							Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   689  							Expect(testUI.Out).ToNot(Say("shared from"))
   690  							Expect(testUI.Out).To(Say("service:\\s+user-provided"))
   691  							Expect(testUI.Out).To(Say("tags:"))
   692  							Expect(testUI.Out).ToNot(Say("plan:"))
   693  							Expect(testUI.Out).ToNot(Say("description:"))
   694  							Expect(testUI.Out).ToNot(Say("documentation:"))
   695  							Expect(testUI.Out).ToNot(Say("dashboard:"))
   696  							Expect(testUI.Out).ToNot(Say("shared with spaces"))
   697  							Expect(testUI.Out).ToNot(Say("last operation"))
   698  							Expect(testUI.Out).ToNot(Say("status:"))
   699  							Expect(testUI.Out).ToNot(Say("message:"))
   700  							Expect(testUI.Out).ToNot(Say("started:"))
   701  							Expect(testUI.Out).ToNot(Say("updated:"))
   702  
   703  							Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   704  							Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   705  
   706  							Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   707  							serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   708  							Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   709  							Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   710  
   711  							Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   712  						})
   713  
   714  						Context("when the service instance has bound apps", func() {
   715  							Context("when the service bindings have binding names", func() {
   716  								BeforeEach(func() {
   717  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   718  										v2action.ServiceInstanceSummary{
   719  											ServiceInstance: v2action.ServiceInstance{
   720  												Name: "some-service-instance",
   721  												Type: constant.ServiceInstanceTypeUserProvidedService,
   722  											},
   723  											BoundApplications: []v2action.BoundApplication{
   724  												{
   725  													AppName:            "app-1",
   726  													ServiceBindingName: "binding-name-1",
   727  												},
   728  												{
   729  													AppName:            "app-2",
   730  													ServiceBindingName: "binding-name-2",
   731  												},
   732  												{
   733  													AppName:            "app-3",
   734  													ServiceBindingName: "binding-name-3",
   735  												},
   736  											},
   737  										},
   738  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   739  										nil,
   740  									)
   741  								})
   742  
   743  								It("displays the bound apps table with service binding names", func() {
   744  									Expect(executeErr).ToNot(HaveOccurred())
   745  
   746  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   747  									Expect(testUI.Out).To(Say("\n\n"))
   748  									Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   749  									Expect(testUI.Out).To(Say("service:\\s+user-provided"))
   750  									Expect(testUI.Out).To(Say("\n\n"))
   751  									Expect(testUI.Out).To(Say("bound apps:"))
   752  									Expect(testUI.Out).To(Say("name\\s+binding name"))
   753  									Expect(testUI.Out).To(Say("app-1\\s+binding-name-1"))
   754  									Expect(testUI.Out).To(Say("app-2\\s+binding-name-2"))
   755  									Expect(testUI.Out).To(Say("app-3\\s+binding-name-3"))
   756  
   757  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   758  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   759  
   760  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   761  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   762  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   763  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   764  
   765  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   766  								})
   767  							})
   768  
   769  							Context("when the service bindings do not have binding names", func() {
   770  								BeforeEach(func() {
   771  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   772  										v2action.ServiceInstanceSummary{
   773  											ServiceInstance: v2action.ServiceInstance{
   774  												Name: "some-service-instance",
   775  												Type: constant.ServiceInstanceTypeUserProvidedService,
   776  											},
   777  											BoundApplications: []v2action.BoundApplication{
   778  												{AppName: "app-1"},
   779  												{AppName: "app-2"},
   780  												{AppName: "app-3"},
   781  											},
   782  										},
   783  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   784  										nil,
   785  									)
   786  								})
   787  
   788  								It("displays the bound apps table with NO service binding names", func() {
   789  									Expect(executeErr).ToNot(HaveOccurred())
   790  
   791  									Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   792  									Expect(testUI.Out).To(Say("\n\n"))
   793  									Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   794  									Expect(testUI.Out).To(Say("service:\\s+user-provided"))
   795  									Expect(testUI.Out).To(Say("\n\n"))
   796  									Expect(testUI.Out).To(Say("bound apps:"))
   797  									Expect(testUI.Out).To(Say("name\\s+binding name"))
   798  									Expect(testUI.Out).To(Say("app-1"))
   799  									Expect(testUI.Out).To(Say("app-2"))
   800  									Expect(testUI.Out).To(Say("app-3"))
   801  
   802  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   803  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   804  
   805  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   806  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   807  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   808  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   809  
   810  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   811  								})
   812  
   813  							})
   814  						})
   815  
   816  						Context("when the service instance does not have bound apps", func() {
   817  							It("displays a message indicating that there are no bound apps", func() {
   818  								Expect(executeErr).ToNot(HaveOccurred())
   819  
   820  								Expect(testUI.Out).To(Say("Showing info of service some-service-instance in org some-org / space some-space as some-user\\.\\.\\."))
   821  								Expect(testUI.Out).To(Say("\n\n"))
   822  								Expect(testUI.Out).To(Say("name:\\s+some-service-instance"))
   823  								Expect(testUI.Out).To(Say("service:\\s+user-provided"))
   824  								Expect(testUI.Out).To(Say("\n\n"))
   825  								Expect(testUI.Out).To(Say("There are no bound apps for this service."))
   826  							})
   827  						})
   828  
   829  						Context("when the service instance have tags", func() {
   830  							BeforeEach(func() {
   831  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   832  									v2action.ServiceInstanceSummary{
   833  										ServiceInstance: v2action.ServiceInstance{
   834  											Name: "some-service-instance",
   835  											Type: constant.ServiceInstanceTypeUserProvidedService,
   836  											Tags: []string{"tag-1", "tag-2", "tag-3"},
   837  										},
   838  									},
   839  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   840  									nil,
   841  								)
   842  							})
   843  
   844  							It("displays the tags", func() {
   845  								Expect(executeErr).ToNot(HaveOccurred())
   846  
   847  								Expect(testUI.Out).To(Say("tags:\\s+tag-1, tag-2, tag-3"))
   848  							})
   849  						})
   850  					})
   851  				})
   852  			})
   853  		})
   854  	})
   855  })