當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。