Add test for PsOutputToProcesses.
This commit is contained in:
parent
7fbc8ebc61
commit
c140ec6a7d
@ -1,7 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"jsh"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestPsOutputToProcesses(t *testing.T) {
|
func TestPsOutputToProcesses(t *testing.T) {
|
||||||
|
psOutput := `USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|
||||||
|
root 1 0.0 0.1 26204 4916 ? Ss 00:39 0:00 /sbin/init
|
||||||
|
root 2 0.0 0.0 0 0 ? S 00:39 0:00 [kthreadd]`
|
||||||
|
processes := PsOutputToProcesses(psOutput)
|
||||||
|
expected := []jsh.Process{jsh.Process{"root", "1", "0.0", "0.1", "26204",
|
||||||
|
"4916", "?", "Ss", "00:39", "0:00", "/sbin/init"},
|
||||||
|
jsh.Process{"root", "2", "0.0", "0.0", "0", "0", "?", "S", "00:39",
|
||||||
|
"0:00", "[kthreadd]"}}
|
||||||
|
actual := *processes
|
||||||
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
|
t.Errorf("Processes not parsed correctly.\n%s != %s", expected, actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user