コード例 #1
0
ファイル: show_service_test.go プロジェクト: nsnt/cli
func TestShowServiceOutput(t *testing.T) {
	offering := cf.ServiceOfferingFields{}
	offering.Label = "mysql"
	offering.DocumentationUrl = "http://documentation.url"
	offering.Description = "the-description"

	plan := cf.ServicePlanFields{}
	plan.Guid = "plan-guid"
	plan.Name = "plan-name"

	serviceInstance := cf.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(t, ui.Outputs, testassert.Lines{
		{"Service instance:", "service1"},
		{"Service: ", "mysql"},
		{"Plan: ", "plan-name"},
		{"Description: ", "the-description"},
		{"Documentation url: ", "http://documentation.url"},
	})
}
コード例 #2
0
ファイル: bind_service_test.go プロジェクト: nsnt/cli
func TestBindCommand(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service"
	serviceInstance.Guid = "my-service-guid"
	reqFactory := &testreq.FakeReqFactory{
		Application:     app,
		ServiceInstance: serviceInstance,
	}
	serviceBindingRepo := &testapi.FakeServiceBindingRepo{}
	ui := callBindService(t, []string{"my-app", "my-service"}, reqFactory, serviceBindingRepo)

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, reqFactory.ServiceInstanceName, "my-service")

	assert.Equal(t, len(ui.Outputs), 3)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Binding service", "my-service", "my-app", "my-org", "my-space", "my-user"},
		{"OK"},
		{"TIP"},
	})
	assert.Equal(t, serviceBindingRepo.CreateServiceInstanceGuid, "my-service-guid")
	assert.Equal(t, serviceBindingRepo.CreateApplicationGuid, "my-app-guid")
}
コード例 #3
0
ファイル: unbind_service_test.go プロジェクト: nsnt/cli
func TestUnbindCommandWhenBindingIsNonExistent(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service"
	serviceInstance.Guid = "my-service-guid"
	reqFactory := &testreq.FakeReqFactory{
		Application:     app,
		ServiceInstance: serviceInstance,
	}
	serviceBindingRepo := &testapi.FakeServiceBindingRepo{DeleteBindingNotFound: true}
	ui := callUnbindService(t, []string{"my-app", "my-service"}, reqFactory, serviceBindingRepo)

	assert.Equal(t, reqFactory.ApplicationName, "my-app")
	assert.Equal(t, reqFactory.ServiceInstanceName, "my-service")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Unbinding app", "my-service", "my-app"},
		{"OK"},
		{"my-service", "my-app", "did not exist"},
	})
	assert.Equal(t, serviceBindingRepo.DeleteServiceInstance, serviceInstance)
	assert.Equal(t, serviceBindingRepo.DeleteApplicationGuid, "my-app-guid")
}
コード例 #4
0
ファイル: service_summary.go プロジェクト: nsnt/cli
func (resource ServiceInstancesSummaries) ToModels() (instances []cf.ServiceInstance) {
	for _, instanceSummary := range resource.ServiceInstances {
		applicationNames := resource.findApplicationNamesForInstance(instanceSummary.Name)

		planSummary := instanceSummary.ServicePlan
		servicePlan := cf.ServicePlanFields{}
		servicePlan.Name = planSummary.Name
		servicePlan.Guid = planSummary.Guid

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

		instance := cf.ServiceInstance{}
		instance.Name = instanceSummary.Name
		instance.ApplicationNames = applicationNames
		instance.ServicePlan = servicePlan
		instance.ServiceOffering = serviceOffering

		instances = append(instances, instance)
	}

	return
}
コード例 #5
0
ファイル: services.go プロジェクト: pmuellr/cli
func (repo CloudControllerServiceRepository) RenameService(instance cf.ServiceInstance, newName string) (apiResponse net.ApiResponse) {
	body := fmt.Sprintf(`{"name":"%s"}`, newName)
	path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.Target, instance.Guid)

	if instance.IsUserProvided() {
		path = fmt.Sprintf("%s/v2/user_provided_service_instances/%s", repo.config.Target, instance.Guid)
	}
	return repo.gateway.UpdateResource(path, repo.config.AccessToken, strings.NewReader(body))
}
コード例 #6
0
ファイル: services_test.go プロジェクト: nsnt/cli
func TestRenameService(t *testing.T) {
	path := "/v2/service_instances/my-service-instance-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Guid = "my-service-instance-guid"

	plan := cf.ServicePlanFields{}
	plan.Guid = "some-plan-guid"
	serviceInstance.ServicePlan = plan

	testRenameService(t, path, serviceInstance)
}
コード例 #7
0
ファイル: service_bindings_test.go プロジェクト: pmuellr/cli
func TestDeleteServiceBindingWhenBindingDoesNotExist(t *testing.T) {
	ts, handler, repo := createServiceBindingRepo(t, []testnet.TestRequest{})
	defer ts.Close()

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

	found, apiResponse := repo.Delete(serviceInstance, "app-2-guid")

	assert.Equal(t, handler.CallCount, 0)
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.False(t, found)
}
コード例 #8
0
ファイル: service_instance_test.go プロジェクト: nsnt/cli
func TestServiceInstanceReqExecute(t *testing.T) {
	instance := cf.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()

	assert.True(t, success)
	assert.Equal(t, repo.FindInstanceByNameName, "foo")
	assert.Equal(t, req.GetServiceInstance(), instance)
}
コード例 #9
0
ファイル: rename_service_test.go プロジェクト: nsnt/cli
func TestRenameService(t *testing.T) {
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "different-name"
	serviceInstance.Guid = "different-name-guid"
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedSpaceSuccess: true, ServiceInstance: serviceInstance}
	ui, fakeServiceRepo := callRenameService(t, []string{"my-service", "new-name"}, reqFactory)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Renaming service", "different-name", "new-name", "my-org", "my-space", "my-user"},
		{"OK"},
	})

	assert.Equal(t, fakeServiceRepo.RenameServiceServiceInstance, serviceInstance)
	assert.Equal(t, fakeServiceRepo.RenameServiceNewName, "new-name")
}
コード例 #10
0
ファイル: services_test.go プロジェクト: nsnt/cli
func TestDeleteServiceWithoutServiceBindings(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "DELETE",
		Path:     "/v2/service_instances/my-service-instance-guid",
		Response: testnet.TestResponse{Status: http.StatusOK},
	})

	ts, handler, repo := createServiceRepo(t, []testnet.TestRequest{req})
	defer ts.Close()
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Guid = "my-service-instance-guid"
	apiResponse := repo.DeleteService(serviceInstance)
	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
}
コード例 #11
0
func TestUpdateUserProvidedServiceWithoutJson(t *testing.T) {
	args := []string{"-l", "syslog://example.com", "service-name"}
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "found-service-name"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:    true,
		ServiceInstance: serviceInstance,
	}
	repo := &testapi.FakeUserProvidedServiceInstanceRepo{}
	ui := callUpdateUserProvidedService(t, args, reqFactory, repo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Updating user provided service"},
		{"OK"},
	})
}
コード例 #12
0
ファイル: show_service_test.go プロジェクト: nsnt/cli
func TestShowUserProvidedServiceOutput(t *testing.T) {
	serviceInstance2 := cf.ServiceInstance{}
	serviceInstance2.Name = "service1"
	serviceInstance2.Guid = "service1-guid"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:         true,
		TargetedSpaceSuccess: true,
		ServiceInstance:      serviceInstance2,
	}
	ui := callShowService([]string{"service1"}, reqFactory)

	assert.Equal(t, len(ui.Outputs), 3)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Service instance: ", "service1"},
		{"Service: ", "user-provided"},
	})
}
コード例 #13
0
ファイル: delete_service_test.go プロジェクト: nsnt/cli
func TestDeleteServiceCommandWithYes(t *testing.T) {
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service"
	serviceInstance.Guid = "my-service-guid"
	reqFactory := &testreq.FakeReqFactory{}
	serviceRepo := &testapi.FakeServiceRepo{FindInstanceByNameServiceInstance: serviceInstance}
	ui := callDeleteService(t, "Yes", []string{"my-service"}, reqFactory, serviceRepo)

	testassert.SliceContains(t, ui.Prompts, testassert.Lines{{"Are you sure"}})

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting service", "my-service"},
		{"OK"},
	})

	assert.Equal(t, serviceRepo.DeleteServiceServiceInstance, serviceInstance)
}
コード例 #14
0
func TestUpdateUserProvidedServiceWhenNoFlagsArePresent(t *testing.T) {
	args := []string{"service-name"}
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "found-service-name"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:    true,
		ServiceInstance: serviceInstance,
	}
	repo := &testapi.FakeUserProvidedServiceInstanceRepo{}
	ui := callUpdateUserProvidedService(t, args, reqFactory, repo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Updating user provided service", "found-service-name", "my-org", "my-space", "my-user"},
		{"OK"},
		{"No changes"},
	})
}
コード例 #15
0
func TestUpdateUserProvidedServiceWithJson(t *testing.T) {
	args := []string{"-p", `{"foo":"bar"}`, "-l", "syslog://example.com", "service-name"}
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "found-service-name"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:    true,
		ServiceInstance: serviceInstance,
	}
	repo := &testapi.FakeUserProvidedServiceInstanceRepo{}
	ui := callUpdateUserProvidedService(t, args, reqFactory, repo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Updating user provided service", "found-service-name", "my-org", "my-space", "my-user"},
		{"OK"},
	})
	assert.Equal(t, repo.UpdateServiceInstance.Name, serviceInstance.Name)
	assert.Equal(t, repo.UpdateServiceInstance.Params, map[string]string{"foo": "bar"})
	assert.Equal(t, repo.UpdateServiceInstance.SysLogDrainUrl, "syslog://example.com")
}
コード例 #16
0
func TestUpdateUserProvidedServiceWithInvalidJson(t *testing.T) {
	args := []string{"-p", `{"foo":"ba`, "service-name"}
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "found-service-name"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:    true,
		ServiceInstance: serviceInstance,
	}
	userProvidedServiceInstanceRepo := &testapi.FakeUserProvidedServiceInstanceRepo{}

	ui := callUpdateUserProvidedService(t, args, reqFactory, userProvidedServiceInstanceRepo)

	assert.NotEqual(t, userProvidedServiceInstanceRepo.UpdateServiceInstance, serviceInstance)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"JSON is invalid"},
	})
}
コード例 #17
0
ファイル: services_test.go プロジェクト: nsnt/cli
func TestDeleteServiceWithServiceBindings(t *testing.T) {
	_, _, repo := createServiceRepo(t, []testnet.TestRequest{})

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

	binding := cf.ServiceBindingFields{}
	binding.Url = "/v2/service_bindings/service-binding-1-guid"
	binding.AppGuid = "app-1-guid"

	binding2 := cf.ServiceBindingFields{}
	binding2.Url = "/v2/service_bindings/service-binding-2-guid"
	binding2.AppGuid = "app-2-guid"

	serviceInstance.ServiceBindings = []cf.ServiceBindingFields{binding, binding2}

	apiResponse := repo.DeleteService(serviceInstance)
	assert.True(t, apiResponse.IsNotSuccessful())
	assert.Equal(t, apiResponse.Message, "Cannot delete service instance, apps are still bound to it")
}
コード例 #18
0
ファイル: bind_service_test.go プロジェクト: nsnt/cli
func TestBindCommandIfServiceIsAlreadyBound(t *testing.T) {
	app := cf.Application{}
	app.Name = "my-app"
	app.Guid = "my-app-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service"
	serviceInstance.Guid = "my-service-guid"
	reqFactory := &testreq.FakeReqFactory{
		Application:     app,
		ServiceInstance: serviceInstance,
	}
	serviceBindingRepo := &testapi.FakeServiceBindingRepo{CreateErrorCode: "90003"}
	ui := callBindService(t, []string{"my-app", "my-service"}, reqFactory, serviceBindingRepo)

	assert.Equal(t, len(ui.Outputs), 3)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Binding service"},
		{"OK"},
		{"my-app", "is already bound", "my-service"},
	})
}
コード例 #19
0
ファイル: service_bindings_test.go プロジェクト: pmuellr/cli
func TestDeleteServiceBinding(t *testing.T) {
	ts, handler, repo := createServiceBindingRepo(t, []testnet.TestRequest{deleteBindingReq})
	defer ts.Close()

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

	binding := cf.ServiceBindingFields{}
	binding.Url = "/v2/service_bindings/service-binding-1-guid"
	binding.AppGuid = "app-1-guid"
	binding2 := cf.ServiceBindingFields{}
	binding2.Url = "/v2/service_bindings/service-binding-2-guid"
	binding2.AppGuid = "app-2-guid"
	serviceInstance.ServiceBindings = []cf.ServiceBindingFields{binding, binding2}

	found, apiResponse := repo.Delete(serviceInstance, "app-2-guid")

	assert.True(t, handler.AllRequestsCalled())
	assert.False(t, apiResponse.IsNotSuccessful())
	assert.True(t, found)
}
コード例 #20
0
func TestUpdateUserProvidedServiceWithAServiceInstanceThatIsNotUserProvided(t *testing.T) {
	args := []string{"-p", `{"foo":"bar"}`, "service-name"}
	plan := cf.ServicePlanFields{}
	plan.Guid = "my-plan-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "found-service-name"
	serviceInstance.ServicePlan = plan

	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess:    true,
		ServiceInstance: serviceInstance,
	}
	userProvidedServiceInstanceRepo := &testapi.FakeUserProvidedServiceInstanceRepo{}

	ui := callUpdateUserProvidedService(t, args, reqFactory, userProvidedServiceInstanceRepo)

	assert.NotEqual(t, userProvidedServiceInstanceRepo.UpdateServiceInstance, serviceInstance)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"Service Instance is not user provided"},
	})
}
コード例 #21
0
ファイル: list_services_test.go プロジェクト: nsnt/cli
func TestServices(t *testing.T) {
	plan := cf.ServicePlanFields{}
	plan.Guid = "spark-guid"
	plan.Name = "spark"

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

	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Name = "my-service-1"
	serviceInstance.ServicePlan = plan
	serviceInstance.ApplicationNames = []string{"cli1", "cli2"}
	serviceInstance.ServiceOffering = offering

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

	serviceInstance2 := cf.ServiceInstance{}
	serviceInstance2.Name = "my-service-2"
	serviceInstance2.ServicePlan = plan2
	serviceInstance2.ApplicationNames = []string{"cli1"}
	serviceInstance2.ServiceOffering = offering

	serviceInstance3 := cf.ServiceInstance{}
	serviceInstance3.Name = "my-service-provided-by-user"

	serviceInstances := []cf.ServiceInstance{serviceInstance, serviceInstance2, serviceInstance3}
	serviceSummaryRepo := &testapi.FakeServiceSummaryRepo{
		GetSummariesInCurrentSpaceInstances: serviceInstances,
	}
	ui := &testterm.FakeUI{}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)
	org := cf.OrganizationFields{}
	org.Name = "my-org"
	space := cf.SpaceFields{}
	space.Name = "my-space"
	config := &configuration.Configuration{
		SpaceFields:        space,
		OrganizationFields: org,
		AccessToken:        token,
	}

	cmd := NewListServices(ui, config, serviceSummaryRepo)
	cmd.Run(testcmd.NewContext("services", []string{}))

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting services in org", "my-org", "my-space", "my-user"},
		{"OK"},
		{"my-service-1", "cleardb", "spark", "cli1, cli2"},
		{"my-service-2", "cleardb", "spark-2", "cli1"},
		{"my-service-provided-by-user", "user-provided"},
	})
}
コード例 #22
0
ファイル: services_test.go プロジェクト: nsnt/cli
func TestRenameServiceWhenServiceIsUserProvided(t *testing.T) {
	path := "/v2/user_provided_service_instances/my-service-instance-guid"
	serviceInstance := cf.ServiceInstance{}
	serviceInstance.Guid = "my-service-instance-guid"
	testRenameService(t, path, serviceInstance)
}