23 lines
752 B
Go
23 lines
752 B
Go
package main
|
|
|
|
import (
|
|
"jsh"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|