Пример #1
0
func (s *metricsAdderSuite) TestAddMetricBatchesFails(c *gc.C) {
	var called bool
	metricsadder.PatchFacadeCall(s, s.adder, func(request string, args, response interface{}) error {
		_, ok := args.(params.MetricBatchParams)
		c.Assert(ok, jc.IsTrue)
		called = true
		c.Assert(request, gc.Equals, "AddMetricBatches")
		result := response.(*params.ErrorResults)
		result.Results = make([]params.ErrorResult, 1)
		result.Results[0].Error = common.ServerError(common.ErrPerm)
		return nil
	})

	batches := []params.MetricBatchParam{{
		Tag: names.NewUnitTag("test-unit/0").String(),
		Batch: params.MetricBatch{
			UUID:     utils.MustNewUUID().String(),
			CharmURL: "test-charm-url",
			Created:  time.Now(),
			Metrics:  []params.Metric{{Key: "pings", Value: "5", Time: time.Now().UTC()}},
		},
	}}

	results, err := s.adder.AddMetricBatches(batches)
	c.Assert(err, jc.ErrorIsNil)
	result, ok := results[batches[0].Batch.UUID]
	c.Assert(ok, jc.IsTrue)
	c.Assert(result.Error(), gc.Equals, "permission denied")
	c.Assert(called, jc.IsTrue)
}
Пример #2
0
func (s *metricsAdderSuite) TestAddMetricBatches(c *gc.C) {
	var called bool
	var callParams params.MetricBatchParams
	metricsadder.PatchFacadeCall(s, s.adder, func(request string, args, response interface{}) error {
		p, ok := args.(params.MetricBatchParams)
		c.Assert(ok, jc.IsTrue)
		callParams = p
		called = true
		c.Assert(request, gc.Equals, "AddMetricBatches")
		result := response.(*params.ErrorResults)
		result.Results = make([]params.ErrorResult, 1)
		return nil
	})

	batches := []params.MetricBatchParam{{
		Tag: names.NewUnitTag("test-unit/0").String(),
		Batch: params.MetricBatch{
			UUID:     utils.MustNewUUID().String(),
			CharmURL: "test-charm-url",
			Created:  time.Now(),
			Metrics:  []params.Metric{{Key: "pings", Value: "5", Time: time.Now().UTC()}},
		},
	}}

	_, err := s.adder.AddMetricBatches(batches)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
	c.Assert(callParams.Batches, gc.DeepEquals, batches)
}