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


Golang budget.NewClient函数代码示例

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


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

示例1: TestSetBudget

func (t *TSuite) TestSetBudget(c *gc.C) {
	expected := "Budget updated successfully"
	respBody, err := json.Marshal(expected)
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusOK,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.SetBudget("personal", "200")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(response, gc.Equals, expected)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"PATCH",
				"application/json+patch",
				"https://api.jujucharms.com/omnibus/v2/budget/personal",
				map[string]interface{}{
					"update": map[string]interface{}{
						"limit": "200",
					},
				},
			}}})
}
开发者ID:cherylj,项目名称:romulus,代码行数:25,代码来源:api_test.go

示例2: TestUpdateAllocation

func (t *TSuite) TestUpdateAllocation(c *gc.C) {
	expected := "Allocation updated."
	respBody, err := json.Marshal(expected)
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusOK,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.UpdateAllocation("model-uuid", "db", "200")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(response, gc.Equals, expected)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"PATCH",
				"application/json+patch",
				"https://api.jujucharms.com/omnibus/v2/model/model-uuid/service/db/allocation",
				map[string]interface{}{
					"update": map[string]interface{}{
						"limit": "200",
					},
				},
			}}})
}
开发者ID:cherylj,项目名称:romulus,代码行数:25,代码来源:api_test.go

示例3: TestCreateAllocation

func (t *TSuite) TestCreateAllocation(c *gc.C) {
	expected := "Allocation created successfully"
	respBody, err := json.Marshal(expected)
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusOK,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.CreateAllocation("personal", "200", "model", []string{"db"})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(response, gc.Equals, expected)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"POST",
				"application/json",
				"https://api.jujucharms.com/omnibus/v2/budget/personal/allocation",
				map[string]interface{}{
					"limit":    "200",
					"model":    "model",
					"services": []interface{}{"db"},
				},
			}}})
}
开发者ID:cherylj,项目名称:romulus,代码行数:25,代码来源:api_test.go

示例4: newAPIClient

func (c *updateAllocationCommand) newAPIClient(bakery *httpbakery.Client) (apiClient, error) {
	if c.api != nil {
		return c.api, nil
	}
	c.api = api.NewClient(bakery)
	return c.api, nil
}
开发者ID:alesstimec,项目名称:romulus-1,代码行数:7,代码来源:updateallocation.go

示例5: TestListBudgets

func (t *TSuite) TestListBudgets(c *gc.C) {
	expected := &wireformat.ListBudgetsResponse{
		Budgets: wireformat.BudgetSummaries{
			wireformat.BudgetSummary{
				Owner:       "bob",
				Budget:      "personal",
				Limit:       "50",
				Allocated:   "30",
				Unallocated: "20",
				Available:   "45",
				Consumed:    "5",
			},
			wireformat.BudgetSummary{
				Owner:       "bob",
				Budget:      "work",
				Limit:       "200",
				Allocated:   "100",
				Unallocated: "100",
				Available:   "150",
				Consumed:    "50",
			},
			wireformat.BudgetSummary{
				Owner:       "bob",
				Budget:      "team",
				Limit:       "50",
				Allocated:   "10",
				Unallocated: "40",
				Available:   "40",
				Consumed:    "10",
			},
		},
		Total: wireformat.BudgetTotals{
			Limit:       "300",
			Allocated:   "140",
			Available:   "235",
			Unallocated: "160",
			Consumed:    "65",
		},
		Credit: "400",
	}
	respBody, err := json.Marshal(expected)
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusOK,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.ListBudgets()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(response, gc.DeepEquals, expected)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"GET",
				"",
				"https://api.jujucharms.com/omnibus/v2/budget",
				map[string]interface{}{},
			}}})
}
开发者ID:cherylj,项目名称:romulus,代码行数:59,代码来源:api_test.go

示例6: TestGetBudget

func (t *TSuite) TestGetBudget(c *gc.C) {
	expected := &wireformat.BudgetWithAllocations{
		Limit: "4000.00",
		Total: wireformat.BudgetTotals{
			Allocated:   "2200.00",
			Unallocated: "1800.00",
			Available:   "1100,00",
			Consumed:    "1100.0",
			Usage:       "50%",
		},
		Allocations: []wireformat.Allocation{{
			Owner:    "user.joe",
			Limit:    "1200.00",
			Consumed: "500.00",
			Usage:    "42%",
			Model:    "model.joe",
			Services: map[string]wireformat.ServiceAllocation{
				"wordpress": wireformat.ServiceAllocation{
					Consumed: "300.00",
				},
				"mysql": wireformat.ServiceAllocation{
					Consumed: "200.00",
				},
			},
		}, {
			Owner:    "user.jess",
			Limit:    "1000.00",
			Consumed: "600.00",
			Usage:    "60%",
			Model:    "model.jess",
			Services: map[string]wireformat.ServiceAllocation{
				"landscape": wireformat.ServiceAllocation{
					Consumed: "600.00",
				},
			},
		},
		},
	}
	respBody, err := json.Marshal(expected)
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusOK,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.GetBudget("personal")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(response, gc.DeepEquals, expected)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"GET",
				"",
				"https://api.jujucharms.com/omnibus/v2/budget/personal",
				map[string]interface{}{},
			}}})
}
开发者ID:cherylj,项目名称:romulus,代码行数:57,代码来源:api_test.go

示例7: TestDeleteAllocationRequestError

func (t *TSuite) TestDeleteAllocationRequestError(c *gc.C) {
	httpClient := &mockClient{
		RespCode: http.StatusBadRequest,
	}
	httpClient.SetErrors(errors.New("bogus error"))
	client := budget.NewClient(httpClient)
	response, err := client.DeleteAllocation("model", "db")
	c.Assert(err, gc.ErrorMatches, ".*bogus error")
	c.Assert(response, gc.Equals, "")
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"DELETE",
				"https://api.jujucharms.com/omnibus/v2/environment/model/service/db/allocation",
				map[string]interface{}{},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:17,代码来源:api_test.go

示例8: TestGetBudgetRequestError

func (t *TSuite) TestGetBudgetRequestError(c *gc.C) {
	httpClient := &mockClient{
		RespCode: http.StatusBadRequest,
	}
	httpClient.SetErrors(errors.New("bogus error"))
	client := budget.NewClient(httpClient)
	response, err := client.GetBudget("personal")
	c.Assert(err, gc.ErrorMatches, ".*bogus error")
	c.Assert(response, gc.IsNil)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"GET",
				"https://api.jujucharms.com/omnibus/v2/budget/personal",
				map[string]interface{}{},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:17,代码来源:api_test.go

示例9: TestListBudgetsServerError

func (t *TSuite) TestListBudgetsServerError(c *gc.C) {
	respBody, err := json.Marshal("budget already exists")
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusBadRequest,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.ListBudgets()
	c.Assert(err, gc.ErrorMatches, "400: budget already exists")
	c.Assert(response, gc.IsNil)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"GET",
				"https://api.jujucharms.com/omnibus/v2/budget",
				map[string]interface{}{},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:19,代码来源:api_test.go

示例10: TestCreateBudgetUnavail

func (t *TSuite) TestCreateBudgetUnavail(c *gc.C) {
	httpClient := &mockClient{
		RespCode: http.StatusServiceUnavailable,
	}
	client := budget.NewClient(httpClient)
	response, err := client.CreateBudget("personal", "200")
	c.Assert(wireformat.IsNotAvail(err), jc.IsTrue)
	c.Assert(response, gc.Equals, "")
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"POST",
				"https://api.jujucharms.com/omnibus/v2/budget",
				map[string]interface{}{
					"limit":  "200",
					"budget": "personal",
				},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:19,代码来源:api_test.go

示例11: TestDeleteAllocationServerError

func (t *TSuite) TestDeleteAllocationServerError(c *gc.C) {
	respBody, err := json.Marshal("cannot delete allocation")
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusBadRequest,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.DeleteAllocation("model", "db")
	c.Assert(err, gc.ErrorMatches, "400: cannot delete allocation")
	c.Assert(response, gc.Equals, "")
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"DELETE",
				"https://api.jujucharms.com/omnibus/v2/environment/model/service/db/allocation",
				map[string]interface{}{},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:19,代码来源:api_test.go

示例12: TestGetBudgetServerError

func (t *TSuite) TestGetBudgetServerError(c *gc.C) {
	respBody, err := json.Marshal("budget not found")
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusNotFound,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.GetBudget("personal")
	c.Assert(err, gc.ErrorMatches, "404: budget not found")
	c.Assert(response, gc.IsNil)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"GET",
				"https://api.jujucharms.com/omnibus/v2/budget/personal",
				map[string]interface{}{},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:19,代码来源:api_test.go

示例13: TestDeleteAllocation

func (t *TSuite) TestDeleteAllocation(c *gc.C) {
	expected := "Allocation deleted."
	respBody, err := json.Marshal(expected)
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusOK,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.DeleteAllocation("model", "db")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(response, gc.Equals, expected)
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"DELETE",
				"https://api.jujucharms.com/omnibus/v2/environment/model/service/db/allocation",
				map[string]interface{}{},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:20,代码来源:api_test.go

示例14: TestSetBudgetServerError

func (t *TSuite) TestSetBudgetServerError(c *gc.C) {
	respBody, err := json.Marshal("cannot update budget")
	c.Assert(err, jc.ErrorIsNil)
	httpClient := &mockClient{
		RespCode: http.StatusBadRequest,
		RespBody: respBody,
	}
	client := budget.NewClient(httpClient)
	response, err := client.SetBudget("personal", "200")
	c.Assert(err, gc.ErrorMatches, "400: cannot update budget")
	c.Assert(response, gc.Equals, "")
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"PUT",
				"https://api.jujucharms.com/omnibus/v2/budget/personal",
				map[string]interface{}{
					"limit": "200",
				},
			}}})
}
开发者ID:wallyworld,项目名称:romulus,代码行数:21,代码来源:api_test.go

示例15: TestCreateBudgetConnRefused

func (t *TSuite) TestCreateBudgetConnRefused(c *gc.C) {
	httpClient := &mockClient{
		RespCode: http.StatusOK,
	}
	httpClient.SetErrors(errors.New("Connection refused"))
	client := budget.NewClient(httpClient)
	response, err := client.CreateBudget("personal", "200")
	c.Assert(wireformat.IsNotAvail(err), jc.IsTrue)
	c.Assert(response, gc.Equals, "")
	httpClient.CheckCalls(c,
		[]jujutesting.StubCall{{
			"DoWithBody",
			[]interface{}{"POST",
				"application/json",
				"https://api.jujucharms.com/omnibus/v2/budget",
				map[string]interface{}{
					"limit":  "200",
					"budget": "personal",
				},
			}}})
}
开发者ID:cherylj,项目名称:romulus,代码行数:21,代码来源:api_test.go


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