diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-08-17 17:19:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-17 17:19:06 -0700 |
commit | 96eab1202717e073782ec399a4e0820cae15b1bb (patch) | |
tree | 011012982be971c7e9ef91466f026bc0956ac9a2 /vendor/github.com/armon/go-metrics/sink_test.go | |
parent | 2c895ee66eed626721135acfcc48254c6e3f3b29 (diff) | |
download | chat-96eab1202717e073782ec399a4e0820cae15b1bb.tar.gz chat-96eab1202717e073782ec399a4e0820cae15b1bb.tar.bz2 chat-96eab1202717e073782ec399a4e0820cae15b1bb.zip |
Updating server dependancies. (#7246)
Diffstat (limited to 'vendor/github.com/armon/go-metrics/sink_test.go')
-rw-r--r-- | vendor/github.com/armon/go-metrics/sink_test.go | 108 |
1 files changed, 106 insertions, 2 deletions
diff --git a/vendor/github.com/armon/go-metrics/sink_test.go b/vendor/github.com/armon/go-metrics/sink_test.go index 77c5c3278..714f99b81 100644 --- a/vendor/github.com/armon/go-metrics/sink_test.go +++ b/vendor/github.com/armon/go-metrics/sink_test.go @@ -7,25 +7,39 @@ import ( ) type MockSink struct { - keys [][]string - vals []float32 + keys [][]string + vals []float32 + labels [][]Label } func (m *MockSink) SetGauge(key []string, val float32) { + m.SetGaugeWithLabels(key, val, nil) +} +func (m *MockSink) SetGaugeWithLabels(key []string, val float32, labels []Label) { m.keys = append(m.keys, key) m.vals = append(m.vals, val) + m.labels = append(m.labels, labels) } func (m *MockSink) EmitKey(key []string, val float32) { m.keys = append(m.keys, key) m.vals = append(m.vals, val) + m.labels = append(m.labels, nil) } func (m *MockSink) IncrCounter(key []string, val float32) { + m.IncrCounterWithLabels(key, val, nil) +} +func (m *MockSink) IncrCounterWithLabels(key []string, val float32, labels []Label) { m.keys = append(m.keys, key) m.vals = append(m.vals, val) + m.labels = append(m.labels, labels) } func (m *MockSink) AddSample(key []string, val float32) { + m.AddSampleWithLabels(key, val, nil) +} +func (m *MockSink) AddSampleWithLabels(key []string, val float32, labels []Label) { m.keys = append(m.keys, key) m.vals = append(m.vals, val) + m.labels = append(m.labels, labels) } func TestFanoutSink_Gauge(t *testing.T) { @@ -51,6 +65,36 @@ func TestFanoutSink_Gauge(t *testing.T) { } } +func TestFanoutSink_Gauge_Labels(t *testing.T) { + m1 := &MockSink{} + m2 := &MockSink{} + fh := &FanoutSink{m1, m2} + + k := []string{"test"} + v := float32(42.0) + l := []Label{{"a", "b"}} + fh.SetGaugeWithLabels(k, v, l) + + if !reflect.DeepEqual(m1.keys[0], k) { + t.Fatalf("key not equal") + } + if !reflect.DeepEqual(m2.keys[0], k) { + t.Fatalf("key not equal") + } + if !reflect.DeepEqual(m1.vals[0], v) { + t.Fatalf("val not equal") + } + if !reflect.DeepEqual(m2.vals[0], v) { + t.Fatalf("val not equal") + } + if !reflect.DeepEqual(m1.labels[0], l) { + t.Fatalf("labels not equal") + } + if !reflect.DeepEqual(m2.labels[0], l) { + t.Fatalf("labels not equal") + } +} + func TestFanoutSink_Key(t *testing.T) { m1 := &MockSink{} m2 := &MockSink{} @@ -97,6 +141,36 @@ func TestFanoutSink_Counter(t *testing.T) { } } +func TestFanoutSink_Counter_Labels(t *testing.T) { + m1 := &MockSink{} + m2 := &MockSink{} + fh := &FanoutSink{m1, m2} + + k := []string{"test"} + v := float32(42.0) + l := []Label{{"a", "b"}} + fh.IncrCounterWithLabels(k, v, l) + + if !reflect.DeepEqual(m1.keys[0], k) { + t.Fatalf("key not equal") + } + if !reflect.DeepEqual(m2.keys[0], k) { + t.Fatalf("key not equal") + } + if !reflect.DeepEqual(m1.vals[0], v) { + t.Fatalf("val not equal") + } + if !reflect.DeepEqual(m2.vals[0], v) { + t.Fatalf("val not equal") + } + if !reflect.DeepEqual(m1.labels[0], l) { + t.Fatalf("labels not equal") + } + if !reflect.DeepEqual(m2.labels[0], l) { + t.Fatalf("labels not equal") + } +} + func TestFanoutSink_Sample(t *testing.T) { m1 := &MockSink{} m2 := &MockSink{} @@ -120,6 +194,36 @@ func TestFanoutSink_Sample(t *testing.T) { } } +func TestFanoutSink_Sample_Labels(t *testing.T) { + m1 := &MockSink{} + m2 := &MockSink{} + fh := &FanoutSink{m1, m2} + + k := []string{"test"} + v := float32(42.0) + l := []Label{{"a", "b"}} + fh.AddSampleWithLabels(k, v, l) + + if !reflect.DeepEqual(m1.keys[0], k) { + t.Fatalf("key not equal") + } + if !reflect.DeepEqual(m2.keys[0], k) { + t.Fatalf("key not equal") + } + if !reflect.DeepEqual(m1.vals[0], v) { + t.Fatalf("val not equal") + } + if !reflect.DeepEqual(m2.vals[0], v) { + t.Fatalf("val not equal") + } + if !reflect.DeepEqual(m1.labels[0], l) { + t.Fatalf("labels not equal") + } + if !reflect.DeepEqual(m2.labels[0], l) { + t.Fatalf("labels not equal") + } +} + func TestNewMetricSinkFromURL(t *testing.T) { for _, tc := range []struct { desc string |