2021-01-22 18:21:40 +03:00
|
|
|
package meter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNoopMeter(t *testing.T) {
|
2021-02-18 15:57:42 +03:00
|
|
|
m := NewMeter(Path("/noop"))
|
|
|
|
if "/noop" != m.Options().Path {
|
|
|
|
t.Fatalf("invalid options parsing: %v", m.Options())
|
2021-02-13 15:35:56 +03:00
|
|
|
}
|
2021-01-27 00:54:19 +03:00
|
|
|
|
2021-02-18 15:57:42 +03:00
|
|
|
cnt := m.Counter("counter", Label("server", "noop"))
|
2021-01-27 00:54:19 +03:00
|
|
|
cnt.Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-02-14 16:16:01 +03:00
|
|
|
//ls.Sort()
|
2021-01-27 00:54:19 +03:00
|
|
|
|
2021-02-14 16:16:01 +03:00
|
|
|
if ls.keys[0] != "type" || ls.vals[0] != "noop" {
|
2021-01-27 00:54:19 +03:00
|
|
|
t.Fatalf("append error: %v", ls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIterator(t *testing.T) {
|
2021-02-18 15:57:42 +03:00
|
|
|
options := NewOptions(
|
|
|
|
Label("name", "svc1"),
|
|
|
|
Label("version", "0.0.1"),
|
|
|
|
Label("id", "12345"),
|
|
|
|
Label("type", "noop"),
|
|
|
|
Label("server", "http"),
|
|
|
|
Label("register", "gossip"),
|
|
|
|
Label("aa", "kk"),
|
|
|
|
Label("zz", "kk"),
|
|
|
|
)
|
|
|
|
|
|
|
|
iter := options.Labels.Iter()
|
2021-01-27 00:54:19 +03:00
|
|
|
var k, v string
|
|
|
|
cnt := 0
|
|
|
|
for iter.Next(&k, &v) {
|
2021-02-18 15:57:42 +03:00
|
|
|
if cnt == 4 && (k != "server" || v != "http") {
|
2021-01-27 00:54:19 +03:00
|
|
|
t.Fatalf("iter error: %s != %s || %s != %s", k, "server", v, "http")
|
|
|
|
}
|
|
|
|
cnt++
|
|
|
|
}
|
2021-01-22 18:21:40 +03:00
|
|
|
}
|