當前位置: 首頁>>代碼示例>>Golang>>正文


Golang uniter.PatchUnitResponse函數代碼示例

本文整理匯總了Golang中github.com/juju/juju/api/uniter.PatchUnitResponse函數的典型用法代碼示例。如果您正苦於以下問題:Golang PatchUnitResponse函數的具體用法?Golang PatchUnitResponse怎麽用?Golang PatchUnitResponse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PatchUnitResponse函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSendMetricBatchFail

func (s *unitMetricBatchesSuite) TestSendMetricBatchFail(c *gc.C) {
	var called bool
	uniter.PatchUnitResponse(s, s.apiUnit, "AddMetricBatches",
		func(response interface{}) error {
			called = true
			result := response.(*params.ErrorResults)
			result.Results = make([]params.ErrorResult, 1)
			result.Results[0].Error = common.ServerError(common.ErrPerm)
			return nil
		})
	metrics := []params.Metric{{"pings", "5", time.Now().UTC()}}
	uuid := utils.MustNewUUID().String()
	batch := params.MetricBatch{
		UUID:     uuid,
		CharmURL: s.charm.URL().String(),
		Created:  time.Now(),
		Metrics:  metrics,
	}

	results, err := s.apiUnit.AddMetricBatches([]params.MetricBatch{batch})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(results, gc.HasLen, 1)
	c.Assert(results[batch.UUID], gc.ErrorMatches, "permission denied")
	c.Assert(called, jc.IsTrue)
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:25,代碼來源:unit_test.go

示例2: TestWatchActionNotificationsNoResults

func (s *unitSuite) TestWatchActionNotificationsNoResults(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "WatchActionNotifications",
		func(results interface{}) error {
			return nil
		},
	)

	_, err := s.apiUnit.WatchActionNotifications()
	c.Assert(err.Error(), gc.Equals, "expected 1 result, got 0")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:10,代碼來源:unit_test.go

示例3: TestWatchActionNotificationsError

func (s *unitSuite) TestWatchActionNotificationsError(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "WatchActionNotifications",
		func(result interface{}) error {
			return fmt.Errorf("Test error")
		},
	)

	_, err := s.apiUnit.WatchActionNotifications()
	c.Assert(err.Error(), gc.Equals, "Test error")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:10,代碼來源:unit_test.go

示例4: TestWatchActionsNoResults

func (s *unitSuite) TestWatchActionsNoResults(c *gc.C) {
	cleanup := uniter.PatchUnitResponse(s.apiUnit,
		func(results interface{}) error {
			return nil
		},
	)
	defer cleanup()

	_, err := s.apiUnit.WatchActions()
	c.Assert(err.Error(), gc.Equals, "expected 1 result, got 0")
}
開發者ID:kapilt,項目名稱:juju,代碼行數:11,代碼來源:unit_test.go

示例5: TestWatchActionsError

func (s *unitSuite) TestWatchActionsError(c *gc.C) {
	cleanup := uniter.PatchUnitResponse(s.apiUnit,
		func(result interface{}) error {
			return fmt.Errorf("Test error")
		},
	)
	defer cleanup()

	_, err := s.apiUnit.WatchActions()
	c.Assert(err.Error(), gc.Equals, "Test error")
}
開發者ID:kapilt,項目名稱:juju,代碼行數:11,代碼來源:unit_test.go

示例6: TestAddMetricsError

func (s *unitSuite) TestAddMetricsError(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "AddMetrics",
		func(results interface{}) error {
			result := results.(*params.ErrorResults)
			result.Results = make([]params.ErrorResult, 1)
			return fmt.Errorf("test error")
		},
	)
	metrics := []params.Metric{{"A", "23", time.Now()}, {"B", "27.0", time.Now()}}
	err := s.apiUnit.AddMetrics(metrics)
	c.Assert(err, gc.ErrorMatches, "unable to add metric: test error")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:12,代碼來源:unit_test.go

示例7: TestAddMetrics

func (s *unitSuite) TestAddMetrics(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "AddMetrics",
		func(results interface{}) error {
			result := results.(*params.ErrorResults)
			result.Results = make([]params.ErrorResult, 1)
			return nil
		},
	)
	metrics := []params.Metric{{"A", "23", time.Now()}, {"B", "27.0", time.Now()}}
	err := s.apiUnit.AddMetrics(metrics)
	c.Assert(err, jc.ErrorIsNil)
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:12,代碼來源:unit_test.go

示例8: TestMeterStatusError

func (s *unitSuite) TestMeterStatusError(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "GetMeterStatus",
		func(results interface{}) error {
			result := results.(*params.MeterStatusResults)
			result.Results = make([]params.MeterStatusResult, 1)
			return fmt.Errorf("boo")
		},
	)
	statusCode, statusInfo, err := s.apiUnit.MeterStatus()
	c.Assert(err, gc.ErrorMatches, "boo")
	c.Assert(statusCode, gc.Equals, "")
	c.Assert(statusInfo, gc.Equals, "")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:13,代碼來源:unit_test.go

示例9: TestWatchActionNotificationsMoreResults

func (s *unitSuite) TestWatchActionNotificationsMoreResults(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "WatchActionNotifications",
		func(results interface{}) error {
			if results, ok := results.(*params.StringsWatchResults); ok {
				results.Results = make([]params.StringsWatchResult, 2)
			}
			return nil
		},
	)

	_, err := s.apiUnit.WatchActionNotifications()
	c.Assert(err.Error(), gc.Equals, "expected 1 result, got 2")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:13,代碼來源:unit_test.go

示例10: TestMeterStatus

func (s *unitSuite) TestMeterStatus(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "GetMeterStatus",
		func(results interface{}) error {
			result := results.(*params.MeterStatusResults)
			result.Results = make([]params.MeterStatusResult, 1)
			result.Results[0].Code = "GREEN"
			result.Results[0].Info = "All ok."
			return nil
		},
	)
	statusCode, statusInfo, err := s.apiUnit.MeterStatus()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(statusCode, gc.Equals, "GREEN")
	c.Assert(statusInfo, gc.Equals, "All ok.")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:15,代碼來源:unit_test.go

示例11: TestAddMetricsResultError

func (s *unitSuite) TestAddMetricsResultError(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "AddMetrics",
		func(results interface{}) error {
			result := results.(*params.ErrorResults)
			result.Results = make([]params.ErrorResult, 1)
			result.Results[0].Error = &params.Error{
				Message: "error adding metrics",
				Code:    params.CodeNotAssigned,
			}
			return nil
		},
	)
	metrics := []params.Metric{{"A", "23", time.Now()}, {"B", "27.0", time.Now()}}
	err := s.apiUnit.AddMetrics(metrics)
	c.Assert(err, gc.ErrorMatches, "error adding metrics")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:16,代碼來源:unit_test.go

示例12: TestMeterStatusResultError

func (s *unitSuite) TestMeterStatusResultError(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "GetMeterStatus",
		func(results interface{}) error {
			result := results.(*params.MeterStatusResults)
			result.Results = make([]params.MeterStatusResult, 1)
			result.Results[0].Error = &params.Error{
				Message: "error getting meter status",
				Code:    params.CodeNotAssigned,
			}
			return nil
		},
	)
	statusCode, statusInfo, err := s.apiUnit.MeterStatus()
	c.Assert(err, gc.ErrorMatches, "error getting meter status")
	c.Assert(statusCode, gc.Equals, "")
	c.Assert(statusInfo, gc.Equals, "")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:17,代碼來源:unit_test.go

示例13: TestAvailabilityZone

func (s *unitSuite) TestAvailabilityZone(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "AvailabilityZone",
		func(result interface{}) error {
			if results, ok := result.(*params.StringResults); ok {
				results.Results = []params.StringResult{{
					Result: "a-zone",
				}}
			}
			return nil
		},
	)

	zone, err := s.apiUnit.AvailabilityZone()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(zone, gc.Equals, "a-zone")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:17,代碼來源:unit_test.go

示例14: TestWatchActionNotificationsErrorResults

func (s *unitSuite) TestWatchActionNotificationsErrorResults(c *gc.C) {
	uniter.PatchUnitResponse(s, s.apiUnit, "WatchActionNotifications",
		func(results interface{}) error {
			if results, ok := results.(*params.StringsWatchResults); ok {
				results.Results = make([]params.StringsWatchResult, 1)
				results.Results[0] = params.StringsWatchResult{
					Error: &params.Error{
						Message: "An error in the watch result.",
						Code:    params.CodeNotAssigned,
					},
				}
			}
			return nil
		},
	)

	_, err := s.apiUnit.WatchActionNotifications()
	c.Assert(err.Error(), gc.Equals, "An error in the watch result.")
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:19,代碼來源:unit_test.go


注:本文中的github.com/juju/juju/api/uniter.PatchUnitResponse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。