gupta_test.go 910 B

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