Robin Thellend | fa70aaa | 2014-10-09 17:13:05 -0700 | [diff] [blame] | 1 | package sysstats_test |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | |
Jiri Simsa | 764efb7 | 2014-12-25 20:57:03 -0800 | [diff] [blame] | 7 | "v.io/core/veyron/lib/stats" |
| 8 | _ "v.io/core/veyron/lib/stats/sysstats" |
Robin Thellend | fa70aaa | 2014-10-09 17:13:05 -0700 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | func TestHostname(t *testing.T) { |
| 12 | obj, err := stats.GetStatsObject("system/hostname") |
| 13 | if err != nil { |
| 14 | t.Fatalf("unexpected error: %v", err) |
| 15 | } |
| 16 | expected, err := os.Hostname() |
| 17 | if err != nil { |
| 18 | t.Fatalf("unexpected error: %v", err) |
| 19 | } |
| 20 | if got := obj.Value(); got != expected { |
| 21 | t.Errorf("unexpected result. Got %q, want %q", got, expected) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func TestMemStats(t *testing.T) { |
| 26 | alloc, err := stats.GetStatsObject("system/memstats/Alloc") |
| 27 | if err != nil { |
| 28 | t.Fatalf("unexpected error: %v", err) |
| 29 | } |
| 30 | if v := alloc.Value(); v == uint64(0) { |
| 31 | t.Errorf("unexpected Alloc value. Got %v, want != 0", v) |
| 32 | } |
| 33 | } |
Robert Kroeger | 4692e29 | 2015-01-28 14:50:21 -0800 | [diff] [blame] | 34 | |
| 35 | func TestPid(t *testing.T) { |
| 36 | obj, err := stats.GetStatsObject("system/pid") |
| 37 | if err != nil { |
| 38 | t.Fatalf("unexpected error: %v", err) |
| 39 | } |
| 40 | expected := int64(os.Getpid()) |
| 41 | if got := obj.Value(); got != expected { |
| 42 | t.Errorf("unexpected result. Got %q, want %q", got, expected) |
| 43 | } |
| 44 | } |