作者:nota-j
项目:cl
func (cmd CreateQuota) Run(context *cli.Context) {
name := context.Args()[0]
cmd.ui.Say("Creating quota %s as %s...",
terminal.EntityNameColor(name),
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("Invalid memory limit: %s\n%s", memoryLimit, 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("Quota Definition %s already exists", quota.Name)
return
}
if err != nil {
cmd.ui.Failed(err.Error())
}
cmd.ui.Ok()
}
作者:knollear
项目:cl
BeforeEach(func() {
reqFactory.LoginSuccess = true
})
It("passes requirements when provided two args", func() {
callSetQuota([]string{"my-org", "my-quota"}, reqFactory, quotaRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
Expect(reqFactory.OrganizationName).To(Equal("my-org"))
})
It("TestSetQuota", func() {
org := models.Organization{}
org.Name = "my-org"
org.Guid = "my-org-guid"
quota := models.QuotaFields{}
quota.Name = "my-found-quota"
quota.Guid = "my-quota-guid"
quotaRepo.FindByNameQuota = quota
reqFactory.Organization = org
ui := callSetQuota([]string{"my-org", "my-quota"}, reqFactory, quotaRepo)
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Setting quota", "my-found-quota", "my-org", "my-user"},
{"OK"},
})
Expect(quotaRepo.FindByNameName).To(Equal("my-quota"))
Expect(quotaRepo.UpdateOrgGuid).To(Equal("my-org-guid"))
作者:normalnorma
项目:cl
Status: http.StatusOK,
Body: `{"resources": [
{
"metadata": { "guid": "my-quota-guid" },
"entity": { "name": "my-remote-quota", "memory_limit": 1024 }
}
]}`},
})
ts, handler, repo := createQuotaRepo(req)
defer ts.Close()
quota, apiResponse := repo.FindByName("my-quota")
Expect(handler.AllRequestsCalled()).To(BeTrue())
Expect(apiResponse.IsNotSuccessful()).To(BeFalse())
expectedQuota := models.QuotaFields{}
expectedQuota.Guid = "my-quota-guid"
expectedQuota.Name = "my-remote-quota"
expectedQuota.MemoryLimit = 1024
Expect(quota).To(Equal(expectedQuota))
})
})
Describe("Update", func() {
It("sets the quota for an organization", func() {
req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "PUT",
Path: "/v2/organizations/my-org-guid",
Matcher: testnet.RequestBodyMatcher(`{"quota_definition_guid":"my-quota-guid"}`),
Response: testnet.TestResponse{Status: http.StatusCreated},
作者:knollear
项目:cl
var _ = Describe("Testing with ginkgo", func() {
It("TestListQuotasRequirements", func() {
quotaRepo := &testapi.FakeQuotaRepository{}
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
callListQuotas(reqFactory, quotaRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeTrue())
reqFactory = &testreq.FakeReqFactory{LoginSuccess: false}
callListQuotas(reqFactory, quotaRepo)
Expect(testcmd.CommandDidPassRequirements).To(BeFalse())
})
It("TestListQuotas", func() {
quota := models.QuotaFields{}
quota.Name = "quota-name"
quota.MemoryLimit = 1024
quotaRepo := &testapi.FakeQuotaRepository{FindAllQuotas: []models.QuotaFields{quota}}
reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
ui := callListQuotas(reqFactory, quotaRepo)
testassert.SliceContains(ui.Outputs, testassert.Lines{
{"Getting quotas as", "my-user"},
{"OK"},
{"name", "memory limit"},
{"quota-name", "1g"},
})
})
})