From c140ec6a7dd1e0717a844c2fbe557065fc178d87 Mon Sep 17 00:00:00 2001 From: Ian Adam Naval Date: Thu, 4 Sep 2014 02:45:09 -0400 Subject: [PATCH] Add test for PsOutputToProcesses. --- ps/main_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ps/main_test.go b/ps/main_test.go index a2b92b7..003cd8c 100644 --- a/ps/main_test.go +++ b/ps/main_test.go @@ -1,7 +1,22 @@ package main -import "testing" +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) + } }