mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [system] keep the whole command name in GetProcessInfo (#426)
* fix(package): [system] keep the whole command name in GetProcessInfo * test(package): [system] cover a command name with spaces
This commit is contained in:
1 parent
1715d14cc8
commit
b4302b2d15
2 files changed
+20
-1
No files matched your search
+1
-1
@@ -252,7 +252,7 @@ func parseProcessInfo(output []byte, pid int) (*ProcessInfo, error) {
|
|||||||
Memory: fields[2],
|
Memory: fields[2],
|
||||||
State: fields[3],
|
State: fields[3],
|
||||||
User: fields[4],
|
User: fields[4],
|
||||||
Cmd: fields[5],
|
Cmd: strings.Join(fields[5:], " "),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package system
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -142,3 +143,21 @@ func TestGetProcessInfo(t *testing.T) {
|
|||||||
|
|
||||||
t.Log(processInfo)
|
t.Log(processInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseProcessInfo_commandWithSpaces(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("parses ps output")
|
||||||
|
}
|
||||||
|
|
||||||
|
assert := internal.NewAssert(t, "TestParseProcessInfo_commandWithSpaces")
|
||||||
|
|
||||||
|
output := []byte(" PID %CPU %MEM STAT USER COMM\n 4242 0.1 0.2 S root Google Chrome Helper\n")
|
||||||
|
|
||||||
|
info, err := parseProcessInfo(output, 4242)
|
||||||
|
assert.IsNil(err)
|
||||||
|
assert.Equal("Google Chrome Helper", info.Cmd)
|
||||||
|
assert.Equal("root", info.User)
|
||||||
|
assert.Equal("S", info.State)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user