Skip to content

Commit 978af3b

Browse files
committed
Fixed ProcessWin
1 parent 5c292d0 commit 978af3b

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

inspector/process.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ func (i Process) createMetric(columns []string, pid int) ProcessMetrics {
120120

121121
func (i *ProcessWin) Parse(output string) {
122122
var values []ProcessMetricsWin
123-
lines := strings.Split(output, "\n")
123+
lines := strings.Split(output, "\r\n")
124124
for index, line := range lines {
125-
// skip title line
126-
if index == 0 {
125+
// skip title lines and ===== line
126+
if index == 0 || index == 1 || index == 2 {
127127
continue
128128
}
129129
columns := strings.Fields(line)
@@ -200,5 +200,6 @@ func NewProcess(driver *driver.Driver) Inspector {
200200
Command: `tasklist`,
201201
}
202202
}
203+
process.SetDriver(driver)
203204
return process
204205
}
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package integration
22

33
import (
4-
"fmt"
54
"testing"
65

76
"github.com/bisohns/saido/driver"
87
"github.com/bisohns/saido/inspector"
98
)
109

11-
func TestTasklistonLocal(t *testing.T) {
12-
d := driver.Local{}
13-
i := inspector.NewTasklist()
14-
output, err := d.RunCommand(i.String())
15-
if err != nil {
16-
t.Error(err)
17-
}
18-
i.Parse(output)
19-
if len(i.Values) <= 1 {
20-
t.Error("showing 1 or less tasks/processes")
10+
func NewLocalForTest() driver.Driver {
11+
return &driver.Local{}
12+
}
13+
14+
func TestProcessonLocal(t *testing.T) {
15+
d := NewLocalForTest()
16+
i := inspector.NewProcess(&d)
17+
i.Execute()
18+
iConcreteWin, ok := i.(*inspector.ProcessWin)
19+
if ok {
20+
if len(iConcreteWin.Values) <= 2 {
21+
t.Error("Less than two processes running")
22+
}
23+
if process := iConcreteWin.Values[0].Command; process != "System Idle Process" {
24+
t.Errorf("Expected System Idle Process as first process, found %s", iConcreteWin.Values[0].Command)
25+
}
2126
}
22-
fmt.Printf(`%#v`, i.Values)
2327
}

0 commit comments

Comments
 (0)