func TestFindQuotaByName(t *testing.T) { req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{ Method: "GET", Path: "/v2/quota_definitions?q=name%3Amy-quota", Response: testnet.TestResponse{ Status: http.StatusOK, Body: `{"resources": [ { "metadata": { "guid": "my-quota-guid" }, "entity": { "name": "my-remote-quota", "memory_limit": 1024 } } ]}`}, }) ts, handler, repo := createQuotaRepo(t, req) defer ts.Close() quota, apiResponse := repo.FindByName("my-quota") assert.True(t, handler.AllRequestsCalled()) assert.False(t, apiResponse.IsNotSuccessful()) expectedQuota := cf.QuotaFields{} expectedQuota.Guid = "my-quota-guid" expectedQuota.Name = "my-remote-quota" expectedQuota.MemoryLimit = 1024 assert.Equal(t, quota, expectedQuota) }
func TestListQuotas(t *testing.T) { quota := cf.QuotaFields{} quota.Name = "quota-name" quota.MemoryLimit = 1024 quotaRepo := &testapi.FakeQuotaRepository{FindAllQuotas: []cf.QuotaFields{quota}} reqFactory := &testreq.FakeReqFactory{LoginSuccess: true} ui := callListQuotas(t, reqFactory, quotaRepo) testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Getting quotas as", "my-user"}, {"OK"}, {"name", "memory limit"}, {"quota-name", "1g"}, }) }
func TestSetQuota(t *testing.T) { org := cf.Organization{} org.Name = "my-org" org.Guid = "my-org-guid" quota := cf.QuotaFields{} quota.Name = "my-found-quota" quota.Guid = "my-quota-guid" quotaRepo := &testapi.FakeQuotaRepository{FindByNameQuota: quota} reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org} ui := callSetQuota(t, []string{"my-org", "my-quota"}, reqFactory, quotaRepo) assert.Equal(t, quotaRepo.FindByNameName, "my-quota") testassert.SliceContains(t, ui.Outputs, testassert.Lines{ {"Setting quota", "my-found-quota", "my-org", "my-user"}, {"OK"}, }) assert.Equal(t, quotaRepo.UpdateOrgGuid, "my-org-guid") assert.Equal(t, quotaRepo.UpdateQuotaGuid, "my-quota-guid") }