Browse Source

Add test for PsOutputToProcesses.

Ian Adam Naval 5 years ago
parent
commit
c140ec6a7d
1 changed files with 17 additions and 2 deletions
  1. 17
    2
      ps/main_test.go

+ 17
- 2
ps/main_test.go View File

@@ -1,7 +1,22 @@
1 1
 package main
2 2
 
3
-import "testing"
3
+import (
4
+	"jsh"
5
+	"reflect"
6
+	"testing"
7
+)
4 8
 
5 9
 func TestPsOutputToProcesses(t *testing.T) {
6
-
10
+	psOutput := `USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
11
+root         1  0.0  0.1  26204  4916 ?        Ss   00:39   0:00 /sbin/init
12
+root         2  0.0  0.0      0     0 ?        S    00:39   0:00 [kthreadd]`
13
+	processes := PsOutputToProcesses(psOutput)
14
+	expected := []jsh.Process{jsh.Process{"root", "1", "0.0", "0.1", "26204",
15
+		"4916", "?", "Ss", "00:39", "0:00", "/sbin/init"},
16
+		jsh.Process{"root", "2", "0.0", "0.0", "0", "0", "?", "S", "00:39",
17
+			"0:00", "[kthreadd]"}}
18
+	actual := *processes
19
+	if !reflect.DeepEqual(expected, actual) {
20
+		t.Errorf("Processes not parsed correctly.\n%s != %s", expected, actual)
21
+	}
7 22
 }

Loading…
Cancel
Save