gupta_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package gupta
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestHello(t *testing.T) {
  7. got := Hello()
  8. want := fmt.Sprintf("Welcome to gupta version %s", version)
  9. if got != want {
  10. t.Errorf("got %q want %q", got, want)
  11. }
  12. }
  13. func TestRunGupta(t *testing.T) {
  14. // test that we get CPU load
  15. got := make([]float64, 3)
  16. got[0], got[1], got[2] = Run(true, true, true, "", "")
  17. want := []float64{0.2, 0.2, 70.0}
  18. for i, v := range got {
  19. if v != want[i] {
  20. t.Errorf("got %v want %v", v, want[i])
  21. }
  22. }
  23. // here it makes sense to return some kind of data structure
  24. // with properties filled.
  25. // having a data structure it would be possible to format
  26. // it to json ...
  27. }
  28. func TestGuptaHasReport(t *testing.T) {
  29. // test we can get some report struct from gupta
  30. report := GuptaReport{
  31. cpuLoad: 0.2,
  32. cpuUsage: 0.2,
  33. memoryUsage: 70.0,
  34. }
  35. got := report.GetCPULoad()
  36. want := "0.20"
  37. if got != want {
  38. t.Errorf("got %v want %v", got, want)
  39. }
  40. }
  41. func TestGetCPULoad(t *testing.T) {
  42. cpuload := CPULoad{}
  43. cpuload.ReadInfo(make([]string, 3))
  44. if cpuload.user != 1 {
  45. t.Errorf("got %v want %v", cpuload.user, 1)
  46. }
  47. }