Exemple #1
0
// TestAvailability tests that the charmdir resource is properly checked.
func (s *ManifoldSuite) TestAvailability(c *gc.C) {
	recorder := &dummyRecorder{
		charmURL:         "cs:wordpress-37",
		unitTag:          "wp/0",
		isDeclaredMetric: true,
	}
	s.PatchValue(collect.NewRecorder,
		func(_ names.UnitTag, _ context.Paths, _ spool.MetricFactory) (spool.MetricRecorder, error) {
			return recorder, nil
		})
	s.PatchValue(collect.ReadCharm,
		func(_ names.UnitTag, _ context.Paths) (*corecharm.URL, map[string]corecharm.Metric, error) {
			return corecharm.MustParseURL("cs:wordpress-37"), map[string]corecharm.Metric{"pings": corecharm.Metric{Description: "test metric", Type: corecharm.MetricTypeAbsolute}}, nil
		})
	charmdir := &dummyCharmdir{aborted: true}
	s.resources["charmdir-name"] = dt.StubResource{Output: charmdir}
	collectEntity, err := collect.NewCollect(s.manifoldConfig, s.resources.Context())
	c.Assert(err, jc.ErrorIsNil)
	err = collectEntity.Do(nil)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(recorder.batches, gc.HasLen, 0)

	charmdir = &dummyCharmdir{aborted: false}
	s.resources["charmdir-name"] = dt.StubResource{Output: charmdir}
	collectEntity, err = collect.NewCollect(s.manifoldConfig, s.resources.Context())
	c.Assert(err, jc.ErrorIsNil)
	err = collectEntity.Do(nil)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(recorder.closed, jc.IsTrue)
	c.Assert(recorder.batches, gc.HasLen, 1)
}
Exemple #2
0
// TestJujuUnitsBuiltinMetric tests that the juju-units built-in metric is collected
// with a mock implementation of newRecorder.
func (s *ManifoldSuite) TestJujuUnitsBuiltinMetric(c *gc.C) {
	recorder := &dummyRecorder{
		charmURL:         "cs:wordpress-37",
		unitTag:          "wp/0",
		isDeclaredMetric: true,
	}
	s.PatchValue(collect.NewRecorder,
		func(_ names.UnitTag, _ context.Paths, _ spool.MetricFactory) (spool.MetricRecorder, error) {
			return recorder, nil
		})
	s.PatchValue(collect.ReadCharm,
		func(_ names.UnitTag, _ context.Paths) (*corecharm.URL, map[string]corecharm.Metric, error) {
			return corecharm.MustParseURL("cs:wordpress-37"), map[string]corecharm.Metric{"pings": corecharm.Metric{Description: "test metric", Type: corecharm.MetricTypeAbsolute}}, nil
		})
	collectEntity, err := collect.NewCollect(s.manifoldConfig, s.resources.Context())
	c.Assert(err, jc.ErrorIsNil)
	err = collectEntity.Do(nil)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(recorder.closed, jc.IsTrue)
	c.Assert(recorder.batches, gc.HasLen, 1)
	c.Assert(recorder.batches[0].CharmURL, gc.Equals, "cs:wordpress-37")
	c.Assert(recorder.batches[0].UnitTag, gc.Equals, "wp/0")
	c.Assert(recorder.batches[0].Metrics, gc.HasLen, 1)
	c.Assert(recorder.batches[0].Metrics[0].Key, gc.Equals, "juju-units")
	c.Assert(recorder.batches[0].Metrics[0].Value, gc.Equals, "1")
}
Exemple #3
0
// TestNoMetricsDeclared tests that if metrics are not declared, none are
// collected, not even builtin.
func (s *ManifoldSuite) TestNoMetricsDeclared(c *gc.C) {
	recorder := &dummyRecorder{
		charmURL:         "cs:wordpress-37",
		unitTag:          "wp/0",
		isDeclaredMetric: false,
	}
	s.PatchValue(collect.NewRecorder,
		func(_ names.UnitTag, _ context.Paths, _ spool.MetricFactory) (spool.MetricRecorder, error) {
			return recorder, nil
		})
	s.PatchValue(collect.ReadCharm,
		func(_ names.UnitTag, _ context.Paths) (*corecharm.URL, map[string]corecharm.Metric, error) {
			return corecharm.MustParseURL("cs:wordpress-37"), map[string]corecharm.Metric{}, nil
		})
	collectEntity, err := collect.NewCollect(s.manifoldConfig, s.resources.Context())
	c.Assert(err, jc.ErrorIsNil)
	err = collectEntity.Do(nil)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(recorder.closed, jc.IsTrue)
	c.Assert(recorder.batches, gc.HasLen, 0)
}