github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/runner/jujuc/testing/metrics.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "time" 8 9 "github.com/juju/errors" 10 11 "github.com/juju/juju/worker/uniter/runner/jujuc" 12 ) 13 14 // Metrics holds the values for the hook sub-context. 15 type Metrics struct { 16 Metrics []jujuc.Metric 17 } 18 19 // AddMetric adds a Metric for the provided data. 20 func (m *Metrics) AddMetric(key, value string, created time.Time) { 21 m.Metrics = append(m.Metrics, jujuc.Metric{ 22 Key: key, 23 Value: value, 24 Time: created, 25 }) 26 } 27 28 // ContextMetrics is a test double for jujuc.ContextMetrics. 29 type ContextMetrics struct { 30 contextBase 31 info *Metrics 32 } 33 34 // AddMetric implements jujuc.ContextMetrics. 35 func (c *ContextMetrics) AddMetric(key, value string, created time.Time) error { 36 c.stub.AddCall("AddMetric", key, value, created) 37 if err := c.stub.NextErr(); err != nil { 38 return errors.Trace(err) 39 } 40 41 c.info.AddMetric(key, value, created) 42 return nil 43 }