Browse Source

Refactor: make user field private again

Oz Tiram 5 years ago
parent
commit
b67ee27ede
2 changed files with 8 additions and 8 deletions
  1. 3 3
      gupta.go
  2. 5 5
      gupta_test.go

+ 3 - 3
gupta.go

@@ -31,7 +31,7 @@ func (g *GuptaReport) GetCPULoad() string {
 
 // collect all CPU stat from /proc/cpustat
 type CPUStat struct {
-	User       uint64
+	user       uint64
 	nice       uint64
 	system     uint64
 	idle       uint64
@@ -46,7 +46,7 @@ type CPUStat struct {
 // parse the first line of /proc/cpustat
 func (c *CPUStat) ReadInfo(rawInfo []string) {
 	if s, err := strconv.ParseUint(rawInfo[0], 10, 64); err == nil {
-		c.User = s
+		c.user = s
 	}
 	if s, err := strconv.ParseUint(rawInfo[1], 10, 64); err == nil {
 		c.nice = s
@@ -78,7 +78,7 @@ func (c *CPUStat) ReadInfo(rawInfo []string) {
 }
 
 func (c *CPUStat) TotalTime() uint64 {
-	return c.User + c.nice + c.system + c.idle + c.iowait + c.irq + c.softirq + c.steal
+	return c.user + c.nice + c.system + c.idle + c.iowait + c.irq + c.softirq + c.steal
 }
 
 func NewCPUStat(procstatline string) CPUStat {

+ 5 - 5
gupta_test.go

@@ -61,8 +61,8 @@ func TestGetCPUUsage(t *testing.T) {
 		"0",
 		"0",
 		"0"})
-	if cpustat.User != 4705 {
-		t.Errorf("Got cpustat.User %v want %v", cpustat.User, 4705)
+	if cpustat.user != 4705 {
+		t.Errorf("Got cpustat.user %v want %v", cpustat.user, 4705)
 	}
 }
 
@@ -72,8 +72,8 @@ func TestNewCPUUsage(t *testing.T) {
 	procstatLine := "cpu 4705 356  584    3699   23    23     0       0     0    0"
 	cpustat := NewCPUStat(procstatLine)
 
-	if cpustat.User != 4705 {
-		t.Errorf("got %v want %v", cpustat.User, 4705)
+	if cpustat.user != 4705 {
+		t.Errorf("got %v want %v", cpustat.user, 4705)
 	}
 }
 
@@ -82,7 +82,7 @@ func TestTotalCPUTime(t *testing.T) {
 	cpustat := NewCPUStat(procstatLine)
 
 	got := cpustat.TotalTime()
-	want := cpustat.User + cpustat.nice + cpustat.system + cpustat.idle + cpustat.iowait +
+	want := cpustat.user + cpustat.nice + cpustat.system + cpustat.idle + cpustat.iowait +
 		cpustat.irq + cpustat.softirq + cpustat.steal
 
 	if got != want {