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", AppGUID: "app-1-guid",
) 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("create-service-key").SetDependency(deps, pluginCall)) } BeforeEach(func() { ui = &testterm.FakeUI{} config = testconfig.NewRepositoryWithDefaults() serviceRepo = &apifakes.FakeServiceRepository{} serviceInstance := models.ServiceInstance{} serviceInstance.GUID = "fake-instance-guid" serviceInstance.Name = "fake-service-instance" serviceRepo.FindInstanceByNameReturns(serviceInstance, nil) serviceKeyRepo = apifakes.NewFakeServiceKeyRepo() requirementsFactory = new(requirementsfakes.FakeFactory) requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{}) serviceInstanceReq := new(requirementsfakes.FakeServiceInstanceRequirement) requirementsFactory.NewServiceInstanceRequirementReturns(serviceInstanceReq) serviceInstanceReq.GetServiceInstanceReturns(serviceInstance) }) var callCreateService = func(args []string) bool { return testcmd.RunCLICommand("create-service-key", args, requirementsFactory, updateCommandDependency, false, ui) }
updateCommandDependency := func(pluginCall bool) { deps.UI = ui deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo) deps.Config = config commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("rename-service").SetDependency(deps, pluginCall)) } BeforeEach(func() { ui = &testterm.FakeUI{} config = testconfig.NewRepositoryWithDefaults() serviceRepo = new(apifakes.FakeServiceRepository) requirementsFactory = new(requirementsfakes.FakeFactory) serviceInstance = models.ServiceInstance{} serviceInstance.Name = "different-name" serviceInstance.GUID = "different-name-guid" serviceReq := new(requirementsfakes.FakeServiceInstanceRequirement) serviceReq.GetServiceInstanceReturns(serviceInstance) requirementsFactory.NewServiceInstanceRequirementReturns(serviceReq) }) runCommand := func(args ...string) bool { return testcmd.RunCLICommand("rename-service", args, requirementsFactory, updateCommandDependency, false, ui) } Describe("requirements", func() { It("Fails with usage when exactly two parameters not passed", func() { runCommand("whatever") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage", "Requires", "arguments"}, ))