当前位置: 首页>>代码示例>>Golang>>正文


Golang quota.Items函数代码示例

本文整理汇总了Golang中github.com/globocom/tsuru/quota.Items函数的典型用法代码示例。如果您正苦于以下问题:Golang Items函数的具体用法?Golang Items怎么用?Golang Items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Items函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: quotaByOwner

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)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:11,代码来源:quota.go

示例2: TestReserveUnitsToAddBackwardNoPointer

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)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:17,代码来源:actions_test.go

示例3: TestChangeQuota

func (QuotaSuite) TestChangeQuota(c *gocheck.C) {
	err := quota.Create("[email protected]", 3)
	c.Assert(err, gocheck.IsNil)
	defer quota.Delete("[email protected]")
	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("[email protected]")
	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.")
}
开发者ID:nemx,项目名称:tsuru,代码行数:18,代码来源:quota_test.go

示例4: TestReserveUnitsToAddForwardNoPointer

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"})
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:20,代码来源:actions_test.go

示例5: TestCreateAppQuotaForward

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)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:21,代码来源:actions_test.go


注:本文中的github.com/globocom/tsuru/quota.Items函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。