package gupta import ( "fmt" "testing" ) func TestHello(t *testing.T) { got := Hello() want := fmt.Sprintf("Welcome to gupta version %s", version) if got != want { t.Errorf("got %q want %q", got, want) } } func TestRunGupta(t *testing.T) { // test that we get CPU load got := make([]float64, 3) got[0], got[1], got[2] = Run(true, true, true, "", "") want := []float64{0.2, 0.2, 70.0} for i, v := range got { if v != want[i] { t.Errorf("got %v want %v", v, want[i]) } } // here it makes sense to return some kind of data structure // with properties filled. // having a data structure it would be possible to format // it to json ... } func TestGuptaHasReport(t *testing.T) { // test we can get some report struct from gupta report := GuptaReport{ cpuLoad: 0.2, cpuUsage: 0.2, memoryUsage: 70.0, } got := report.GetCPULoad() want := "0.20" if got != want { t.Errorf("got %v want %v", got, want) } } func TestGetCPULoad(t *testing.T) { cpuload := CPULoad{} cpuload.ReadInfo([]string{"1234", "5678", "9101112"}) if cpuload.user != 1234 { t.Errorf("got %v want %v", cpuload.user, 1234) } }