From daf17c8b6b47033a78c1cde6e57805c17e4c4b49 Mon Sep 17 00:00:00 2001
From: josh <josh@elixxir.io>
Date: Wed, 31 Mar 2021 08:39:42 -0700
Subject: [PATCH] Modify testing functions for metric

---
 connect/host.go    |  4 ++--
 connect/metrics.go | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/connect/host.go b/connect/host.go
index 584335d..15be3d3 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 5da6906..efd4469 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)
-- 
GitLab