コード例 #1
0
ファイル: service_summary.go プロジェクト: yingkitw/cli
func (resource ServiceInstancesSummaries) ToModels() (instances []models.ServiceInstance) {
	for _, instanceSummary := range resource.ServiceInstances {
		applicationNames := resource.findApplicationNamesForInstance(instanceSummary.Name)

		planSummary := instanceSummary.ServicePlan
		servicePlan := models.ServicePlanFields{}
		servicePlan.Name = planSummary.Name
		servicePlan.GUID = planSummary.GUID

		offeringSummary := planSummary.ServiceOffering
		serviceOffering := models.ServiceOfferingFields{}
		serviceOffering.Label = offeringSummary.Label
		serviceOffering.Provider = offeringSummary.Provider
		serviceOffering.Version = offeringSummary.Version

		instance := models.ServiceInstance{}
		instance.Name = instanceSummary.Name
		instance.LastOperation.Type = instanceSummary.LastOperation.Type
		instance.LastOperation.State = instanceSummary.LastOperation.State
		instance.LastOperation.Description = instanceSummary.LastOperation.Description
		instance.ApplicationNames = applicationNames
		instance.ServicePlan = servicePlan
		instance.ServiceOffering = serviceOffering

		instances = append(instances, instance)
	}

	return
}
コード例 #2
0
ファイル: services.go プロジェクト: Reejoshi/cli
func (repo CloudControllerServiceRepository) RenameService(instance models.ServiceInstance, newName string) (apiErr error) {
	body := fmt.Sprintf(`{"name":"%s"}`, newName)
	path := fmt.Sprintf("/v2/service_instances/%s?accepts_incomplete=true", instance.GUID)

	if instance.IsUserProvided() {
		path = fmt.Sprintf("/v2/user_provided_service_instances/%s", instance.GUID)
	}
	return repo.gateway.UpdateResource(repo.config.APIEndpoint(), path, strings.NewReader(body))
}
コード例 #3
0
ファイル: service.go プロジェクト: vframbach/cli
func (cmd *ShowService) populatePluginModel(serviceInstance models.ServiceInstance) {
	cmd.pluginModel.Name = serviceInstance.Name
	cmd.pluginModel.Guid = serviceInstance.Guid
	cmd.pluginModel.DashboardUrl = serviceInstance.DashboardUrl
	cmd.pluginModel.IsUserProvided = serviceInstance.IsUserProvided()
	cmd.pluginModel.LastOperation.Type = serviceInstance.LastOperation.Type
	cmd.pluginModel.LastOperation.State = serviceInstance.LastOperation.State
	cmd.pluginModel.LastOperation.Description = serviceInstance.LastOperation.Description
	cmd.pluginModel.LastOperation.CreatedAt = serviceInstance.LastOperation.CreatedAt
	cmd.pluginModel.LastOperation.UpdatedAt = serviceInstance.LastOperation.UpdatedAt
	cmd.pluginModel.ServicePlan.Name = serviceInstance.ServicePlan.Name
	cmd.pluginModel.ServicePlan.Guid = serviceInstance.ServicePlan.Guid
	cmd.pluginModel.ServiceOffering.DocumentationUrl = serviceInstance.ServiceOffering.DocumentationUrl
	cmd.pluginModel.ServiceOffering.Name = serviceInstance.ServiceOffering.Label
}
コード例 #4
0
ファイル: delete_service_test.go プロジェクト: yingkitw/cli
	"github.com/cloudfoundry/cli/cf/models"
	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/cloudfoundry/cli/testhelpers/matchers"
)

var _ = Describe("delete-service command", func() {
	var (
		ui                  *testterm.FakeUI
		requirementsFactory *testreq.FakeReqFactory
		serviceRepo         *apifakes.FakeServiceRepository
		serviceInstance     models.ServiceInstance
		configRepo          coreconfig.Repository
		deps                commandregistry.Dependency
	)

	updateCommandDependency := func(pluginCall bool) {
		deps.UI = ui
		deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
		deps.Config = configRepo
		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-service").SetDependency(deps, pluginCall))
	}

	BeforeEach(func() {
		ui = &testterm.FakeUI{
			Inputs: []string{"yes"},
		}
コード例 #5
0
ファイル: service_test.go プロジェクト: xinpingluo/cli
			Expect(runCommand("come-ON")).To(BeFalse())
		})

		It("fails when a space is not targeted", func() {
			requirementsFactory.LoginSuccess = true

			Expect(runCommand("okay-this-time-please??")).To(BeFalse())
		})
	})

	Describe("After Requirement", func() {
		createServiceInstanceWithState := func(state string) {
			offering := models.ServiceOfferingFields{Label: "mysql", DocumentationUrl: "http://documentation.url", Description: "the-description"}
			plan := models.ServicePlanFields{Guid: "plan-guid", Name: "plan-name"}

			serviceInstance := models.ServiceInstance{}
			serviceInstance.Name = "service1"
			serviceInstance.Guid = "service1-guid"
			serviceInstance.LastOperation.Type = "create"
			serviceInstance.LastOperation.State = "in progress"
			serviceInstance.LastOperation.Description = "creating resource - step 1"
			serviceInstance.ServicePlan = plan
			serviceInstance.ServiceOffering = offering
			serviceInstance.DashboardUrl = "some-url"
			serviceInstance.LastOperation.State = state
			serviceInstance.LastOperation.CreatedAt = "created-date"
			serviceInstance.LastOperation.UpdatedAt = "updated-date"
			requirementsFactory.ServiceInstance = serviceInstance
		}

		createServiceInstance := func() {
コード例 #6
0
ファイル: service_instance_test.go プロジェクト: Reejoshi/cli
	"github.com/cloudfoundry/cli/cf/models"
	. "github.com/cloudfoundry/cli/cf/requirements"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ServiceInstanceRequirement", func() {
	var repo *apifakes.FakeServiceRepository

	BeforeEach(func() {
		repo = new(apifakes.FakeServiceRepository)
	})

	Context("when a service instance with the given name can be found", func() {
		It("succeeds", func() {
			instance := models.ServiceInstance{}
			instance.Name = "my-service"
			instance.GUID = "my-service-guid"
			repo.FindInstanceByNameReturns(instance, nil)

			req := NewServiceInstanceRequirement("my-service", repo)

			err := req.Execute()
			Expect(err).NotTo(HaveOccurred())
			Expect(repo.FindInstanceByNameArgsForCall(0)).To(Equal("my-service"))
			Expect(req.GetServiceInstance()).To(Equal(instance))
		})
	})

	Context("when a service instance with the given name can't be found", func() {
		It("errors", func() {
コード例 #7
0
				}))
			})

			It("TestCreateServiceBindingIfError", func() {
				apiErr := repo.Create("my-service-instance-guid", "my-app-guid")

				Expect(testHandler).To(testnet.HaveAllRequestsCalled())
				Expect(apiErr).NotTo(BeNil())
				Expect(apiErr.(errors.HttpError).ErrorCode()).To(Equal("90003"))
			})
		})
	})

	Describe("Delete", func() {
		Context("when binding does exist", func() {
			var serviceInstance models.ServiceInstance

			BeforeEach(func() {
				setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
					Method:   "DELETE",
					Path:     "/v2/service_bindings/service-binding-2-guid",
					Response: testnet.TestResponse{Status: http.StatusOK},
				}))

				serviceInstance.Guid = "my-service-instance-guid"

				binding := models.ServiceBindingFields{}
				binding.Url = "/v2/service_bindings/service-binding-1-guid"
				binding.AppGuid = "app-1-guid"
				binding2 := models.ServiceBindingFields{}
				binding2.Url = "/v2/service_bindings/service-binding-2-guid"
コード例 #8
0
		deps                commandregistry.Dependency
	)

	updateCommandDependency := func(pluginCall bool) {
		deps.UI = ui
		deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
		deps.RepoLocator = deps.RepoLocator.SetServiceKeyRepository(serviceKeyRepo)
		deps.Config = config
		commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-service-key").SetDependency(deps, pluginCall))
	}

	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		config = testconfig.NewRepositoryWithDefaults()
		serviceRepo = &apifakes.FakeServiceRepository{}
		serviceInstance := models.ServiceInstance{}
		serviceInstance.GUID = "fake-service-instance-guid"
		serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
		serviceKeyRepo = apifakes.NewFakeServiceKeyRepo()
		requirementsFactory = new(requirementsfakes.FakeFactory)
		requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
		requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{})
	})

	var callDeleteServiceKey = func(args []string) bool {
		return testcmd.RunCLICommand("delete-service-key", args, requirementsFactory, updateCommandDependency, false, ui)
	}

	Describe("requirements are not satisfied", func() {
		It("fails when not logged in", func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
コード例 #9
0
ファイル: rename_service_test.go プロジェクト: GABONIA/cli
		It("fails when not logged in", func() {
			requirementsFactory.TargetedSpaceSuccess = true
			runCommand("banana", "fppants")

			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})

		It("fails when a space is not targeted", func() {
			requirementsFactory.LoginSuccess = true
			runCommand("banana", "faaaaasdf")
			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	Context("when logged in and a space is targeted", func() {
		var serviceInstance models.ServiceInstance

		BeforeEach(func() {
			serviceInstance = models.ServiceInstance{}
			serviceInstance.Name = "different-name"
			serviceInstance.Guid = "different-name-guid"

			requirementsFactory.LoginSuccess = true
			requirementsFactory.TargetedSpaceSuccess = true
			requirementsFactory.ServiceInstance = serviceInstance
		})

		It("renames the service, obviously", func() {
			runCommand("my-service", "new-name")

			Expect(ui.Outputs).To(ContainSubstrings(
コード例 #10
0
	. "github.com/cloudfoundry/cli/cf/commands/service"
	"github.com/cloudfoundry/cli/cf/models"
	testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
	testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
	testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/cloudfoundry/cli/testhelpers/matchers"
)

var _ = Describe("unbind-service command", func() {
	var (
		app                 models.Application
		serviceInstance     models.ServiceInstance
		requirementsFactory *testreq.FakeReqFactory
		serviceBindingRepo  *testapi.FakeServiceBindingRepo
	)

	BeforeEach(func() {
		app.Name = "my-app"
		app.Guid = "my-app-guid"

		serviceInstance.Name = "my-service"
		serviceInstance.Guid = "my-service-guid"

		requirementsFactory = &testreq.FakeReqFactory{}
		requirementsFactory.Application = app
		requirementsFactory.ServiceInstance = serviceInstance

		serviceBindingRepo = &testapi.FakeServiceBindingRepo{}
コード例 #11
0
ファイル: service_test.go プロジェクト: BlueSpice/cli
			Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
		})
	})

	Context("when logged in, a space is targeted, and provided the name of a service that exists", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true
			requirementsFactory.TargetedSpaceSuccess = true
		})

		Context("when the service is externally provided", func() {
			BeforeEach(func() {
				offering := models.ServiceOfferingFields{Label: "mysql", DocumentationUrl: "http://documentation.url", Description: "the-description"}
				plan := models.ServicePlanFields{Guid: "plan-guid", Name: "plan-name"}

				serviceInstance := models.ServiceInstance{}
				serviceInstance.Name = "service1"
				serviceInstance.Guid = "service1-guid"
				serviceInstance.ServicePlan = plan
				serviceInstance.ServiceOffering = offering
				requirementsFactory.ServiceInstance = serviceInstance
			})

			It("shows the service", func() {
				runCommand("service1")

				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Service instance:", "service1"},
					[]string{"Service: ", "mysql"},
					[]string{"Plan: ", "plan-name"},
					[]string{"Description: ", "the-description"},
コード例 #12
0
ファイル: unbind_route_service.go プロジェクト: Reejoshi/cli
func (cmd *UnbindRouteService) UnbindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
	return cmd.routeServiceBindingRepo.Unbind(serviceInstance.GUID, route.GUID, serviceInstance.IsUserProvided())
}
コード例 #13
0
ファイル: bind_route_service.go プロジェクト: datatonic/cli
func (cmd *BindRouteService) BindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
	return cmd.routeServiceBindingRepo.Bind(serviceInstance.Guid, route.Guid, serviceInstance.IsUserProvided())
}
コード例 #14
0
				Expect(routeRepo.FindCallCount()).To(Equal(1))
				host, _, _, _ := routeRepo.FindArgsForCall(0)
				Expect(host).To(Equal("the-hostname"))
			})
		})

		Context("when the route can be found", func() {
			BeforeEach(func() {
				routeRepo.FindReturns(models.Route{GUID: "route-guid"}, nil)
			})

			Context("when the service instance is not user-provided and requires route forwarding", func() {
				BeforeEach(func() {
					serviceInstance := models.ServiceInstance{
						ServiceOffering: models.ServiceOfferingFields{
							Requires: []string{"route_forwarding"},
						},
					}
					serviceInstance.ServicePlan = models.ServicePlanFields{
						GUID: "service-plan-guid",
					}
					serviceInstanceRequirement.GetServiceInstanceReturns(serviceInstance)
				})

				It("asks the user to confirm", func() {
					ui.Inputs = []string{"n"}
					cmd.Execute(flagContext)
					Expect(ui.Prompts).To(ContainSubstrings(
						[]string{"Binding may cause requests for route", "Do you want to proceed?"},
					))
				})
コード例 #15
0
ファイル: service_bindings_test.go プロジェクト: Reejoshi/cli
							"description":"The app space binding to service is taken: 7b959018-110a-4913-ac0a-d663e613cdea 346bf237-7eef-41a7-b892-68fb08068f09"
						}`),
					),
				)
			})

			It("returns an error", func() {
				err := repo.Create("my-service-instance-guid", "my-app-guid", nil)
				Expect(err).To(HaveOccurred())
				Expect(err.(errors.HTTPError).ErrorCode()).To(Equal("90003"))
			})
		})
	})

	Describe("Delete", func() {
		var serviceInstance models.ServiceInstance

		BeforeEach(func() {
			serviceInstance.GUID = "my-service-instance-guid"
		})

		Context("when binding does exist", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("DELETE", "/v2/service_bindings/service-binding-2-guid"),
						ghttp.RespondWith(http.StatusOK, nil),
					),
				)

				serviceInstance.ServiceBindings = []models.ServiceBindingFields{
コード例 #16
0
	Describe("Execute", func() {
		BeforeEach(func() {
			err := flagContext.Parse("service-instance-name")
			Expect(err).NotTo(HaveOccurred())
			cmd.Requirements(factory, flagContext)
		})

		It("finds the instance by name in the service repo", func() {
			err := flagContext.Parse("service-instance-name", "-f")
			Expect(err).NotTo(HaveOccurred())
			cmd.Execute(flagContext)
			Expect(serviceRepo.FindInstanceByNameCallCount()).To(Equal(1))
		})

		Context("when the instance can be found", func() {
			var serviceInstance models.ServiceInstance

			BeforeEach(func() {
				serviceInstance = models.ServiceInstance{}
				serviceInstance.Name = "service-instance-name"
				serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
			})

			It("warns the user", func() {
				ui.Inputs = []string{"n"}
				cmd.Execute(flagContext)
				Eventually(func() []string {
					return ui.Outputs()
				}).Should(ContainSubstrings(
					[]string{"WARNING"},
				))
コード例 #17
0
ファイル: services_test.go プロジェクト: raghulsid/cli
	})

	It("lists available services", func() {
		plan := models.ServicePlanFields{
			Guid: "spark-guid",
			Name: "spark",
		}

		plan2 := models.ServicePlanFields{
			Guid: "spark-guid-2",
			Name: "spark-2",
		}

		offering := models.ServiceOfferingFields{Label: "cleardb"}

		serviceInstance := models.ServiceInstance{}
		serviceInstance.Name = "my-service-1"
		serviceInstance.LastOperation.Type = "create"
		serviceInstance.LastOperation.State = "in progress"
		serviceInstance.LastOperation.Description = "fake state description"
		serviceInstance.ServicePlan = plan
		serviceInstance.ApplicationNames = []string{"cli1", "cli2"}
		serviceInstance.ServiceOffering = offering

		serviceInstance2 := models.ServiceInstance{}
		serviceInstance2.Name = "my-service-2"
		serviceInstance2.LastOperation.Type = "create"
		serviceInstance2.LastOperation.State = ""
		serviceInstance2.LastOperation.Description = "fake state description"
		serviceInstance2.ServicePlan = plan2
		serviceInstance2.ApplicationNames = []string{"cli1"}
コード例 #18
0
ファイル: service_keys_test.go プロジェクト: vframbach/cli
		deps                command_registry.Dependency
	)

	updateCommandDependency := func(pluginCall bool) {
		deps.Ui = ui
		deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
		deps.RepoLocator = deps.RepoLocator.SetServiceKeyRepository(serviceKeyRepo)
		deps.Config = config
		command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("service-keys").SetDependency(deps, pluginCall))
	}

	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		config = testconfig.NewRepositoryWithDefaults()
		serviceRepo = &testapi.FakeServiceRepository{}
		serviceInstance := models.ServiceInstance{}
		serviceInstance.Guid = "fake-instance-guid"
		serviceInstance.Name = "fake-service-instance"
		serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
		serviceKeyRepo = testapi.NewFakeServiceKeyRepo()
		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, ServiceInstanceNotFound: false}
		requirementsFactory.ServiceInstance = serviceInstance
	})

	var callListServiceKeys = func(args []string) bool {
		return testcmd.RunCliCommand("service-keys", args, requirementsFactory, updateCommandDependency, false)
	}

	Describe("requirements", func() {
		It("fails when not logged in", func() {
			requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
コード例 #19
0
			Expect(runCommand("come-ON")).To(BeFalse())
		})

		It("fails when a space is not targeted", func() {
			requirementsFactory.LoginSuccess = true

			Expect(runCommand("okay-this-time-please??")).To(BeFalse())
		})
	})

	Describe("After Requirement", func() {
		createServiceInstanceWithState := func(state string) {
			offering := models.ServiceOfferingFields{Label: "mysql", DocumentationUrl: "http://documentation.url", Description: "the-description"}
			plan := models.ServicePlanFields{Guid: "plan-guid", Name: "plan-name"}

			serviceInstance := models.ServiceInstance{}
			serviceInstance.Name = "service1"
			serviceInstance.Guid = "service1-guid"
			serviceInstance.LastOperation.Type = "create"
			serviceInstance.LastOperation.State = "in progress"
			serviceInstance.LastOperation.Description = "creating resource - step 1"
			serviceInstance.ServicePlan = plan
			serviceInstance.ServiceOffering = offering
			serviceInstance.DashboardUrl = "some-url"
			serviceInstance.LastOperation.State = state
			serviceInstance.LastOperation.CreatedAt = "created-date"
			serviceInstance.LastOperation.UpdatedAt = "updated-date"
			requirementsFactory.ServiceInstance = serviceInstance
		}

		createServiceInstance := func() {
コード例 #20
0
			runCommand()
			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Incorrect Usage", "Requires", "argument"},
			))
		})

		It("fails when not logged in", func() {
			Expect(runCommand("whoops")).To(BeFalse())
		})
	})

	Context("when logged in", func() {
		BeforeEach(func() {
			requirementsFactory.LoginSuccess = true

			serviceInstance := models.ServiceInstance{}
			serviceInstance.Name = "service-name"
			requirementsFactory.ServiceInstance = serviceInstance
		})

		Context("when no flags are provided", func() {
			It("tells the user that no changes occurred", func() {
				runCommand("service-name")

				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"Updating user provided service", "service-name", "my-org", "my-space", "my-user"},
					[]string{"OK"},
					[]string{"No changes"},
				))
			})
		})
コード例 #21
0
ファイル: services_test.go プロジェクト: GABONIA/cli
			_, err := repo.FindInstanceByName("my-service")

			Expect(testHandler).To(testnet.HaveAllRequestsCalled())
			Expect(err).To(BeAssignableToTypeOf(&errors.ModelNotFoundError{}))
		})
	})

	Describe("DeleteService", func() {
		It("it deletes the service when no apps are bound", func() {
			setupTestServer(testapi.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "DELETE",
				Path:     "/v2/service_instances/my-service-instance-guid",
				Response: testnet.TestResponse{Status: http.StatusOK},
			}))

			serviceInstance := models.ServiceInstance{}
			serviceInstance.Guid = "my-service-instance-guid"

			err := repo.DeleteService(serviceInstance)
			Expect(testHandler).To(testnet.HaveAllRequestsCalled())
			Expect(err).NotTo(HaveOccurred())
		})

		It("doesn't delete the service when apps are bound", func() {
			setupTestServer()

			serviceInstance := models.ServiceInstance{}
			serviceInstance.Guid = "my-service-instance-guid"
			serviceInstance.ServiceBindings = []models.ServiceBindingFields{
				{
					Url:     "/v2/service_bindings/service-binding-1-guid",
コード例 #22
0
						GUID: "service-plan-guid",
					},
				})
			})

			It("fails with error", func() {
				Expect(func() { cmd.Execute(flagContext) }).To(Panic())
				Expect(ui.Outputs).To(ContainSubstrings(
					[]string{"FAILED"},
					[]string{"Service Instance is not user provided"},
				))
			})
		})

		Context("when the service instance is user-provided", func() {
			var serviceInstance models.ServiceInstance
			BeforeEach(func() {
				serviceInstance = models.ServiceInstance{
					ServicePlan: models.ServicePlanFields{
						GUID:        "",
						Description: "service-plan-description",
					},
				}
				serviceInstance.Name = "service-instance"
				serviceInstance.Params = map[string]interface{}{}
				serviceInstanceRequirement.GetServiceInstanceReturns(serviceInstance)
			})

			It("tells the user it is updating the user provided service", func() {
				cmd.Execute(flagContext)
				Expect(ui.Outputs).To(ContainSubstrings(
コード例 #23
0
ファイル: services_test.go プロジェクト: Reejoshi/cli
			_, err := repo.FindInstanceByName("my-service")

			Expect(testHandler).To(HaveAllRequestsCalled())
			Expect(err).NotTo(HaveOccurred())
		})
	})

	Describe("DeleteService", func() {
		It("deletes the service when no apps and keys are bound", func() {
			setupTestServer(apifakes.NewCloudControllerTestRequest(testnet.TestRequest{
				Method:   "DELETE",
				Path:     "/v2/service_instances/my-service-instance-guid?accepts_incomplete=true&async=true",
				Response: testnet.TestResponse{Status: http.StatusOK},
			}))

			serviceInstance := models.ServiceInstance{}
			serviceInstance.GUID = "my-service-instance-guid"

			err := repo.DeleteService(serviceInstance)
			Expect(testHandler).To(HaveAllRequestsCalled())
			Expect(err).NotTo(HaveOccurred())
		})

		It("doesn't delete the service when apps are bound", func() {
			setupTestServer()

			serviceInstance := models.ServiceInstance{}
			serviceInstance.GUID = "my-service-instance-guid"
			serviceInstance.ServiceBindings = []models.ServiceBindingFields{
				{
					URL:     "/v2/service_bindings/service-binding-1-guid",
コード例 #24
0
var _ = Describe("service-keys command", func() {
	var (
		ui                  *testterm.FakeUI
		config              core_config.Repository
		cmd                 *ServiceKeys
		requirementsFactory *testreq.FakeReqFactory
		serviceRepo         *testapi.FakeServiceRepo
		serviceKeyRepo      *testapi.FakeServiceKeyRepo
	)

	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		config = testconfig.NewRepositoryWithDefaults()
		serviceRepo = &testapi.FakeServiceRepo{}
		serviceInstance := models.ServiceInstance{}
		serviceInstance.Guid = "fake-instance-guid"
		serviceRepo.FindInstanceByNameMap = generic.NewMap()
		serviceRepo.FindInstanceByNameMap.Set("fake-service-instance", serviceInstance)
		serviceKeyRepo = testapi.NewFakeServiceKeyRepo()
		cmd = NewListServiceKeys(ui, config, serviceRepo, serviceKeyRepo)
		requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, ServiceInstanceNotFound: false}
		requirementsFactory.ServiceInstance = serviceInstance
	})

	var callListServiceKeys = func(args []string) bool {
		return testcmd.RunCommand(cmd, args, requirementsFactory)
	}

	Describe("requirements", func() {
		It("fails when not logged in", func() {
コード例 #25
0
				Expect(routeRepo.FindCallCount()).To(Equal(1))
				host, _, _ := routeRepo.FindArgsForCall(0)
				Expect(host).To(Equal("the-hostname"))
			})
		})

		Context("when the route can be found", func() {
			BeforeEach(func() {
				routeRepo.FindReturns(models.Route{Guid: "route-guid"}, nil)
			})

			Context("when the service instance is not user-provided and requires route forwarding", func() {
				BeforeEach(func() {
					serviceInstance := models.ServiceInstance{
						ServiceOffering: models.ServiceOfferingFields{
							Requires: []string{"route_forwarding"},
						},
					}
					serviceInstance.ServicePlan = models.ServicePlanFields{
						Guid: "service-plan-guid",
					}
					serviceInstanceRequirement.GetServiceInstanceReturns(serviceInstance)
				})

				It("asks the user to confirm", func() {
					ui.Inputs = []string{"n"}
					cmd.Execute(flagContext)
					Expect(ui.Prompts).To(ContainSubstrings(
						[]string{"Binding may cause requests for route", "Do you want to proceed?"},
					))
				})