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.ApplicationNames = applicationNames instance.ServicePlan = servicePlan instance.ServiceOffering = serviceOffering instances = append(instances, instance) } return }
reqFactory.LoginSuccess = false callUpdateUserProvidedService(args, reqFactory, userProvidedServiceInstanceRepo) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) reqFactory.LoginSuccess = true callUpdateUserProvidedService(args, reqFactory, userProvidedServiceInstanceRepo) Expect(testcmd.CommandDidPassRequirements).To(BeTrue()) Expect(reqFactory.ServiceInstanceName).To(Equal("service-name")) }) It("TestUpdateUserProvidedServiceWhenNoFlagsArePresent", func() { args := []string{"service-name"} serviceInstance := models.ServiceInstance{} serviceInstance.Name = "found-service-name" reqFactory := &testreq.FakeReqFactory{ LoginSuccess: true, ServiceInstance: serviceInstance, } repo := &testapi.FakeUserProvidedServiceInstanceRepo{} ui := callUpdateUserProvidedService(args, reqFactory, repo) testassert.SliceContains(ui.Outputs, testassert.Lines{ {"Updating user provided service", "found-service-name", "my-org", "my-space", "my-user"}, {"OK"}, {"No changes"}, }) }) It("TestUpdateUserProvidedServiceWithJson", func() {
testcmd.RunCommand(cmd, context, requirementsFactory) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) Context("when logged in", func() { BeforeEach(func() { requirementsFactory.LoginSuccess = true }) It("binds a service instance to an app", func() { app := models.Application{} app.Name = "my-app" app.Guid = "my-app-guid" serviceInstance := models.ServiceInstance{} serviceInstance.Name = "my-service" serviceInstance.Guid = "my-service-guid" requirementsFactory.Application = app requirementsFactory.ServiceInstance = serviceInstance serviceBindingRepo := &testapi.FakeServiceBindingRepo{} ui := callBindService([]string{"my-app", "my-service"}, requirementsFactory, serviceBindingRepo) Expect(requirementsFactory.ApplicationName).To(Equal("my-app")) Expect(requirementsFactory.ServiceInstanceName).To(Equal("my-service")) testassert.SliceContains(ui.Outputs, testassert.Lines{ {"Binding service", "my-service", "my-app", "my-org", "my-space", "my-user"}, {"OK"}, {"TIP"}, }) Expect(serviceBindingRepo.CreateServiceInstanceGuid).To(Equal("my-service-guid"))
import ( "cf/models" . "cf/requirements" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" testapi "testhelpers/api" testassert "testhelpers/assert" testterm "testhelpers/terminal" ) var _ = Describe("Testing with ginkgo", func() { It("TestServiceInstanceReqExecute", func() { instance := models.ServiceInstance{} instance.Name = "my-service" instance.Guid = "my-service-guid" repo := &testapi.FakeServiceRepo{FindInstanceByNameServiceInstance: instance} ui := new(testterm.FakeUI) req := NewServiceInstanceRequirement("foo", ui, repo) success := req.Execute() Expect(success).To(BeTrue()) Expect(repo.FindInstanceByNameName).To(Equal("foo")) Expect(req.GetServiceInstance()).To(Equal(instance)) }) It("TestServiceInstanceReqExecuteWhenServiceInstanceNotFound", func() { repo := &testapi.FakeServiceRepo{FindInstanceByNameNotFound: true} ui := new(testterm.FakeUI)
}) It("TestRenameServiceRequirements", func() { requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: false, TargetedSpaceSuccess: true} callRenameService([]string{"my-service", "new-name"}, requirementsFactory) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: false} callRenameService([]string{"my-service", "new-name"}, requirementsFactory) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) Expect(requirementsFactory.ServiceInstanceName).To(Equal("my-service")) }) It("TestRenameService", func() { serviceInstance := models.ServiceInstance{} serviceInstance.Name = "different-name" serviceInstance.Guid = "different-name-guid" requirementsFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, ServiceInstance: serviceInstance} ui, fakeServiceRepo := callRenameService([]string{"my-service", "new-name"}, requirementsFactory) testassert.SliceContains(ui.Outputs, testassert.Lines{ {"Renaming service", "different-name", "new-name", "my-org", "my-space", "my-user"}, {"OK"}, }) Expect(fakeServiceRepo.RenameServiceServiceInstance).To(Equal(serviceInstance)) Expect(fakeServiceRepo.RenameServiceNewName).To(Equal("new-name")) }) })
ui = callShowService([]string{"my-service"}, reqFactory) Expect(ui.FailedWithUsage).To(BeFalse()) }) It("TestShowServiceOutput", func() { offering := models.ServiceOfferingFields{} offering.Label = "mysql" offering.DocumentationUrl = "http://documentation.url" offering.Description = "the-description" plan := models.ServicePlanFields{} plan.Guid = "plan-guid" plan.Name = "plan-name" serviceInstance := models.ServiceInstance{} serviceInstance.Name = "service1" serviceInstance.Guid = "service1-guid" serviceInstance.ServicePlan = plan serviceInstance.ServiceOffering = offering reqFactory := &testreq.FakeReqFactory{ LoginSuccess: true, TargetedSpaceSuccess: true, ServiceInstance: serviceInstance, } ui := callShowService([]string{"service1"}, reqFactory) testassert.SliceContains(ui.Outputs, testassert.Lines{ {"Service instance:", "service1"}, {"Service: ", "mysql"}, {"Plan: ", "plan-name"}, {"Description: ", "the-description"},
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.ServicePlan = plan serviceInstance.ApplicationNames = []string{"cli1", "cli2"} serviceInstance.ServiceOffering = offering serviceInstance2 := models.ServiceInstance{} serviceInstance2.Name = "my-service-2" serviceInstance2.ServicePlan = plan2 serviceInstance2.ApplicationNames = []string{"cli1"} serviceInstance2.ServiceOffering = offering serviceInstance3 := models.ServiceInstance{} serviceInstance3.Name = "my-service-provided-by-user" serviceInstances := []models.ServiceInstance{serviceInstance, serviceInstance2, serviceInstance3} serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{