Example #1
0
func quotaByOwner(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
	result := map[string]interface{}{}
	owner := r.URL.Query().Get(":owner")
	items, available, err := quota.Items(owner)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	result["items"] = items
	result["available"] = available
	return json.NewEncoder(w).Encode(result)
}
Example #2
0
func (s *S) TestReserveUnitsToAddBackwardNoPointer(c *gocheck.C) {
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	err := quota.Create(app.Name, 5)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(app.Name)
	ids := []string{"visions-0", "visions-1", "visions-2", "visions-3"}
	err = quota.Reserve(app.Name, ids...)
	c.Assert(err, gocheck.IsNil)
	reserveUnitsToAdd.Backward(action.BWContext{Params: []interface{}{app, 3}, FWResult: ids})
	items, avail, err := quota.Items(app.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(avail, gocheck.Equals, uint(5))
	c.Assert(items, gocheck.HasLen, 0)
}
Example #3
0
func (QuotaSuite) TestChangeQuota(c *gocheck.C) {
	err := quota.Create("*****@*****.**", 3)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete("*****@*****.**")
	recorder := httptest.NewRecorder()
	request, err := http.NewRequest("PUT", "/quota/[email protected]?:[email protected]", strings.NewReader("quota=1"))
	c.Assert(err, gocheck.IsNil)
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	err = changeQuota(recorder, request, nil)
	c.Assert(err, gocheck.IsNil)
	_, qtd, err := quota.Items("*****@*****.**")
	c.Assert(err, gocheck.IsNil)
	c.Assert(int(qtd), gocheck.Equals, 1)
	c.Assert(recorder.Code, gocheck.Equals, http.StatusOK)
	body, err := ioutil.ReadAll(recorder.Body)
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(body), gocheck.Equals, "Quota changed sucessfully.")
}
Example #4
0
func (s *S) TestReserveUnitsToAddForwardNoPointer(c *gocheck.C) {
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	s.conn.Apps().Insert(app)
	defer s.conn.Apps().Remove(bson.M{"name": app.Name})
	err := quota.Create(app.Name, 5)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete(app.Name)
	result, err := reserveUnitsToAdd.Forward(action.FWContext{Params: []interface{}{app, 3}})
	c.Assert(err, gocheck.IsNil)
	ids, ok := result.([]string)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(ids, gocheck.DeepEquals, []string{"visions-0", "visions-1", "visions-2"})
	items, avail, err := quota.Items(app.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(avail, gocheck.Equals, uint(2))
	c.Assert(items, gocheck.DeepEquals, []string{"visions-0", "visions-1", "visions-2"})
}
Example #5
0
func (s *S) TestCreateAppQuotaForward(c *gocheck.C) {
	config.Set("quota:units-per-app", 2)
	defer config.Unset("quota:units-per-app")
	app := App{
		Name:     "visions",
		Platform: "django",
	}
	defer quota.Delete(app.Name)
	previous, err := createAppQuota.Forward(action.FWContext{Params: []interface{}{app}})
	c.Assert(err, gocheck.IsNil)
	c.Assert(previous, gocheck.Equals, app.Name)
	items, available, err := quota.Items(app.Name)
	c.Assert(err, gocheck.IsNil)
	c.Assert(items, gocheck.DeepEquals, []string{"visions-0"})
	c.Assert(available, gocheck.Equals, uint(1))
	err = quota.Reserve(app.Name, "visions-1")
	c.Assert(err, gocheck.IsNil)
	err = quota.Reserve(app.Name, "visions-2")
	_, ok := err.(*quota.QuotaExceededError)
	c.Assert(ok, gocheck.Equals, true)
}