mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-12 08:42:29 +08:00
feat: add StartProcess, StopProcess, KillProcess for system package
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -53,7 +54,9 @@ func TestExecCommand(t *testing.T) {
|
||||
assert := internal.NewAssert(t, "TestExecCommand")
|
||||
|
||||
// linux or mac
|
||||
stdout, stderr, err := ExecCommand("ls")
|
||||
stdout, stderr, err := ExecCommand("ls", func(cmd *exec.Cmd) {
|
||||
cmd.Dir = "/"
|
||||
})
|
||||
t.Log("std out: ", stdout)
|
||||
t.Log("std err: ", stderr)
|
||||
assert.Equal("", stderr)
|
||||
@@ -74,16 +77,6 @@ func TestExecCommand(t *testing.T) {
|
||||
assert.IsNotNil(err)
|
||||
}
|
||||
|
||||
// func TestExecCommandWithOption(t *testing.T) {
|
||||
// assert := internal.NewAssert(t, "TestExecCommandWithOption")
|
||||
|
||||
// stdout, stderr, err := ExecCommand("ls", WithForeground())
|
||||
// t.Log("std out: ", stdout)
|
||||
// t.Log("std err: ", stderr)
|
||||
// assert.Equal("", stderr)
|
||||
// assert.IsNil(err)
|
||||
// }
|
||||
|
||||
func TestGetOsBits(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -95,3 +88,40 @@ func TestGetOsBits(t *testing.T) {
|
||||
t.Error("os is not 32 or 64 bits")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStartProcess(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := internal.NewAssert(t, "TestStartProcess")
|
||||
|
||||
pid, err := StartProcess("ls", "-a")
|
||||
|
||||
assert.IsNil(err)
|
||||
assert.Equal(true, pid > 0)
|
||||
}
|
||||
|
||||
func TestKillProcess(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := internal.NewAssert(t, "TestKillProcess")
|
||||
|
||||
pid, err := StartProcess("ls")
|
||||
assert.IsNil(err)
|
||||
assert.Equal(true, pid > 0)
|
||||
|
||||
err = KillProcess(pid)
|
||||
assert.IsNil(err)
|
||||
}
|
||||
|
||||
func TestStopProcess(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := internal.NewAssert(t, "TestStopProcess")
|
||||
|
||||
pid, err := StartProcess("ls")
|
||||
assert.IsNil(err)
|
||||
assert.Equal(true, pid > 0)
|
||||
|
||||
err = StopProcess(pid)
|
||||
assert.IsNil(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user