From 9400939fec85653834c7f80d6e96c57d02b41d9c Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 30 Aug 2022 12:14:33 -0600 Subject: [PATCH] change verify gauge and sample test function to only take in a string --- memberlist_test.go | 2 +- state_test.go | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/memberlist_test.go b/memberlist_test.go index b47266687..3d8cf92d1 100644 --- a/memberlist_test.go +++ b/memberlist_test.go @@ -260,7 +260,7 @@ func TestCreate_checkBroadcastQueueMetrics(t *testing.T) { time.Sleep(3 * time.Second) sampleName := "consul.usage.test.memberlist.queue.broadcasts" - verifySamplesExists(t, []string{sampleName}, sink) + verifySampleExists(t, sampleName, sink) } func TestCreate_keyringOnly(t *testing.T) { diff --git a/state_test.go b/state_test.go index 93126e6c6..7816a96bf 100644 --- a/state_test.go +++ b/state_test.go @@ -2274,12 +2274,11 @@ func TestMemberlist_PushPull(t *testing.T) { } instancesMetricName := "consul.usage.test.memberlist.node.instances" - verifyGaugesExists(t, []string{"consul.usage.test.memberlist.size.local", - fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateAlive), - fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateDead), - fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateLeft), - fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateSuspect)}, - sink) + verifyGaugeExists(t, "consul.usage.test.memberlist.size.local", sink) + verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateAlive), sink) + verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateDead), sink) + verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateLeft), sink) + verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateSuspect), sink) }) } @@ -2423,24 +2422,21 @@ func getIntervalMetrics(t *testing.T, sink *metrics.InmemSink) *metrics.Interval return intv } -func verifyGaugesExists(t *testing.T, names []string, sink *metrics.InmemSink) { +func verifyGaugeExists(t *testing.T, name string, sink *metrics.InmemSink) { interval := getIntervalMetrics(t, sink) interval.RLock() defer interval.RUnlock() - for _, name := range names { - if _, ok := interval.Gauges[name]; !ok { - t.Fatalf("%s gauge not emmited", name) - } + if _, ok := interval.Gauges[name]; !ok { + t.Fatalf("%s gauge not emmited", name) } } -func verifySamplesExists(t *testing.T, names []string, sink *metrics.InmemSink) { +func verifySampleExists(t *testing.T, name string, sink *metrics.InmemSink) { interval := getIntervalMetrics(t, sink) interval.RLock() defer interval.RUnlock() - for _, name := range names { - if _, ok := interval.Samples[name]; !ok { - t.Fatalf("%s sample not emmited", name) - } + + if _, ok := interval.Samples[name]; !ok { + t.Fatalf("%s sample not emmited", name) } }