diff --git a/connect/host.go b/connect/host.go index 584335de2839e9f3fbb75e2cc6a0c5703c167ad1..15be3d32593551825ba5f0a955cffbdf89b2222c 100644 --- a/connect/host.go +++ b/connect/host.go @@ -206,7 +206,7 @@ func (h *Host) isExcludedMetricError(err string) bool { // Sets the host metrics to an arbitrary value. Used for testing // purposes only -func (h *Host) SetMetricsTesting(errCounter uint64, face interface{}) { +func (h *Host) SetMetricsTesting(m *Metric, face interface{}) { // Ensure that this function is only run in testing environments switch face.(type) { case *testing.T, *testing.M, *testing.B: @@ -215,7 +215,7 @@ func (h *Host) SetMetricsTesting(errCounter uint64, face interface{}) { panic("SetMetricsTesting() can only be used for testing.") } - h.metrics.errCounter = &errCounter + h.metrics.errCounter = m } diff --git a/connect/metrics.go b/connect/metrics.go index 5da69067ce6c721185ea7a8c3e780909b81b86eb..efd4469bbef3ca45dbe206eb23e5ecaadae575fd 100644 --- a/connect/metrics.go +++ b/connect/metrics.go @@ -11,6 +11,7 @@ package connect import ( "sync/atomic" + "testing" ) type Metric struct { @@ -27,6 +28,22 @@ func newMetric() *Metric { } } +// Creates a metrics object with specified values. Used for testing +// purposes only +func NewMetricTesting(errCounter uint64, face interface{}) *Metric { + // Ensure that this function is only run in testing environments + switch face.(type) { + case *testing.T, *testing.M, *testing.B: + break + default: + panic("SetMetricsTesting() can only be used for testing.") + } + + return &Metric{ + errCounter: &errCounter, + } +} + // Getter for errCounter func (m *Metric) GetErrorCounter() uint64 { return atomic.LoadUint64(m.errCounter)