Browse Source

Add some basic reporting

Information that will be queried from the OS will be saved in
a sturct. This struct will be gradually added methods to get the OS
parameters.
Oz Tiram 5 years ago
parent
commit
b5c08d6d04
2 changed files with 31 additions and 0 deletions
  1. 14 0
      gupta.go
  2. 17 0
      gupta_test.go

+ 14 - 0
gupta.go

@@ -1,5 +1,9 @@
 package gupta
 
+import (
+	"fmt"
+)
+
 func Hello() string {
 	return "Hello, world"
 }
@@ -10,3 +14,13 @@ func Run(load, cpu, memory bool, partition, networkInterface string) (cpuLoad, c
 	memoryUsage = 70.0
 	return cpuLoad, cpuUsage, memoryUsage
 }
+
+type GuptaReport struct {
+	cpuLoad     float64
+	cpuUsage    float64
+	memoryUsage float64
+}
+
+func (g *GuptaReport) GetCPULoad() string {
+	return fmt.Sprintf("%.2f", g.cpuLoad)
+}

+ 17 - 0
gupta_test.go

@@ -29,3 +29,20 @@ func TestRunGupta(t *testing.T) {
 	// 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)
+	}
+
+}