github.com/google/cloudprober@v0.11.3/sysvars/runtime_test.go (about) 1 package sysvars 2 3 import ( 4 "runtime" 5 "testing" 6 "time" 7 8 "github.com/google/cloudprober/logger" 9 "github.com/google/cloudprober/metrics" 10 ) 11 12 func TestCounterRuntimeVars(t *testing.T) { 13 dataChan := make(chan *metrics.EventMetrics, 1) 14 l := &logger.Logger{} 15 m := &runtime.MemStats{} 16 runtime.ReadMemStats(m) 17 ts := time.Now() 18 19 counterRuntimeVars(dataChan, ts, m, l) 20 em := <-dataChan 21 22 if em.Timestamp != ts { 23 t.Errorf("em.Timestamp=%v, want=%v", em.Timestamp, ts) 24 } 25 26 if em.Kind != metrics.CUMULATIVE { 27 t.Errorf("Metrics kind is not cumulative.") 28 } 29 30 for _, name := range []string{"uptime_msec", "gc_time_msec", "mallocs", "frees"} { 31 if em.Metric(name) == nil { 32 t.Errorf("Expected metric \"%s\" not defined in EventMetrics: %s", name, em.String()) 33 } 34 } 35 } 36 37 func TestGaugeRuntimeVars(t *testing.T) { 38 dataChan := make(chan *metrics.EventMetrics, 1) 39 l := &logger.Logger{} 40 m := &runtime.MemStats{} 41 runtime.ReadMemStats(m) 42 ts := time.Now() 43 44 gaugeRuntimeVars(dataChan, ts, m, l) 45 em := <-dataChan 46 47 if em.Timestamp != ts { 48 t.Errorf("em.Timestamp=%v, want=%v", em.Timestamp, ts) 49 } 50 51 if em.Kind != metrics.GAUGE { 52 t.Errorf("Metrics kind is not gauge.") 53 } 54 55 for _, name := range []string{"goroutines", "mem_stats_sys_bytes"} { 56 if em.Metric(name) == nil { 57 t.Errorf("Expected metric \"%s\" not defined in EventMetrics: %s", name, em.String()) 58 } 59 } 60 }