Skip to content

Commit

Permalink
Fixed ProcessWin
Browse files Browse the repository at this point in the history
  • Loading branch information
deven96 committed Mar 16, 2022
1 parent 5c292d0 commit 978af3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
7 changes: 4 additions & 3 deletions inspector/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ func (i Process) createMetric(columns []string, pid int) ProcessMetrics {

func (i *ProcessWin) Parse(output string) {
var values []ProcessMetricsWin
lines := strings.Split(output, "\n")
lines := strings.Split(output, "\r\n")
for index, line := range lines {
// skip title line
if index == 0 {
// skip title lines and ===== line
if index == 0 || index == 1 || index == 2 {
continue
}
columns := strings.Fields(line)
Expand Down Expand Up @@ -200,5 +200,6 @@ func NewProcess(driver *driver.Driver) Inspector {
Command: `tasklist`,
}
}
process.SetDriver(driver)
return process
}
28 changes: 16 additions & 12 deletions integration/integration_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package integration

import (
"fmt"
"testing"

"github.com/bisohns/saido/driver"
"github.com/bisohns/saido/inspector"
)

func TestTasklistonLocal(t *testing.T) {
d := driver.Local{}
i := inspector.NewTasklist()
output, err := d.RunCommand(i.String())
if err != nil {
t.Error(err)
}
i.Parse(output)
if len(i.Values) <= 1 {
t.Error("showing 1 or less tasks/processes")
func NewLocalForTest() driver.Driver {
return &driver.Local{}
}

func TestProcessonLocal(t *testing.T) {
d := NewLocalForTest()
i := inspector.NewProcess(&d)
i.Execute()
iConcreteWin, ok := i.(*inspector.ProcessWin)
if ok {
if len(iConcreteWin.Values) <= 2 {
t.Error("Less than two processes running")
}
if process := iConcreteWin.Values[0].Command; process != "System Idle Process" {
t.Errorf("Expected System Idle Process as first process, found %s", iConcreteWin.Values[0].Command)
}
}
fmt.Printf(`%#v`, i.Values)
}

0 comments on commit 978af3b

Please sign in to comment.