From 65b106ac3923a68426fcc8c8242607dbf69c5597 Mon Sep 17 00:00:00 2001 From: George Blue Date: Wed, 10 Feb 2021 16:28:53 +0000 Subject: [PATCH] v8(services): services cmd should use V3 API Removes the V2 API implementation and replaces it with the V3 implementation [#176843213](https://www.pivotaltracker.com/story/show/176843213) --- command/common/command_list_v7.go | 3 +- command/v6/services_command.go | 159 ------------- command/v6/services_command_test.go | 216 ------------------ .../v6fakes/fake_service_instances_actor.go | 185 --------------- .../v7/isolated/services_command_test.go | 205 +---------------- 5 files changed, 3 insertions(+), 765 deletions(-) delete mode 100644 command/v6/services_command.go delete mode 100644 command/v6/services_command_test.go delete mode 100644 command/v6/v6fakes/fake_service_instances_actor.go diff --git a/command/common/command_list_v7.go b/command/common/command_list_v7.go index 7267371f009..91399e8eab9 100644 --- a/command/common/command_list_v7.go +++ b/command/common/command_list_v7.go @@ -143,8 +143,7 @@ type commandList struct { ServiceBrokers v7.ServiceBrokersCommand `command:"service-brokers" description:"List service brokers"` ServiceKey v7.ServiceKeyCommand `command:"service-key" description:"Show service key info"` ServiceKeys v7.ServiceKeysCommand `command:"service-keys" alias:"sk" description:"List keys for a service instance"` - Services v6.ServicesCommand `command:"services" alias:"s" description:"List all service instances in the target space"` - ServicesV3 v7.ServicesCommand `command:"v3-services" alias:"s" description:"List all service instances in the target space"` + Services v7.ServicesCommand `command:"services" alias:"s" description:"List all service instances in the target space"` SetDroplet v7.SetDropletCommand `command:"set-droplet" description:"Set the droplet used to run an app"` SetEnv v7.SetEnvCommand `command:"set-env" alias:"se" description:"Set an env variable for an app"` SetHealthCheck v7.SetHealthCheckCommand `command:"set-health-check" description:"Change type of health check performed on an app's process"` diff --git a/command/v6/services_command.go b/command/v6/services_command.go deleted file mode 100644 index be5582f459e..00000000000 --- a/command/v6/services_command.go +++ /dev/null @@ -1,159 +0,0 @@ -package v6 - -import ( - "fmt" - "sort" - "strings" - - "code.cloudfoundry.org/cli/actor/sharedaction" - "code.cloudfoundry.org/cli/actor/v2action" - "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" - "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" - "code.cloudfoundry.org/cli/command" - "code.cloudfoundry.org/cli/command/v6/shared" - "code.cloudfoundry.org/cli/util/sorting" -) - -//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ServiceInstancesActor - -type ServiceInstancesActor interface { - CloudControllerAPIVersion() string - GetServiceInstancesSummaryBySpace(spaceGUID string) ([]v2action.ServiceInstanceSummary, v2action.Warnings, error) -} - -type ServicesCommand struct { - usage interface{} `usage:"CF_NAME services"` - relatedCommands interface{} `related_commands:"create-service, marketplace"` - - UI command.UI - Config command.Config - SharedActor command.SharedActor - Actor ServiceInstancesActor -} - -func (cmd *ServicesCommand) Setup(config command.Config, ui command.UI) error { - cmd.Config = config - cmd.UI = ui - cmd.SharedActor = sharedaction.NewActor(config) - ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui) - if err != nil { - return err - } - cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) - - return nil -} - -func (cmd ServicesCommand) Execute(args []string) error { - err := cmd.SharedActor.CheckTarget(true, true) - if err != nil { - return err - } - - user, err := cmd.Config.CurrentUser() - if err != nil { - return err - } - - cmd.UI.DisplayTextWithFlavor("Getting services in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", - map[string]interface{}{ - "OrgName": cmd.Config.TargetedOrganization().Name, - "SpaceName": cmd.Config.TargetedSpace().Name, - "CurrentUser": user.Name, - }) - cmd.UI.DisplayNewline() - - instanceSummaries, warnings, err := cmd.Actor.GetServiceInstancesSummaryBySpace(cmd.Config.TargetedSpace().GUID) - cmd.UI.DisplayWarnings(warnings) - if err != nil { - return err - } - - if len(instanceSummaries) == 0 { - cmd.UI.DisplayText("No services found") - return nil - } - - sortServiceInstances(instanceSummaries) - - table := [][]string{{ - cmd.UI.TranslateText("name"), - cmd.UI.TranslateText("service"), - cmd.UI.TranslateText("plan"), - cmd.UI.TranslateText("bound apps"), - cmd.UI.TranslateText("last operation"), - cmd.UI.TranslateText("broker"), - cmd.UI.TranslateText("upgrade available"), - }} - - var boundAppNames []string - - for _, summary := range instanceSummaries { - serviceLabel := summary.Service.Label - if summary.ServiceInstance.Type == constant.UserProvidedService { - serviceLabel = "user-provided" - } - - boundAppNames = []string{} - for _, boundApplication := range summary.BoundApplications { - boundAppNames = append(boundAppNames, boundApplication.AppName) - } - - table = append( - table, - []string{ - summary.Name, - serviceLabel, - summary.ServicePlan.Name, - strings.Join(boundAppNames, ", "), - fmt.Sprintf("%s %s", summary.LastOperation.Type, summary.LastOperation.State), - summary.Service.ServiceBrokerName, - upgradeAvailableSummary(summary), - }, - ) - } - cmd.UI.DisplayTableWithHeader("", table, 3) - - isOutdated, err := command.CheckVersionOutdated(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionMaintenanceInfoInSummaryV2) - if err != nil { - return err - } - - if isOutdated { - cmd.UI.DisplayNewline() - cmd.UI.DisplayText("TIP: Please upgrade to CC API v{{.version}} or higher for individual service upgrades", - map[string]interface{}{ - "version": ccversion.MinVersionMaintenanceInfoInSummaryV2, - }) - } - - return nil -} - -func sortServiceInstances(instanceSummaries []v2action.ServiceInstanceSummary) { - sort.Slice(instanceSummaries, func(i, j int) bool { - return sorting.LessIgnoreCase(instanceSummaries[i].Name, instanceSummaries[j].Name) - }) - - for _, instance := range instanceSummaries { - sortBoundApps(instance) - } -} - -func sortBoundApps(serviceInstance v2action.ServiceInstanceSummary) { - sort.Slice( - serviceInstance.BoundApplications, - func(i, j int) bool { - return sorting.LessIgnoreCase(serviceInstance.BoundApplications[i].AppName, serviceInstance.BoundApplications[j].AppName) - }) -} - -func upgradeAvailableSummary(s v2action.ServiceInstanceSummary) string { - if s.UpgradeSupported() { - if s.UpgradeAvailable() { - return "yes" - } - return "no" - } - return "" -} diff --git a/command/v6/services_command_test.go b/command/v6/services_command_test.go deleted file mode 100644 index eb7eb42acac..00000000000 --- a/command/v6/services_command_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package v6_test - -import ( - "errors" - - "code.cloudfoundry.org/cli/actor/actionerror" - "code.cloudfoundry.org/cli/actor/v2action" - "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" - "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" - "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" - "code.cloudfoundry.org/cli/command/commandfakes" - . "code.cloudfoundry.org/cli/command/v6" - "code.cloudfoundry.org/cli/command/v6/v6fakes" - "code.cloudfoundry.org/cli/util/configv3" - "code.cloudfoundry.org/cli/util/ui" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gbytes" -) - -var _ = Describe("services Command", func() { - var ( - cmd ServicesCommand - testUI *ui.UI - fakeConfig *commandfakes.FakeConfig - fakeSharedActor *commandfakes.FakeSharedActor - fakeActor *v6fakes.FakeServiceInstancesActor - binaryName string - executeErr error - ) - - BeforeEach(func() { - testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) - fakeConfig = new(commandfakes.FakeConfig) - fakeSharedActor = new(commandfakes.FakeSharedActor) - fakeActor = new(v6fakes.FakeServiceInstancesActor) - - cmd = ServicesCommand{ - UI: testUI, - Config: fakeConfig, - SharedActor: fakeSharedActor, - Actor: fakeActor, - } - - binaryName = "faceman" - fakeConfig.BinaryNameReturns(binaryName) - - fakeActor.CloudControllerAPIVersionReturns(ccversion.MinVersionMaintenanceInfoInSummaryV2) - }) - - JustBeforeEach(func() { - executeErr = cmd.Execute(nil) - }) - - When("an error is encountered checking if the environment is setup correctly", func() { - BeforeEach(func() { - fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) - }) - - It("returns an error", func() { - Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) - Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) - checkTargetedOrgArg, checkTargetedSpaceArg := fakeSharedActor.CheckTargetArgsForCall(0) - Expect(checkTargetedOrgArg).To(BeTrue()) - Expect(checkTargetedSpaceArg).To(BeTrue()) - }) - }) - - When("the user is logged in and an org and space are targeted", func() { - BeforeEach(func() { - fakeConfig.TargetedOrganizationReturns(configv3.Organization{ - Name: "some-org", - }) - fakeConfig.TargetedSpaceReturns(configv3.Space{ - GUID: "some-space-guid", - Name: "some-space", - }) - }) - - When("getting the current user fails", func() { - var expectedErr error - - BeforeEach(func() { - expectedErr = errors.New("some-error that happened") - fakeConfig.CurrentUserReturns(configv3.User{}, expectedErr) - }) - - It("returns the error", func() { - Expect(executeErr).To(MatchError(expectedErr)) - Expect(fakeConfig.CurrentUserCallCount()).To(Equal(1)) - }) - }) - - When("getting the current user succeeds", func() { - var ( - fakeUser configv3.User - ) - - BeforeEach(func() { - fakeUser = configv3.User{Name: "some-user"} - fakeConfig.CurrentUserReturns(fakeUser, nil) - fakeConfig.TargetedSpaceReturns(configv3.Space{ - GUID: "some-space-guid", - Name: "some-space", - }) - fakeConfig.TargetedOrganizationReturns(configv3.Organization{ - Name: "some-org", - }) - }) - - When("there are no services", func() { - BeforeEach(func() { - fakeActor.GetServiceInstancesSummaryBySpaceReturns( - nil, - v2action.Warnings{"get-summary-warnings"}, - nil, - ) - }) - - It("displays that there are no services", func() { - Expect(executeErr).ToNot(HaveOccurred()) - Expect(testUI.Out).To(Say("Getting services in org %s / space %s as %s...", "some-org", - "some-space", fakeUser.Name)) - - out := testUI.Out.(*Buffer).Contents() - Expect(out).To(MatchRegexp("No services found")) - Expect(out).ToNot(MatchRegexp(`name\s+service\s+plan\s+bound apps\s+last operation`)) - Expect(testUI.Err).To(Say("get-summary-warnings")) - }) - }) - - When("there are services", func() { - BeforeEach(func() { - fakeActor.GetServiceInstancesSummaryBySpaceReturns( - []v2action.ServiceInstanceSummary{ - { - ServiceInstance: v2action.ServiceInstance{ - Name: "instance-1", - LastOperation: ccv2.LastOperation{ - Type: "some-type", - State: "some-state", - }, - Type: constant.ManagedService, - MaintenanceInfo: ccv2.MaintenanceInfo{ - Version: "2.0.0", - }, - }, - ServicePlan: v2action.ServicePlan{ - Name: "some-plan", - MaintenanceInfo: ccv2.MaintenanceInfo{ - Version: "3.0.0", - }, - }, - Service: v2action.Service{ - Label: "some-service-1", - ServiceBrokerName: "broker-1", - }, - BoundApplications: []v2action.BoundApplication{ - {AppName: "app-2"}, - {AppName: "app-1"}, - }, - }, - { - ServiceInstance: v2action.ServiceInstance{ - Name: "instance-3", - Type: constant.UserProvidedService, - }, - }, - { - ServiceInstance: v2action.ServiceInstance{ - Name: "instance-2", - Type: constant.ManagedService, - MaintenanceInfo: ccv2.MaintenanceInfo{ - Version: "2.0.0", - }, - }, - ServicePlan: v2action.ServicePlan{ - Name: "some-plan", - MaintenanceInfo: ccv2.MaintenanceInfo{ - Version: "2.0.0", - }, - }, - Service: v2action.Service{ - Label: "some-service-2", - ServiceBrokerName: "broker-2", - }, - }, - }, - v2action.Warnings{"get-summary-warnings"}, - nil, - ) - }) - - It("displays all the services and apps in alphanumeric sorted order together with the org & space & warnings & upgrades", func() { - Expect(executeErr).ToNot(HaveOccurred()) - Expect(testUI.Out).To(Say("Getting services in org %s / space %s as %s...", "some-org", "some-space", fakeUser.Name)) - Expect(testUI.Out).To(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker\s+upgrade available`)) - Expect(testUI.Out).To(Say(`instance-1\s+some-service-1\s+some-plan\s+app-1, app-2\s+some-type some-state\s+broker-1\s+yes`)) - Expect(testUI.Out).To(Say(`instance-2\s+some-service-2\s+some-plan\s+broker-2\s+no`)) - Expect(testUI.Out).To(Say(`instance-3\s+user-provided\s+$`)) - Expect(testUI.Err).To(Say("get-summary-warnings")) - }) - - When("CC version is too old to show upgrade information", func() { - BeforeEach(func() { - fakeActor.CloudControllerAPIVersionReturns(ccversion.MinSupportedV2ClientVersion) - }) - - It("shows a tip with a minimum service upgrade version required", func() { - Expect(testUI.Out).To(Say("TIP: Please upgrade to CC API v%s or higher for individual service upgrades", ccversion.MinVersionMaintenanceInfoInSummaryV2)) - }) - }) - }) - }) - }) -}) diff --git a/command/v6/v6fakes/fake_service_instances_actor.go b/command/v6/v6fakes/fake_service_instances_actor.go deleted file mode 100644 index b14f26e6bc6..00000000000 --- a/command/v6/v6fakes/fake_service_instances_actor.go +++ /dev/null @@ -1,185 +0,0 @@ -// Code generated by counterfeiter. DO NOT EDIT. -package v6fakes - -import ( - "sync" - - "code.cloudfoundry.org/cli/actor/v2action" - v6 "code.cloudfoundry.org/cli/command/v6" -) - -type FakeServiceInstancesActor struct { - CloudControllerAPIVersionStub func() string - cloudControllerAPIVersionMutex sync.RWMutex - cloudControllerAPIVersionArgsForCall []struct { - } - cloudControllerAPIVersionReturns struct { - result1 string - } - cloudControllerAPIVersionReturnsOnCall map[int]struct { - result1 string - } - GetServiceInstancesSummaryBySpaceStub func(string) ([]v2action.ServiceInstanceSummary, v2action.Warnings, error) - getServiceInstancesSummaryBySpaceMutex sync.RWMutex - getServiceInstancesSummaryBySpaceArgsForCall []struct { - arg1 string - } - getServiceInstancesSummaryBySpaceReturns struct { - result1 []v2action.ServiceInstanceSummary - result2 v2action.Warnings - result3 error - } - getServiceInstancesSummaryBySpaceReturnsOnCall map[int]struct { - result1 []v2action.ServiceInstanceSummary - result2 v2action.Warnings - result3 error - } - invocations map[string][][]interface{} - invocationsMutex sync.RWMutex -} - -func (fake *FakeServiceInstancesActor) CloudControllerAPIVersion() string { - fake.cloudControllerAPIVersionMutex.Lock() - ret, specificReturn := fake.cloudControllerAPIVersionReturnsOnCall[len(fake.cloudControllerAPIVersionArgsForCall)] - fake.cloudControllerAPIVersionArgsForCall = append(fake.cloudControllerAPIVersionArgsForCall, struct { - }{}) - fake.recordInvocation("CloudControllerAPIVersion", []interface{}{}) - fake.cloudControllerAPIVersionMutex.Unlock() - if fake.CloudControllerAPIVersionStub != nil { - return fake.CloudControllerAPIVersionStub() - } - if specificReturn { - return ret.result1 - } - fakeReturns := fake.cloudControllerAPIVersionReturns - return fakeReturns.result1 -} - -func (fake *FakeServiceInstancesActor) CloudControllerAPIVersionCallCount() int { - fake.cloudControllerAPIVersionMutex.RLock() - defer fake.cloudControllerAPIVersionMutex.RUnlock() - return len(fake.cloudControllerAPIVersionArgsForCall) -} - -func (fake *FakeServiceInstancesActor) CloudControllerAPIVersionCalls(stub func() string) { - fake.cloudControllerAPIVersionMutex.Lock() - defer fake.cloudControllerAPIVersionMutex.Unlock() - fake.CloudControllerAPIVersionStub = stub -} - -func (fake *FakeServiceInstancesActor) CloudControllerAPIVersionReturns(result1 string) { - fake.cloudControllerAPIVersionMutex.Lock() - defer fake.cloudControllerAPIVersionMutex.Unlock() - fake.CloudControllerAPIVersionStub = nil - fake.cloudControllerAPIVersionReturns = struct { - result1 string - }{result1} -} - -func (fake *FakeServiceInstancesActor) CloudControllerAPIVersionReturnsOnCall(i int, result1 string) { - fake.cloudControllerAPIVersionMutex.Lock() - defer fake.cloudControllerAPIVersionMutex.Unlock() - fake.CloudControllerAPIVersionStub = nil - if fake.cloudControllerAPIVersionReturnsOnCall == nil { - fake.cloudControllerAPIVersionReturnsOnCall = make(map[int]struct { - result1 string - }) - } - fake.cloudControllerAPIVersionReturnsOnCall[i] = struct { - result1 string - }{result1} -} - -func (fake *FakeServiceInstancesActor) GetServiceInstancesSummaryBySpace(arg1 string) ([]v2action.ServiceInstanceSummary, v2action.Warnings, error) { - fake.getServiceInstancesSummaryBySpaceMutex.Lock() - ret, specificReturn := fake.getServiceInstancesSummaryBySpaceReturnsOnCall[len(fake.getServiceInstancesSummaryBySpaceArgsForCall)] - fake.getServiceInstancesSummaryBySpaceArgsForCall = append(fake.getServiceInstancesSummaryBySpaceArgsForCall, struct { - arg1 string - }{arg1}) - fake.recordInvocation("GetServiceInstancesSummaryBySpace", []interface{}{arg1}) - fake.getServiceInstancesSummaryBySpaceMutex.Unlock() - if fake.GetServiceInstancesSummaryBySpaceStub != nil { - return fake.GetServiceInstancesSummaryBySpaceStub(arg1) - } - if specificReturn { - return ret.result1, ret.result2, ret.result3 - } - fakeReturns := fake.getServiceInstancesSummaryBySpaceReturns - return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3 -} - -func (fake *FakeServiceInstancesActor) GetServiceInstancesSummaryBySpaceCallCount() int { - fake.getServiceInstancesSummaryBySpaceMutex.RLock() - defer fake.getServiceInstancesSummaryBySpaceMutex.RUnlock() - return len(fake.getServiceInstancesSummaryBySpaceArgsForCall) -} - -func (fake *FakeServiceInstancesActor) GetServiceInstancesSummaryBySpaceCalls(stub func(string) ([]v2action.ServiceInstanceSummary, v2action.Warnings, error)) { - fake.getServiceInstancesSummaryBySpaceMutex.Lock() - defer fake.getServiceInstancesSummaryBySpaceMutex.Unlock() - fake.GetServiceInstancesSummaryBySpaceStub = stub -} - -func (fake *FakeServiceInstancesActor) GetServiceInstancesSummaryBySpaceArgsForCall(i int) string { - fake.getServiceInstancesSummaryBySpaceMutex.RLock() - defer fake.getServiceInstancesSummaryBySpaceMutex.RUnlock() - argsForCall := fake.getServiceInstancesSummaryBySpaceArgsForCall[i] - return argsForCall.arg1 -} - -func (fake *FakeServiceInstancesActor) GetServiceInstancesSummaryBySpaceReturns(result1 []v2action.ServiceInstanceSummary, result2 v2action.Warnings, result3 error) { - fake.getServiceInstancesSummaryBySpaceMutex.Lock() - defer fake.getServiceInstancesSummaryBySpaceMutex.Unlock() - fake.GetServiceInstancesSummaryBySpaceStub = nil - fake.getServiceInstancesSummaryBySpaceReturns = struct { - result1 []v2action.ServiceInstanceSummary - result2 v2action.Warnings - result3 error - }{result1, result2, result3} -} - -func (fake *FakeServiceInstancesActor) GetServiceInstancesSummaryBySpaceReturnsOnCall(i int, result1 []v2action.ServiceInstanceSummary, result2 v2action.Warnings, result3 error) { - fake.getServiceInstancesSummaryBySpaceMutex.Lock() - defer fake.getServiceInstancesSummaryBySpaceMutex.Unlock() - fake.GetServiceInstancesSummaryBySpaceStub = nil - if fake.getServiceInstancesSummaryBySpaceReturnsOnCall == nil { - fake.getServiceInstancesSummaryBySpaceReturnsOnCall = make(map[int]struct { - result1 []v2action.ServiceInstanceSummary - result2 v2action.Warnings - result3 error - }) - } - fake.getServiceInstancesSummaryBySpaceReturnsOnCall[i] = struct { - result1 []v2action.ServiceInstanceSummary - result2 v2action.Warnings - result3 error - }{result1, result2, result3} -} - -func (fake *FakeServiceInstancesActor) Invocations() map[string][][]interface{} { - fake.invocationsMutex.RLock() - defer fake.invocationsMutex.RUnlock() - fake.cloudControllerAPIVersionMutex.RLock() - defer fake.cloudControllerAPIVersionMutex.RUnlock() - fake.getServiceInstancesSummaryBySpaceMutex.RLock() - defer fake.getServiceInstancesSummaryBySpaceMutex.RUnlock() - copiedInvocations := map[string][][]interface{}{} - for key, value := range fake.invocations { - copiedInvocations[key] = value - } - return copiedInvocations -} - -func (fake *FakeServiceInstancesActor) recordInvocation(key string, args []interface{}) { - fake.invocationsMutex.Lock() - defer fake.invocationsMutex.Unlock() - if fake.invocations == nil { - fake.invocations = map[string][][]interface{}{} - } - if fake.invocations[key] == nil { - fake.invocations[key] = [][]interface{}{} - } - fake.invocations[key] = append(fake.invocations[key], args) -} - -var _ v6.ServiceInstancesActor = new(FakeServiceInstancesActor) diff --git a/integration/v7/isolated/services_command_test.go b/integration/v7/isolated/services_command_test.go index 76da2d85395..54ad1ff6357 100644 --- a/integration/v7/isolated/services_command_test.go +++ b/integration/v7/isolated/services_command_test.go @@ -1,7 +1,6 @@ package isolated import ( - "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" "code.cloudfoundry.org/cli/integration/assets/hydrabroker/config" "code.cloudfoundry.org/cli/integration/helpers" "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" @@ -12,207 +11,7 @@ import ( ) var _ = Describe("services command", func() { - var userName string - - BeforeEach(func() { - userName, _ = helpers.GetCredentials() - }) - - Describe("help", func() { - When("--help flag is set", func() { - It("Displays command usage to output", func() { - session := helpers.CF("services", "--help") - - Eventually(session).Should(Say("NAME:")) - Eventually(session).Should(Say("services - List all service instances in the target space")) - Eventually(session).Should(Say("USAGE:")) - Eventually(session).Should(Say("cf services")) - Eventually(session).Should(Say("ALIAS:")) - Eventually(session).Should(Say("s")) - Eventually(session).Should(Say("SEE ALSO:")) - Eventually(session).Should(Say("create-service, marketplace")) - - Eventually(session).Should(Exit(0)) - }) - }) - }) - - Context("has no services", func() { - BeforeEach(func() { - helpers.LoginCF() - helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) - }) - - It("tells the user 'no services found'", func() { - session := helpers.CF("services") - - Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", ReadOnlyOrg, ReadOnlySpace, userName)) - Eventually(session).Should(Say("No services found")) - Eventually(session).Should(Exit(0)) - }) - }) - - Context("has services and applications", func() { - var ( - orgName string - spaceName string - - broker *servicebrokerstub.ServiceBrokerStub - - managedService1 string - managedService2 string - userProvidedService1 string - userProvidedService2 string - appName1 string - appName2 string - ) - - BeforeEach(func() { - orgName = helpers.NewOrgName() - spaceName = helpers.NewSpaceName() - helpers.SetupCF(orgName, spaceName) - - userProvidedService1 = helpers.PrefixedRandomName("UPS1") - userProvidedService2 = helpers.PrefixedRandomName("UPS2") - - Eventually(helpers.CF("cups", userProvidedService1, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0)) - Eventually(helpers.CF("cups", userProvidedService2, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0)) - - broker = servicebrokerstub.EnableServiceAccess() - - managedService1 = helpers.PrefixedRandomName("MANAGED1") - managedService2 = helpers.PrefixedRandomName("MANAGED2") - Eventually(helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedService1)).Should(Exit(0)) - Eventually(helpers.CF("create-service", broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), managedService2)).Should(Exit(0)) - - appName1 = helpers.PrefixedRandomName("APP1") - appName2 = helpers.PrefixedRandomName("APP2") - helpers.WithHelloWorldApp(func(appDir string) { - Eventually(helpers.CF("push", appName1, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) - Eventually(helpers.CF("push", appName2, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0)) - }) - Eventually(helpers.CF("bind-service", appName1, managedService1)).Should(Exit(0)) - Eventually(helpers.CF("bind-service", appName1, managedService2)).Should(Exit(0)) - Eventually(helpers.CF("bind-service", appName1, userProvidedService1)).Should(Exit(0)) - Eventually(helpers.CF("bind-service", appName1, userProvidedService2)).Should(Exit(0)) - Eventually(helpers.CF("bind-service", appName2, managedService2)).Should(Exit(0)) - Eventually(helpers.CF("bind-service", appName2, userProvidedService2)).Should(Exit(0)) - }) - - AfterEach(func() { - Eventually(helpers.CF("unbind-service", appName1, managedService1)).Should(Exit(0)) - Eventually(helpers.CF("unbind-service", appName1, managedService2)).Should(Exit(0)) - Eventually(helpers.CF("unbind-service", appName1, userProvidedService1)).Should(Exit(0)) - Eventually(helpers.CF("unbind-service", appName1, userProvidedService2)).Should(Exit(0)) - Eventually(helpers.CF("unbind-service", appName2, managedService2)).Should(Exit(0)) - Eventually(helpers.CF("unbind-service", appName2, userProvidedService2)).Should(Exit(0)) - Eventually(helpers.CF("delete-service", managedService1, "-f")).Should(Exit(0)) - Eventually(helpers.CF("delete-service", managedService2, "-f")).Should(Exit(0)) - broker.Forget() - helpers.QuickDeleteOrg(orgName) - }) - - When("CAPI version is < 2.125.0", func() { - It("displays all service information", func() { - session := helpers.CF("services") - Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) - Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker`)) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s`, managedService1, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, "create succeeded")) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s`, managedService2, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, appName2, "create succeeded")) - Eventually(session).Should(Say(`%s\s+%s\s+%s`, userProvidedService1, "user-provided", appName1)) - Eventually(session).Should(Say(`%s\s+%s\s+%s, %s`, userProvidedService2, "user-provided", appName1, appName2)) - Eventually(session).Should(Exit(0)) - }) - }) - - When("CAPI version is >= 2.125.0 (broker name is available in summary endpoint)", func() { - It("displays all service information", func() { - session := helpers.CF("services") - Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) - Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker`)) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, managedService1, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, "create succeeded", broker.Name)) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s, %s\s+%s\s+%s`, managedService2, broker.FirstServiceOfferingName(), broker.FirstServicePlanName(), appName1, appName2, "create succeeded", broker.Name)) - Eventually(session).Should(Say(`%s\s+%s\s+%s`, userProvidedService1, "user-provided", appName1)) - Eventually(session).Should(Say(`%s\s+%s\s+%s, %s`, userProvidedService2, "user-provided", appName1, appName2)) - Eventually(session).Should(Exit(0)) - }) - }) - }) - - Context("has only services", func() { - const ( - serviceInstanceWithNoMaintenanceInfo = "s3" - serviceInstanceWithOldMaintenanceInfo = "s2" - serviceInstanceWithNewMaintenanceInfo = "s1" - ) - - var ( - broker *servicebrokerstub.ServiceBrokerStub - orgName string - spaceName string - service string - planWithNoMaintenanceInfo string - planWithMaintenanceInfo string - userProvidedService string - ) - - BeforeEach(func() { - orgName = helpers.NewOrgName() - spaceName = helpers.NewSpaceName() - helpers.SetupCF(orgName, spaceName) - - broker = servicebrokerstub.New().WithPlans(2) - - service = broker.FirstServiceOfferingName() - planWithMaintenanceInfo = broker.Services[0].Plans[0].Name - broker.Services[0].Plans[0].MaintenanceInfo = &config.MaintenanceInfo{Version: "1.2.3"} - planWithNoMaintenanceInfo = broker.Services[0].Plans[1].Name - broker.Services[0].Plans[1].MaintenanceInfo = nil - - broker.EnableServiceAccess() - - Eventually(helpers.CF("create-service", service, planWithNoMaintenanceInfo, serviceInstanceWithNoMaintenanceInfo)).Should(Exit(0)) - Eventually(helpers.CF("create-service", service, planWithMaintenanceInfo, serviceInstanceWithOldMaintenanceInfo)).Should(Exit(0)) - - broker.Services[0].Plans[0].MaintenanceInfo = &config.MaintenanceInfo{Version: "2.0.0"} - - broker.Configure().Register() - Eventually(helpers.CF("create-service", service, planWithMaintenanceInfo, serviceInstanceWithNewMaintenanceInfo)).Should(Exit(0)) - - userProvidedService = helpers.PrefixedRandomName("UPS1") - Eventually(helpers.CF("cups", userProvidedService, "-p", `{"username": "admin", "password": "admin"}`)).Should(Exit(0)) - }) - - AfterEach(func() { - Eventually(helpers.CF("delete-service", serviceInstanceWithNoMaintenanceInfo, "-f")).Should(Exit(0)) - Eventually(helpers.CF("delete-service", serviceInstanceWithOldMaintenanceInfo, "-f")).Should(Exit(0)) - Eventually(helpers.CF("delete-service", serviceInstanceWithNewMaintenanceInfo, "-f")).Should(Exit(0)) - - broker.Forget() - helpers.QuickDeleteOrg(orgName) - }) - - When("CAPI version supports maintenance_info in summary endpoint", func() { - BeforeEach(func() { - helpers.SkipIfVersionLessThan(ccversion.MinVersionMaintenanceInfoInSummaryV2) - }) - - It("displays all service information", func() { - session := helpers.CF("services") - Eventually(session).Should(Say("Getting services in org %s / space %s as %s...", orgName, spaceName, userName)) - Eventually(session).Should(Say(`name\s+service\s+plan\s+bound apps\s+last operation\s+broker\s+upgrade available`)) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithNewMaintenanceInfo, service, planWithMaintenanceInfo, "", "create succeeded", broker.Name, "no")) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithOldMaintenanceInfo, service, planWithMaintenanceInfo, "", "create succeeded", broker.Name, "yes")) - Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`, serviceInstanceWithNoMaintenanceInfo, service, planWithNoMaintenanceInfo, "", "create succeeded", broker.Name, "")) - Eventually(session).Should(Say(`%s\s+%s\s+`, userProvidedService, "user-provided")) - Eventually(session).Should(Exit(0)) - }) - }) - }) -}) - -var _ = Describe("services command V3", func() { - const command = "v3-services" + const command = "services" var userName string @@ -360,7 +159,7 @@ var _ = Describe("services command V3", func() { }) }) - When("there are shared service instances", func() { + Context("has shared service instances", func() { var ( managedService, appNameOnSpaceA, appNameOnSpaceB string )