當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.ServiceInstance類代碼示例

本文整理匯總了Golang中cf/models.ServiceInstance的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceInstance類的具體用法?Golang ServiceInstance怎麽用?Golang ServiceInstance使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ServiceInstance類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ToModels

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
}
開發者ID:juggernaut,項目名稱:cli,代碼行數:26,代碼來源:service_summary.go

示例2: RenameService

func (repo CloudControllerServiceRepository) RenameService(instance models.ServiceInstance, newName string) (apiErr errors.Error) {
	body := fmt.Sprintf(`{"name":"%s"}`, newName)
	path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.ApiEndpoint(), instance.Guid)

	if instance.IsUserProvided() {
		path = fmt.Sprintf("%s/v2/user_provided_service_instances/%s", repo.config.ApiEndpoint(), instance.Guid)
	}
	return repo.gateway.UpdateResource(path, repo.config.AccessToken(), strings.NewReader(body))
}
開發者ID:knolleary,項目名稱:cli,代碼行數:9,代碼來源:services.go

示例3:

		ts, handler, repo := createServiceBindingRepo([]testnet.TestRequest{req})
		defer ts.Close()

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

		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(apiErr).NotTo(BeNil())
		Expect(apiErr.ErrorCode()).To(Equal("90003"))
	})

	It("TestDeleteServiceBinding", func() {
		ts, handler, repo := createServiceBindingRepo([]testnet.TestRequest{deleteBindingReq})
		defer ts.Close()

		serviceInstance := models.ServiceInstance{}
		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}

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

		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(apiErr).NotTo(HaveOccurred())
		Expect(found).To(BeTrue())
開發者ID:jibin-tomy,項目名稱:cli,代碼行數:30,代碼來源:service_bindings_test.go

示例4:

		userProvidedServiceInstanceRepo := &testapi.FakeUserProvidedServiceInstanceRepo{}

		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() {
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:update_user_provided_service_test.go

示例5:

		cmd := NewBindService(&testterm.FakeUI{}, testconfig.NewRepository(), &testapi.FakeServiceBindingRepo{})
		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"},
			})
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:bind_service_test.go

示例6:

package requirements_test

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}
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:service_instance_test.go

示例7:

			_, 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",
開發者ID:nota-ja,項目名稱:cli,代碼行數:31,代碼來源:services_test.go

示例8:

	})
	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"))
	})
})
開發者ID:nota-ja,項目名稱:cli,代碼行數:30,代碼來源:rename_service_test.go

示例9:

		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"},
開發者ID:knolleary,項目名稱:cli,代碼行數:30,代碼來源:show_service_test.go

示例10:

	})

	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}
開發者ID:knolleary,項目名稱:cli,代碼行數:31,代碼來源:list_services_test.go


注:本文中的cf/models.ServiceInstance類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。