2021-01-22 18:21:40 +03:00
|
|
|
package meter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNoopMeter(t *testing.T) {
|
|
|
|
meter := NewMeter(Path("/noop"))
|
|
|
|
assert.NotNil(t, meter)
|
|
|
|
assert.Equal(t, "/noop", meter.Options().Path)
|
|
|
|
assert.Implements(t, new(Meter), meter)
|
2021-01-27 00:54:19 +03:00
|
|
|
|
|
|
|
cnt := meter.Counter("counter", Label("server", "noop"))
|
|
|
|
cnt.Inc()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLabels(t *testing.T) {
|
|
|
|
var ls Labels
|
|
|
|
ls.keys = []string{"type", "server"}
|
|
|
|
ls.vals = []string{"noop", "http"}
|
|
|
|
|
|
|
|
ls.Sort()
|
|
|
|
|
|
|
|
if ls.keys[0] != "server" || ls.vals[0] != "http" {
|
|
|
|
t.Fatalf("sort error: %v", ls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLabelsAppend(t *testing.T) {
|
|
|
|
var ls Labels
|
|
|
|
ls.keys = []string{"type", "server"}
|
|
|
|
ls.vals = []string{"noop", "http"}
|
|
|
|
|
|
|
|
var nls Labels
|
2021-01-29 13:17:32 +03:00
|
|
|
nls.keys = []string{"register"}
|
2021-01-27 00:54:19 +03:00
|
|
|
nls.vals = []string{"gossip"}
|
|
|
|
ls = ls.Append(nls)
|
|
|
|
|
|
|
|
ls.Sort()
|
|
|
|
|
2021-01-29 13:17:32 +03:00
|
|
|
if ls.keys[0] != "register" || ls.vals[0] != "gossip" {
|
2021-01-27 00:54:19 +03:00
|
|
|
t.Fatalf("append error: %v", ls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIterator(t *testing.T) {
|
|
|
|
var ls Labels
|
2021-01-29 13:17:32 +03:00
|
|
|
ls.keys = []string{"type", "server", "register"}
|
2021-01-27 00:54:19 +03:00
|
|
|
ls.vals = []string{"noop", "http", "gossip"}
|
|
|
|
|
|
|
|
iter := ls.Iter()
|
|
|
|
var k, v string
|
|
|
|
cnt := 0
|
|
|
|
for iter.Next(&k, &v) {
|
|
|
|
if cnt == 1 && (k != "server" || v != "http") {
|
|
|
|
t.Fatalf("iter error: %s != %s || %s != %s", k, "server", v, "http")
|
|
|
|
}
|
|
|
|
cnt++
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|