Parcourir la source

Add some basic function to test how the UI could work

Still not much, there is a lot more missing ..
Oz Tiram il y a 5 ans
Parent
commit
5a0051d908
2 fichiers modifiés avec 22 ajouts et 6 suppressions
  1. 5 6
      gupta.go
  2. 17 0
      gupta_test.go

+ 5 - 6
gupta.go

@@ -1,13 +1,12 @@
 package gupta
 
-import (
-	"fmt"
-)
-
 func Hello() string {
 	return "Hello, world"
 }
 
-func main() {
-	fmt.Println(Hello())
+func Run(load, cpu, memory bool, partition, networkInterface string) (cpuLoad, cpuUsage, memoryUsage float64) {
+	cpuLoad = 0.2
+	cpuUsage = 0.2
+	memoryUsage = 70.0
+	return cpuLoad, cpuUsage, memoryUsage
 }

+ 17 - 0
gupta_test.go

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