本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/models.QuotaFields類的典型用法代碼示例。如果您正苦於以下問題:Golang QuotaFields類的具體用法?Golang QuotaFields怎麽用?Golang QuotaFields使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QuotaFields類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (cmd CreateQuota) Run(context *cli.Context) {
name := context.Args()[0]
cmd.ui.Say(cmd.T("Creating quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.QuotaFields{
Name: name,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, err := formatters.ToMegabytes(memoryLimit)
if err != nil {
cmd.ui.Failed(cmd.T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": err}))
}
quota.MemoryLimit = parsedMemory
}
if context.IsSet("r") {
quota.RoutesLimit = context.Int("r")
}
if context.IsSet("s") {
quota.ServicesLimit = context.Int("s")
}
if context.IsSet("allow-paid-service-plans") {
quota.NonBasicServicesAllowed = true
}
err := cmd.quotaRepo.Create(quota)
httpErr, ok := err.(errors.HttpError)
if ok && httpErr.ErrorCode() == errors.QUOTA_EXISTS {
cmd.ui.Ok()
cmd.ui.Warn(cmd.T("Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
示例2:
})
})
Context("when the user is logged in", func() {
BeforeEach(func() {
requirementsFactory.LoginSuccess = true
})
It("fails requirements when called without a quota name", func() {
runCommand()
Expect(ui.FailedWithUsage).To(BeTrue())
})
Context("When the quota provided exists", func() {
BeforeEach(func() {
quota := models.QuotaFields{}
quota.Name = "my-quota"
quota.Guid = "my-quota-guid"
quotaRepo.FindByNameReturns.Quota = quota
})
It("deletes a quota with a given name when the user confirms", func() {
ui.Inputs = []string{"y"}
runCommand("my-quota")
Expect(quotaRepo.DeleteCalledWith.Guid).To(Equal("my-quota-guid"))
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Really delete the quota", "my-quota"},
))
示例3:
testcmd "github.com/cloudfoundry/cli/testhelpers/commands"
testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
. "github.com/cloudfoundry/cli/testhelpers/matchers"
testreq "github.com/cloudfoundry/cli/testhelpers/requirements"
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
"github.com/cloudfoundry/cli/cf/models"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("app Command", func() {
var (
ui *testterm.FakeUI
requirementsFactory *testreq.FakeReqFactory
quotaRepo *fakes.FakeQuotaRepository
quota models.QuotaFields
configRepo core_config.Repository
deps command_registry.Dependency
)
updateCommandDependency := func(pluginCall bool) {
deps.Ui = ui
deps.Config = configRepo
deps.RepoLocator = deps.RepoLocator.SetQuotaRepository(quotaRepo)
command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("update-quota").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
configRepo = testconfig.NewRepositoryWithDefaults()
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
示例4:
Context("when the user is logged in", func() {
BeforeEach(func() {
requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
})
It("fails requirements when called without a quota name", func() {
runCommand()
Expect(ui.Outputs()).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires an argument"},
))
})
Context("When the quota provided exists", func() {
BeforeEach(func() {
quota := models.QuotaFields{}
quota.Name = "my-quota"
quota.GUID = "my-quota-guid"
quotaRepo.FindByNameReturns(quota, nil)
})
It("deletes a quota with a given name when the user confirms", func() {
ui.Inputs = []string{"y"}
runCommand("my-quota")
Expect(quotaRepo.DeleteArgsForCall(0)).To(Equal("my-quota-guid"))
Expect(ui.Prompts).To(ContainSubstrings(
[]string{"Really delete the quota", "my-quota"},
))
示例5: Execute
func (cmd *CreateQuota) Execute(context flags.FlagContext) error {
name := context.Args()[0]
cmd.ui.Say(T("Creating quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{
"QuotaName": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username()),
}))
quota := models.QuotaFields{
Name: name,
}
memoryLimit := context.String("m")
if memoryLimit != "" {
parsedMemory, err := formatters.ToMegabytes(memoryLimit)
if err != nil {
return errors.New(T("Invalid memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": memoryLimit, "Err": err}))
}
quota.MemoryLimit = parsedMemory
}
instanceMemoryLimit := context.String("i")
if instanceMemoryLimit == "-1" || instanceMemoryLimit == "" {
quota.InstanceMemoryLimit = -1
} else {
parsedMemory, errr := formatters.ToMegabytes(instanceMemoryLimit)
if errr != nil {
return errors.New(T("Invalid instance memory limit: {{.MemoryLimit}}\n{{.Err}}", map[string]interface{}{"MemoryLimit": instanceMemoryLimit, "Err": errr}))
}
quota.InstanceMemoryLimit = parsedMemory
}
if context.IsSet("r") {
quota.RoutesLimit = context.Int("r")
}
if context.IsSet("s") {
quota.ServicesLimit = context.Int("s")
}
if context.IsSet("a") {
quota.AppInstanceLimit = context.Int("a")
} else {
quota.AppInstanceLimit = resources.UnlimitedAppInstances
}
if context.IsSet("allow-paid-service-plans") {
quota.NonBasicServicesAllowed = true
}
if context.IsSet("reserved-route-ports") {
quota.ReservedRoutePorts = json.Number(context.String("reserved-route-ports"))
}
err := cmd.quotaRepo.Create(quota)
httpErr, ok := err.(errors.HTTPError)
if ok && httpErr.ErrorCode() == errors.QuotaDefinitionNameTaken {
cmd.ui.Ok()
cmd.ui.Warn(T("Quota Definition {{.QuotaName}} already exists", map[string]interface{}{"QuotaName": quota.Name}))
return nil
}
if err != nil {
return err
}
cmd.ui.Ok()
return nil
}