influxdb/stats_test.go

89 lines
1.8 KiB
Go
Raw Normal View History

package influxdb_test
import (
"testing"
"github.com/influxdb/influxdb"
)
func TestStats_SetAndGet(t *testing.T) {
s := influxdb.NewStats("foo")
s.Set("a", 100)
if s.Get("a") != 100 {
t.Fatalf("stats set failed, expected 100, got %d", s.Get("a"))
}
}
func TestStats_Add(t *testing.T) {
s := influxdb.NewStats("foo")
s.Add("a", 200)
if s.Get("a") != 200 {
t.Fatalf("stats set failed, expected 200, got %d", s.Get("a"))
}
}
2015-03-13 05:16:30 +00:00
func TestStats_Inc(t *testing.T) {
2015-03-13 22:43:19 +00:00
s := influxdb.NewStats("foo")
2015-03-13 05:16:30 +00:00
s.Set("a", 100)
s.Inc("a")
if s.Get("a") != 101 {
t.Fatalf("stats Inc failed, expected 101, got %d", s.Get("a"))
}
s.Inc("b")
if s.Get("b") != 1 {
t.Fatalf("stats Inc failed, expected 1, got %d", s.Get("b"))
}
}
func TestStats_AddNegative(t *testing.T) {
s := influxdb.NewStats("foo")
s.Add("a", -200)
if s.Get("a") != -200 {
t.Fatalf("stats set failed, expected -200, got %d", s.Get("a"))
}
}
func TestStats_SetAndAdd(t *testing.T) {
s := influxdb.NewStats("foo")
s.Set("a", 100)
s.Add("a", 200)
if s.Get("a") != 300 {
t.Fatalf("stats set failed, expected 300, got %d", s.Get("a"))
}
}
func TestStats_Diff(t *testing.T) {
foo := influxdb.NewStats("server")
bar := influxdb.NewStats("server")
foo.Set("a", 100)
foo.Set("b", 600)
bar.Set("a", 450)
bar.Set("b", 525)
qux := bar.Diff(foo)
if qux.Name() != "server" {
t.Fatalf("stats diff has unexpected name: %s", qux.Name())
}
if qux.Get("a") != 350 || qux.Get("b") != -75 {
2015-03-13 22:51:14 +00:00
t.Fatalf("stats diff returned unexpected result: %v", qux)
2015-03-13 22:01:53 +00:00
}
}
func TestStats_Snapshot(t *testing.T) {
foo := influxdb.NewStats("server")
foo.Set("a", 100)
foo.Set("b", 600)
bar := foo.Snapshot()
if bar.Name() != "server" || bar.Get("a") != 100 || bar.Get("b") != 600 {
2015-03-16 14:57:21 +00:00
t.Fatalf("stats snapshot returned unexpected result: %#v", bar)
}
}