1
0
mirror of https://github.com/divan/expvarmon.git synced 2025-04-27 13:48:55 +08:00
expvarmon/expvars_test.go

74 lines
1.6 KiB
Go
Raw Normal View History

2015-04-21 12:51:01 +03:00
package main
import (
"os"
"testing"
)
2015-04-25 15:54:17 +03:00
const (
expvarsTestFile = "./expvars.json"
expvarsAdvTestFile = "./expvars_advanced.json"
)
2015-04-21 12:51:01 +03:00
func TestExpvars(t *testing.T) {
file, err := os.Open(expvarsTestFile)
if err != nil {
t.Fatalf("cannot open test file %v", err)
}
defer file.Close()
2015-05-01 16:49:19 +03:00
expvar, err := ParseExpvar(file)
if err != nil {
t.Fatal(err)
}
2015-05-01 14:37:28 +03:00
2015-05-01 16:49:19 +03:00
cmdline, err := expvar.GetStringArray("cmdline")
if err != nil {
t.Fatal(err)
}
if len(cmdline) != 3 {
t.Fatalf("Cmdline should have 3 items, but has %d", len(cmdline))
}
2015-05-01 18:48:34 +03:00
alloc, err := expvar.GetInt64(VarName("memstats.Alloc").ToSlice()...)
2015-05-01 16:49:19 +03:00
if err != nil {
t.Fatal(err)
}
if alloc == 0 {
t.Fatalf("Alloc should be greater than 0")
}
2015-04-21 12:51:01 +03:00
}
2015-04-25 15:54:17 +03:00
func TestExpvarsAdvanced(t *testing.T) {
file, err := os.Open(expvarsAdvTestFile)
if err != nil {
t.Fatalf("cannot open test file %v", err)
}
defer file.Close()
2015-05-01 14:37:28 +03:00
/*
vars, err := ParseExpvar(file)
if err != nil {
t.Fatal(err)
}
if len(vars.Extra) != 2 {
t.Fatalf("Got:", vars)
t.Fatalf("vars should have 2 items, but has %d", len(vars.Extra))
}
if int(vars.Extra["goroutines"].(float64)) != 10 {
t.Logf("Expecting 'goroutines' to be %d, but got %d", 10, vars.Extra["goroutines"])
}
counters := vars.Extra["counters"].(map[string]interface{})
counterA := counters["A"].(float64)
counterB := counters["B"].(float64)
if counterA != 123.12 {
t.Logf("Expecting 'counter.A' to be %f, but got %f", 123.12, counterA)
}
if int(counterB) != 245342 {
t.Logf("Expecting 'counter.B' to be %d, but got %d", 245342, counterB)
}
*/
2015-04-25 15:54:17 +03:00
}