Skip to content
Snippets Groups Projects
Commit daf17c8b authored by Josh Brooks's avatar Josh Brooks
Browse files

Modify testing functions for metric

parent 2d0e07fb
No related branches found
No related tags found
No related merge requests found
...@@ -206,7 +206,7 @@ func (h *Host) isExcludedMetricError(err string) bool { ...@@ -206,7 +206,7 @@ func (h *Host) isExcludedMetricError(err string) bool {
// Sets the host metrics to an arbitrary value. Used for testing // Sets the host metrics to an arbitrary value. Used for testing
// purposes only // 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 // Ensure that this function is only run in testing environments
switch face.(type) { switch face.(type) {
case *testing.T, *testing.M, *testing.B: case *testing.T, *testing.M, *testing.B:
...@@ -215,7 +215,7 @@ func (h *Host) SetMetricsTesting(errCounter uint64, face interface{}) { ...@@ -215,7 +215,7 @@ func (h *Host) SetMetricsTesting(errCounter uint64, face interface{}) {
panic("SetMetricsTesting() can only be used for testing.") panic("SetMetricsTesting() can only be used for testing.")
} }
h.metrics.errCounter = &errCounter h.metrics.errCounter = m
} }
......
...@@ -11,6 +11,7 @@ package connect ...@@ -11,6 +11,7 @@ package connect
import ( import (
"sync/atomic" "sync/atomic"
"testing"
) )
type Metric struct { type Metric struct {
...@@ -27,6 +28,22 @@ func newMetric() *Metric { ...@@ -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 // Getter for errCounter
func (m *Metric) GetErrorCounter() uint64 { func (m *Metric) GetErrorCounter() uint64 {
return atomic.LoadUint64(m.errCounter) return atomic.LoadUint64(m.errCounter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment