github.com/arunkumar7540/cli@v6.45.0+incompatible/command/v6/service_command_test.go (about)

     1  package v6_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/v6"
    12  	"code.cloudfoundry.org/cli/command/v6/v6fakes"
    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       *v6fakes.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(v6fakes.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  	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  	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  		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  		When("getting the current user succeeds", func() {
    92  			BeforeEach(func() {
    93  				fakeConfig.CurrentUserReturns(configv3.User{Name: "some-user"}, nil)
    94  			})
    95  
    96  			When("the '--guid' flag is provided", func() {
    97  				BeforeEach(func() {
    98  					cmd.GUID = true
    99  				})
   100  
   101  				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  				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  				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  			When("the '--guid' flag is not provided", func() {
   184  				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  				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  				When("no errors are encountered getting the service instance summary", func() {
   242  					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.ManagedService,
   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  						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.Service.ServiceBrokerName = "broker-1"
   279  								returnedSummary.BoundApplications = []v2action.BoundApplication{
   280  									{
   281  										AppName:            "app-1",
   282  										ServiceBindingName: "binding-name-1",
   283  									},
   284  									{
   285  										AppName:            "app-2",
   286  										ServiceBindingName: "binding-name-2",
   287  										LastOperation: v2action.LastOperation{
   288  											Type:        "delete",
   289  											State:       constant.LastOperationInProgress,
   290  											Description: "10% complete",
   291  											UpdatedAt:   "some-updated-at-time",
   292  											CreatedAt:   "some-created-at-time",
   293  										},
   294  									},
   295  									{
   296  										AppName:            "app-3",
   297  										ServiceBindingName: "binding-name-3",
   298  										LastOperation: v2action.LastOperation{
   299  											Type:        "create",
   300  											State:       constant.LastOperationFailed,
   301  											Description: "Binding failed",
   302  											UpdatedAt:   "some-updated-at-time",
   303  											CreatedAt:   "some-created-at-time",
   304  										},
   305  									},
   306  									{
   307  										AppName:            "app-4",
   308  										ServiceBindingName: "binding-name-4",
   309  										LastOperation: v2action.LastOperation{
   310  											Type:        "create",
   311  											State:       constant.LastOperationSucceeded,
   312  											Description: "Binding created",
   313  											UpdatedAt:   "some-updated-at-time",
   314  											CreatedAt:   "some-created-at-time",
   315  										},
   316  									},
   317  								}
   318  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   319  									returnedSummary,
   320  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   321  									nil)
   322  
   323  							})
   324  
   325  							It("displays the service instance summary, all warnings and bound applications in the correct position", func() {
   326  								Expect(executeErr).ToNot(HaveOccurred())
   327  
   328  								Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   329  								Expect(testUI.Out).To(Say("\n\n"))
   330  								Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   331  								Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   332  								Expect(testUI.Out).To(Say(`service:\s+some-service`))
   333  								Expect(testUI.Out).To(Say(`tags:\s+tag-1, tag-2, tag-3`))
   334  								Expect(testUI.Out).To(Say(`plan:\s+some-plan`))
   335  								Expect(testUI.Out).To(Say(`description:\s+some-description`))
   336  								Expect(testUI.Out).To(Say(`documentation:\s+some-docs-url`))
   337  								Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   338  								Expect(testUI.Out).To(Say(`service broker:\s+broker-1`))
   339  								Expect(testUI.Out).To(Say("\n\n"))
   340  								Expect(testUI.Out).ToNot(Say("shared with spaces:"))
   341  								Expect(testUI.Out).ToNot(Say(`org\s+space\s+bindings`))
   342  								Expect(testUI.Out).ToNot(Say("This service is not currently shared."))
   343  
   344  								Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   345  								Expect(testUI.Out).To(Say("\n\n"))
   346  								Expect(testUI.Out).To(Say(`status:\s+some-type some-state`))
   347  								Expect(testUI.Out).To(Say(`message:\s+some-last-operation-description`))
   348  								Expect(testUI.Out).To(Say(`started:\s+some-created-at-time`))
   349  								Expect(testUI.Out).To(Say(`updated:\s+some-updated-at-time`))
   350  								Expect(testUI.Out).To(Say("\n\n"))
   351  
   352  								Expect(testUI.Out).To(Say("bound apps:"))
   353  								Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`))
   354  								Expect(testUI.Out).To(Say(`app-1\s+binding-name-1\s+`))
   355  								Expect(testUI.Out).To(Say(`app-2\s+binding-name-2\s+delete in progress\s+10\% complete`))
   356  								Expect(testUI.Out).To(Say(`app-3\s+binding-name-3\s+create failed\s+Binding failed`))
   357  								Expect(testUI.Out).To(Say(`app-4\s+binding-name-4\s+create succeeded\s+Binding created`))
   358  
   359  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   360  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   361  
   362  								Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   363  								serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   364  								Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   365  								Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   366  
   367  								Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   368  							})
   369  						})
   370  
   371  						When("the service instance is not shared and is shareable", func() {
   372  							BeforeEach(func() {
   373  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsNotShared
   374  								returnedSummary.ServiceInstanceSharingFeatureFlag = true
   375  								returnedSummary.Service.Extra.Shareable = true
   376  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   377  									returnedSummary,
   378  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   379  									nil)
   380  							})
   381  
   382  							It("displays the service instance summary and all warnings", func() {
   383  								Expect(executeErr).ToNot(HaveOccurred())
   384  
   385  								Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   386  								Expect(testUI.Out).To(Say("\n\n"))
   387  								Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   388  								Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   389  								Expect(testUI.Out).To(Say(`service:\s+some-service`))
   390  								Expect(testUI.Out).To(Say(`tags:\s+tag-1, tag-2, tag-3`))
   391  								Expect(testUI.Out).To(Say(`plan:\s+some-plan`))
   392  								Expect(testUI.Out).To(Say(`description:\s+some-description`))
   393  								Expect(testUI.Out).To(Say(`documentation:\s+some-docs-url`))
   394  								Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   395  								Expect(testUI.Out).To(Say("\n\n"))
   396  								Expect(testUI.Out).ToNot(Say("shared with spaces:"))
   397  								Expect(testUI.Out).ToNot(Say(`org\s+space\s+bindings`))
   398  								Expect(testUI.Out).To(Say("This service is not currently shared."))
   399  								Expect(testUI.Out).To(Say("\n\n"))
   400  								Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   401  								Expect(testUI.Out).To(Say("\n\n"))
   402  								Expect(testUI.Out).To(Say(`status:\s+some-type some-state`))
   403  								Expect(testUI.Out).To(Say(`message:\s+some-last-operation-description`))
   404  								Expect(testUI.Out).To(Say(`started:\s+some-created-at-time`))
   405  								Expect(testUI.Out).To(Say(`updated:\s+some-updated-at-time`))
   406  
   407  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   408  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   409  
   410  								Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   411  								serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   412  								Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   413  								Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   414  
   415  								Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   416  							})
   417  						})
   418  
   419  						When("the service instance is shared from another space", func() {
   420  							BeforeEach(func() {
   421  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsSharedFrom
   422  								returnedSummary.ServiceInstanceSharedFrom = v2action.ServiceInstanceSharedFrom{
   423  									SpaceGUID:        "some-space-guid",
   424  									SpaceName:        "some-space-name",
   425  									OrganizationName: "some-org-name",
   426  								}
   427  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   428  									returnedSummary,
   429  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   430  									nil)
   431  							})
   432  
   433  							It("displays the shared from info and does not display the shared to info", func() {
   434  								Expect(executeErr).ToNot(HaveOccurred())
   435  
   436  								Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   437  								Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   438  								Expect(testUI.Out).To(Say(`shared from org/space:\s+some-org-name / some-space-name`))
   439  								Expect(testUI.Out).To(Say(`service:\s+some-service`))
   440  								Expect(testUI.Out).ToNot(Say("shared with spaces:"))
   441  
   442  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   443  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   444  							})
   445  						})
   446  
   447  						When("the service instance is shared to other spaces", func() {
   448  							BeforeEach(func() {
   449  								returnedSummary.ServiceInstanceShareType = v2action.ServiceInstanceIsSharedTo
   450  								returnedSummary.ServiceInstanceSharedTos = []v2action.ServiceInstanceSharedTo{
   451  									{
   452  										SpaceGUID:        "another-space-guid",
   453  										SpaceName:        "another-space-name",
   454  										OrganizationName: "another-org-name",
   455  										BoundAppCount:    2,
   456  									},
   457  									{
   458  										SpaceGUID:        "yet-another-space-guid",
   459  										SpaceName:        "yet-another-space-name",
   460  										OrganizationName: "yet-another-org-name",
   461  										BoundAppCount:    3,
   462  									},
   463  								}
   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  							When("the service instance is still shareable", func() {
   471  								It("displays the shared to info and does not display the shared from info", func() {
   472  									Expect(executeErr).ToNot(HaveOccurred())
   473  
   474  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   475  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   476  									Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   477  									Expect(testUI.Out).To(Say("shared with spaces:"))
   478  									Expect(testUI.Out).To(Say(`org\s+space\s+bindings`))
   479  									Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`))
   480  									Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`))
   481  									Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   482  
   483  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   484  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   485  								})
   486  							})
   487  
   488  							When("the service instance is no longer shareable due to global settings only", func() {
   489  								BeforeEach(func() {
   490  									returnedSummary.ServiceInstanceSharingFeatureFlag = false
   491  									returnedSummary.Service.Extra.Shareable = true
   492  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   493  										returnedSummary,
   494  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   495  										nil)
   496  								})
   497  
   498  								It("displays the shared to info and message that the service instance feature flag is disabled", func() {
   499  									Expect(executeErr).ToNot(HaveOccurred())
   500  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   501  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   502  									Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   503  									Expect(testUI.Out).To(Say("\n\n"))
   504  									Expect(testUI.Out).To(Say(`The "service_instance_sharing" feature flag is disabled for this Cloud Foundry platform.`))
   505  									Expect(testUI.Out).To(Say("\n\n"))
   506  									Expect(testUI.Out).To(Say("shared with spaces:"))
   507  									Expect(testUI.Out).To(Say(`org\s+space\s+bindings`))
   508  									Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`))
   509  									Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`))
   510  									Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   511  
   512  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   513  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   514  								})
   515  							})
   516  
   517  							When("the service instance is no longer shareable due to service broker settings only", func() {
   518  								BeforeEach(func() {
   519  									returnedSummary.ServiceInstanceSharingFeatureFlag = true
   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 and message 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("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  							When("the service instance is no longer shareable due to  global settings AND service broker settings", func() {
   546  								BeforeEach(func() {
   547  									returnedSummary.ServiceInstanceSharingFeatureFlag = false
   548  									returnedSummary.Service.Extra.Shareable = false
   549  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   550  										returnedSummary,
   551  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   552  										nil)
   553  								})
   554  
   555  								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() {
   556  									Expect(executeErr).ToNot(HaveOccurred())
   557  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   558  									Expect(testUI.Out).ToNot(Say("shared from org/space:"))
   559  									Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   560  									Expect(testUI.Out).To(Say("\n\n"))
   561  									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.`))
   562  									Expect(testUI.Out).To(Say("\n\n"))
   563  									Expect(testUI.Out).To(Say("shared with spaces:"))
   564  									Expect(testUI.Out).To(Say(`org\s+space\s+bindings`))
   565  									Expect(testUI.Out).To(Say(`another-org-name\s+another-space-name\s+2`))
   566  									Expect(testUI.Out).To(Say(`yet-another-org-name\s+yet-another-space-name\s+3`))
   567  									Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   568  
   569  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   570  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   571  								})
   572  							})
   573  						})
   574  
   575  						When("the service instance has bound apps", func() {
   576  							When("the service bindings have binding names", func() {
   577  								BeforeEach(func() {
   578  									returnedSummary.BoundApplications = []v2action.BoundApplication{
   579  										{
   580  											AppName:            "app-1",
   581  											ServiceBindingName: "binding-name-1",
   582  										},
   583  										{
   584  											AppName:            "app-2",
   585  											ServiceBindingName: "binding-name-2",
   586  										},
   587  										{
   588  											AppName:            "app-3",
   589  											ServiceBindingName: "binding-name-3",
   590  										},
   591  									}
   592  
   593  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   594  										returnedSummary,
   595  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   596  										nil)
   597  								})
   598  
   599  								It("displays the bound apps table with service binding names", func() {
   600  									Expect(executeErr).ToNot(HaveOccurred())
   601  
   602  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   603  									Expect(testUI.Out).To(Say("\n\n"))
   604  									Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   605  									Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   606  									Expect(testUI.Out).To(Say("\n\n"))
   607  									Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   608  									Expect(testUI.Out).To(Say("\n\n"))
   609  									Expect(testUI.Out).To(Say("bound apps:"))
   610  									Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`))
   611  									Expect(testUI.Out).To(Say(`app-1\s+binding-name-1`))
   612  									Expect(testUI.Out).To(Say(`app-2\s+binding-name-2`))
   613  									Expect(testUI.Out).To(Say(`app-3\s+binding-name-3`))
   614  
   615  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   616  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   617  
   618  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   619  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   620  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   621  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   622  
   623  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   624  								})
   625  							})
   626  
   627  							When("the service bindings do not have binding names", func() {
   628  								BeforeEach(func() {
   629  									returnedSummary.BoundApplications = []v2action.BoundApplication{
   630  										{AppName: "app-1"},
   631  										{AppName: "app-2"},
   632  										{AppName: "app-3"},
   633  									}
   634  
   635  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   636  										returnedSummary,
   637  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   638  										nil)
   639  								})
   640  
   641  								It("displays the bound apps table with NO service binding names", func() {
   642  									Expect(executeErr).ToNot(HaveOccurred())
   643  
   644  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   645  									Expect(testUI.Out).To(Say("\n\n"))
   646  									Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   647  									Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   648  									Expect(testUI.Out).To(Say("\n\n"))
   649  									Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   650  									Expect(testUI.Out).To(Say("\n\n"))
   651  									Expect(testUI.Out).To(Say("bound apps:"))
   652  									Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`))
   653  									Expect(testUI.Out).To(Say("app-1"))
   654  									Expect(testUI.Out).To(Say("app-2"))
   655  									Expect(testUI.Out).To(Say("app-3"))
   656  
   657  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   658  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   659  
   660  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   661  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   662  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   663  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   664  
   665  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   666  								})
   667  							})
   668  						})
   669  
   670  						When("the service instance does not have bound apps", func() {
   671  							It("displays a message indicating that there are no bound apps", func() {
   672  								Expect(executeErr).ToNot(HaveOccurred())
   673  
   674  								Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   675  								Expect(testUI.Out).To(Say("\n\n"))
   676  								Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   677  								Expect(testUI.Out).To(Say(`dashboard:\s+some-dashboard`))
   678  								Expect(testUI.Out).To(Say("\n\n"))
   679  								Expect(testUI.Out).To(Say(`Showing status of last operation from service some-service-instance\.\.\.`))
   680  								Expect(testUI.Out).To(Say("\n\n"))
   681  								Expect(testUI.Out).To(Say("There are no bound apps for this service."))
   682  
   683  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   684  								Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   685  
   686  								Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   687  								serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   688  								Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   689  								Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   690  
   691  								Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   692  							})
   693  
   694  						})
   695  					})
   696  
   697  					When("the service instance is a user provided service instance", func() {
   698  						BeforeEach(func() {
   699  							fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   700  								v2action.ServiceInstanceSummary{
   701  									ServiceInstance: v2action.ServiceInstance{
   702  										Name: "some-service-instance",
   703  										Type: constant.UserProvidedService,
   704  									},
   705  								},
   706  								v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   707  								nil,
   708  							)
   709  						})
   710  
   711  						It("displays a smaller service instance summary than for managed service instances", func() {
   712  							Expect(executeErr).ToNot(HaveOccurred())
   713  
   714  							Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   715  							Expect(testUI.Out).To(Say(""))
   716  							Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   717  							Expect(testUI.Out).ToNot(Say("shared from"))
   718  							Expect(testUI.Out).To(Say(`service:\s+user-provided`))
   719  							Expect(testUI.Out).To(Say("tags:"))
   720  							Expect(testUI.Out).ToNot(Say("plan:"))
   721  							Expect(testUI.Out).ToNot(Say("description:"))
   722  							Expect(testUI.Out).ToNot(Say("documentation:"))
   723  							Expect(testUI.Out).ToNot(Say("dashboard:"))
   724  							Expect(testUI.Out).ToNot(Say("shared with spaces"))
   725  							Expect(testUI.Out).ToNot(Say("last operation"))
   726  							Expect(testUI.Out).ToNot(Say("status:"))
   727  							Expect(testUI.Out).ToNot(Say("message:"))
   728  							Expect(testUI.Out).ToNot(Say("started:"))
   729  							Expect(testUI.Out).ToNot(Say("updated:"))
   730  
   731  							Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   732  							Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   733  
   734  							Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   735  							serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   736  							Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   737  							Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   738  
   739  							Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   740  						})
   741  
   742  						When("the service instance has bound apps", func() {
   743  							When("the service bindings have binding names", func() {
   744  								BeforeEach(func() {
   745  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   746  										v2action.ServiceInstanceSummary{
   747  											ServiceInstance: v2action.ServiceInstance{
   748  												Name: "some-service-instance",
   749  												Type: constant.UserProvidedService,
   750  											},
   751  											BoundApplications: []v2action.BoundApplication{
   752  												{
   753  													AppName:            "app-1",
   754  													ServiceBindingName: "binding-name-1",
   755  												},
   756  												{
   757  													AppName:            "app-2",
   758  													ServiceBindingName: "binding-name-2",
   759  												},
   760  												{
   761  													AppName:            "app-3",
   762  													ServiceBindingName: "binding-name-3",
   763  												},
   764  											},
   765  										},
   766  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   767  										nil,
   768  									)
   769  								})
   770  
   771  								It("displays the bound apps table with service binding names", func() {
   772  									Expect(executeErr).ToNot(HaveOccurred())
   773  
   774  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   775  									Expect(testUI.Out).To(Say("\n\n"))
   776  									Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   777  									Expect(testUI.Out).To(Say(`service:\s+user-provided`))
   778  									Expect(testUI.Out).To(Say("\n\n"))
   779  									Expect(testUI.Out).To(Say("bound apps:"))
   780  									Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`))
   781  									Expect(testUI.Out).To(Say(`app-1\s+binding-name-1`))
   782  									Expect(testUI.Out).To(Say(`app-2\s+binding-name-2`))
   783  									Expect(testUI.Out).To(Say(`app-3\s+binding-name-3`))
   784  
   785  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   786  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   787  
   788  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   789  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   790  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   791  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   792  
   793  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   794  								})
   795  							})
   796  
   797  							When("the service bindings do not have binding names", func() {
   798  								BeforeEach(func() {
   799  									fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   800  										v2action.ServiceInstanceSummary{
   801  											ServiceInstance: v2action.ServiceInstance{
   802  												Name: "some-service-instance",
   803  												Type: constant.UserProvidedService,
   804  											},
   805  											BoundApplications: []v2action.BoundApplication{
   806  												{AppName: "app-1"},
   807  												{AppName: "app-2"},
   808  												{AppName: "app-3"},
   809  											},
   810  										},
   811  										v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   812  										nil,
   813  									)
   814  								})
   815  
   816  								It("displays the bound apps table with NO service binding names", func() {
   817  									Expect(executeErr).ToNot(HaveOccurred())
   818  
   819  									Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   820  									Expect(testUI.Out).To(Say("\n\n"))
   821  									Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   822  									Expect(testUI.Out).To(Say(`service:\s+user-provided`))
   823  									Expect(testUI.Out).To(Say("\n\n"))
   824  									Expect(testUI.Out).To(Say("bound apps:"))
   825  									Expect(testUI.Out).To(Say(`name\s+binding name\s+status\s+message`))
   826  									Expect(testUI.Out).To(Say("app-1"))
   827  									Expect(testUI.Out).To(Say("app-2"))
   828  									Expect(testUI.Out).To(Say("app-3"))
   829  
   830  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-1"))
   831  									Expect(testUI.Err).To(Say("get-service-instance-summary-warning-2"))
   832  
   833  									Expect(fakeActor.GetServiceInstanceSummaryByNameAndSpaceCallCount()).To(Equal(1))
   834  									serviceInstanceNameArg, spaceGUIDArg := fakeActor.GetServiceInstanceSummaryByNameAndSpaceArgsForCall(0)
   835  									Expect(serviceInstanceNameArg).To(Equal("some-service-instance"))
   836  									Expect(spaceGUIDArg).To(Equal("some-space-guid"))
   837  
   838  									Expect(fakeActor.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(0))
   839  								})
   840  
   841  							})
   842  						})
   843  
   844  						When("the service instance does not have bound apps", func() {
   845  							It("displays a message indicating that there are no bound apps", func() {
   846  								Expect(executeErr).ToNot(HaveOccurred())
   847  
   848  								Expect(testUI.Out).To(Say(`Showing info of service some-service-instance in org some-org / space some-space as some-user\.\.\.`))
   849  								Expect(testUI.Out).To(Say("\n\n"))
   850  								Expect(testUI.Out).To(Say(`name:\s+some-service-instance`))
   851  								Expect(testUI.Out).To(Say(`service:\s+user-provided`))
   852  								Expect(testUI.Out).To(Say("\n\n"))
   853  								Expect(testUI.Out).To(Say("There are no bound apps for this service."))
   854  							})
   855  						})
   856  
   857  						When("the service instance have tags", func() {
   858  							BeforeEach(func() {
   859  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   860  									v2action.ServiceInstanceSummary{
   861  										ServiceInstance: v2action.ServiceInstance{
   862  											Name: "some-service-instance",
   863  											Type: constant.UserProvidedService,
   864  											Tags: []string{"tag-1", "tag-2", "tag-3"},
   865  										},
   866  									},
   867  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   868  									nil,
   869  								)
   870  							})
   871  
   872  							It("displays the tags", func() {
   873  								Expect(executeErr).ToNot(HaveOccurred())
   874  
   875  								Expect(testUI.Out).To(Say(`tags:\s+tag-1, tag-2, tag-3`))
   876  							})
   877  						})
   878  
   879  						When("the service instance has route service url", func() {
   880  							BeforeEach(func() {
   881  								fakeActor.GetServiceInstanceSummaryByNameAndSpaceReturns(
   882  									v2action.ServiceInstanceSummary{
   883  										ServiceInstance: v2action.ServiceInstance{
   884  											Name:            "some-service-instance",
   885  											Type:            constant.UserProvidedService,
   886  											RouteServiceURL: "some-route-service-url",
   887  										},
   888  									},
   889  									v2action.Warnings{"get-service-instance-summary-warning-1", "get-service-instance-summary-warning-2"},
   890  									nil,
   891  								)
   892  							})
   893  
   894  							It("displays the route service url", func() {
   895  								Expect(executeErr).ToNot(HaveOccurred())
   896  
   897  								Expect(testUI.Out).To(Say(`route service url:\s+some-route-service-url`))
   898  							})
   899  						})
   900  					})
   901  				})
   902  			})
   903  		})
   904  	})
   905  })