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() {
			requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: false}
Example #2
0
			})
		})
	})

	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"
				binding2.AppGuid = "app-2-guid"
				serviceInstance.ServiceBindings = []models.ServiceBindingFields{binding, binding2}
			})

			It("TestDeleteServiceBinding", func() {
				found, apiErr := repo.Delete(serviceInstance, "app-2-guid")

				Expect(testHandler).To(testnet.HaveAllRequestsCalled())
				Expect(apiErr).NotTo(HaveOccurred())
Example #3
0
		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() {
			createServiceInstanceWithState("")
		}
Example #4
0
		})

		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(
				[]string{"Renaming service", "different-name", "new-name", "my-org", "my-space", "my-user"},
				[]string{"OK"},
			))

			Expect(serviceRepo.RenameServiceServiceInstance).To(Equal(serviceInstance))
		Expect(testcmd.RunCommand(cmd, []string{"service", "app"}, requirementsFactory)).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"))

			Expect(ui.Outputs).To(ContainSubstrings(
				[]string{"Binding service", "my-service", "my-app", "my-org", "my-space", "my-user"},
				[]string{"OK"},
				[]string{"TIP", "my-app"},
			))
			Expect(serviceBindingRepo.CreateServiceInstanceGuid).To(Equal("my-service-guid"))
			Expect(serviceBindingRepo.CreateApplicationGuid).To(Equal("my-app-guid"))