本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/models.ServiceInstance類的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceInstance類的具體用法?Golang ServiceInstance怎麽用?Golang ServiceInstance使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ServiceInstance類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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.LastOperation.Type = instanceSummary.LastOperation.Type
instance.LastOperation.State = instanceSummary.LastOperation.State
instance.LastOperation.Description = instanceSummary.LastOperation.Description
instance.ApplicationNames = applicationNames
instance.ServicePlan = servicePlan
instance.ServiceOffering = serviceOffering
instances = append(instances, instance)
}
return
}
示例2: RenameService
func (repo CloudControllerServiceRepository) RenameService(instance models.ServiceInstance, newName string) (apiErr error) {
body := fmt.Sprintf(`{"name":"%s"}`, newName)
path := fmt.Sprintf("/v2/service_instances/%s?accepts_incomplete=true", instance.GUID)
if instance.IsUserProvided() {
path = fmt.Sprintf("/v2/user_provided_service_instances/%s", instance.GUID)
}
return repo.gateway.UpdateResource(repo.config.APIEndpoint(), path, strings.NewReader(body))
}
示例3: populatePluginModel
func (cmd *ShowService) populatePluginModel(serviceInstance models.ServiceInstance) {
cmd.pluginModel.Name = serviceInstance.Name
cmd.pluginModel.Guid = serviceInstance.Guid
cmd.pluginModel.DashboardUrl = serviceInstance.DashboardUrl
cmd.pluginModel.IsUserProvided = serviceInstance.IsUserProvided()
cmd.pluginModel.LastOperation.Type = serviceInstance.LastOperation.Type
cmd.pluginModel.LastOperation.State = serviceInstance.LastOperation.State
cmd.pluginModel.LastOperation.Description = serviceInstance.LastOperation.Description
cmd.pluginModel.LastOperation.CreatedAt = serviceInstance.LastOperation.CreatedAt
cmd.pluginModel.LastOperation.UpdatedAt = serviceInstance.LastOperation.UpdatedAt
cmd.pluginModel.ServicePlan.Name = serviceInstance.ServicePlan.Name
cmd.pluginModel.ServicePlan.Guid = serviceInstance.ServicePlan.Guid
cmd.pluginModel.ServiceOffering.DocumentationUrl = serviceInstance.ServiceOffering.DocumentationUrl
cmd.pluginModel.ServiceOffering.Name = serviceInstance.ServiceOffering.Label
}
示例4:
"github.com/cloudfoundry/cli/cf/models"
testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/cli/testhelpers/matchers"
)
var _ = Describe("delete-service command", func() {
var (
ui *testterm.FakeUI
requirementsFactory *testreq.FakeReqFactory
serviceRepo *apifakes.FakeServiceRepository
serviceInstance models.ServiceInstance
configRepo coreconfig.Repository
deps commandregistry.Dependency
)
updateCommandDependency := func(pluginCall bool) {
deps.UI = ui
deps.RepoLocator = deps.RepoLocator.SetServiceRepository(serviceRepo)
deps.Config = configRepo
commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("delete-service").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{
Inputs: []string{"yes"},
}
示例5:
Expect(runCommand("come-ON")).To(BeFalse())
})
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() {
示例6:
"github.com/cloudfoundry/cli/cf/models"
. "github.com/cloudfoundry/cli/cf/requirements"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ServiceInstanceRequirement", func() {
var repo *apifakes.FakeServiceRepository
BeforeEach(func() {
repo = new(apifakes.FakeServiceRepository)
})
Context("when a service instance with the given name can be found", func() {
It("succeeds", func() {
instance := models.ServiceInstance{}
instance.Name = "my-service"
instance.GUID = "my-service-guid"
repo.FindInstanceByNameReturns(instance, nil)
req := NewServiceInstanceRequirement("my-service", repo)
err := req.Execute()
Expect(err).NotTo(HaveOccurred())
Expect(repo.FindInstanceByNameArgsForCall(0)).To(Equal("my-service"))
Expect(req.GetServiceInstance()).To(Equal(instance))
})
})
Context("when a service instance with the given name can't be found", func() {
It("errors", func() {
示例7:
}))
})
It("TestCreateServiceBindingIfError", func() {
apiErr := repo.Create("my-service-instance-guid", "my-app-guid")
Expect(testHandler).To(testnet.HaveAllRequestsCalled())
Expect(apiErr).NotTo(BeNil())
Expect(apiErr.(errors.HttpError).ErrorCode()).To(Equal("90003"))
})
})
})
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"
示例8:
deps commandregistry.Dependency
)
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("delete-service-key").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
config = testconfig.NewRepositoryWithDefaults()
serviceRepo = &apifakes.FakeServiceRepository{}
serviceInstance := models.ServiceInstance{}
serviceInstance.GUID = "fake-service-instance-guid"
serviceRepo.FindInstanceByNameReturns(serviceInstance, nil)
serviceKeyRepo = apifakes.NewFakeServiceKeyRepo()
requirementsFactory = new(requirementsfakes.FakeFactory)
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{})
})
var callDeleteServiceKey = func(args []string) bool {
return testcmd.RunCLICommand("delete-service-key", args, requirementsFactory, updateCommandDependency, false, ui)
}
Describe("requirements are not satisfied", func() {
It("fails when not logged in", func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"})
示例9:
It("fails when not logged in", func() {
requirementsFactory.TargetedSpaceSuccess = true
runCommand("banana", "fppants")
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
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(
示例10:
. "github.com/cloudfoundry/cli/cf/commands/service"
"github.com/cloudfoundry/cli/cf/models"
testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/cli/testhelpers/matchers"
)
var _ = Describe("unbind-service command", func() {
var (
app models.Application
serviceInstance models.ServiceInstance
requirementsFactory *testreq.FakeReqFactory
serviceBindingRepo *testapi.FakeServiceBindingRepo
)
BeforeEach(func() {
app.Name = "my-app"
app.Guid = "my-app-guid"
serviceInstance.Name = "my-service"
serviceInstance.Guid = "my-service-guid"
requirementsFactory = &testreq.FakeReqFactory{}
requirementsFactory.Application = app
requirementsFactory.ServiceInstance = serviceInstance
serviceBindingRepo = &testapi.FakeServiceBindingRepo{}
示例11:
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
})
Context("when logged in, a space is targeted, and provided the name of a service that exists", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
requirementsFactory.TargetedSpaceSuccess = true
})
Context("when the service is externally provided", func() {
BeforeEach(func() {
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.ServicePlan = plan
serviceInstance.ServiceOffering = offering
requirementsFactory.ServiceInstance = serviceInstance
})
It("shows the service", func() {
runCommand("service1")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Service instance:", "service1"},
[]string{"Service: ", "mysql"},
[]string{"Plan: ", "plan-name"},
[]string{"Description: ", "the-description"},
示例12: UnbindRoute
func (cmd *UnbindRouteService) UnbindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
return cmd.routeServiceBindingRepo.Unbind(serviceInstance.GUID, route.GUID, serviceInstance.IsUserProvided())
}
示例13: BindRoute
func (cmd *BindRouteService) BindRoute(route models.Route, serviceInstance models.ServiceInstance) error {
return cmd.routeServiceBindingRepo.Bind(serviceInstance.Guid, route.Guid, serviceInstance.IsUserProvided())
}
示例14:
Expect(routeRepo.FindCallCount()).To(Equal(1))
host, _, _, _ := routeRepo.FindArgsForCall(0)
Expect(host).To(Equal("the-hostname"))
})
})
Context("when the route can be found", func() {
BeforeEach(func() {
routeRepo.FindReturns(models.Route{GUID: "route-guid"}, nil)
})
Context("when the service instance is not user-provided and requires route forwarding", func() {
BeforeEach(func() {
serviceInstance := models.ServiceInstance{
ServiceOffering: models.ServiceOfferingFields{
Requires: []string{"route_forwarding"},
},
}
serviceInstance.ServicePlan = models.ServicePlanFields{
GUID: "service-plan-guid",
}
serviceInstanceRequirement.GetServiceInstanceReturns(serviceInstance)
})
It("asks the user to confirm", func() {
ui.Inputs = []string{"n"}
cmd.Execute(flagContext)
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Binding may cause requests for route", "Do you want to proceed?"},
))
})
示例15:
"description":"The app space binding to service is taken: 7b959018-110a-4913-ac0a-d663e613cdea 346bf237-7eef-41a7-b892-68fb08068f09"
}`),
),
)
})
It("returns an error", func() {
err := repo.Create("my-service-instance-guid", "my-app-guid", nil)
Expect(err).To(HaveOccurred())
Expect(err.(errors.HTTPError).ErrorCode()).To(Equal("90003"))
})
})
})
Describe("Delete", func() {
var serviceInstance models.ServiceInstance
BeforeEach(func() {
serviceInstance.GUID = "my-service-instance-guid"
})
Context("when binding does exist", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("DELETE", "/v2/service_bindings/service-binding-2-guid"),
ghttp.RespondWith(http.StatusOK, nil),
),
)
serviceInstance.ServiceBindings = []models.ServiceBindingFields{