feat: 实现电脑端被控与控制界面
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInterpreter(t *testing.T) {
|
||||
name, args := Interpreter("echo hi")
|
||||
if runtime.GOOS == "windows" {
|
||||
if name != "cmd.exe" || len(args) != 2 || args[0] != "/c" || args[1] != "echo hi" {
|
||||
t.Fatalf("windows interpreter: %s %v", name, args)
|
||||
}
|
||||
return
|
||||
}
|
||||
if name != "/bin/sh" || len(args) != 2 || args[0] != "-c" || args[1] != "echo hi" {
|
||||
t.Fatalf("unix interpreter: %s %v", name, args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSystemEcho(t *testing.T) {
|
||||
out, err := (System{Timeout: 5 * time.Second}).Run(context.Background(), "echo tapremly-ok")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(out, "tapremly-ok") {
|
||||
t.Fatalf("output %q", out)
|
||||
}
|
||||
}
|
||||
func TestSummarize(t *testing.T) {
|
||||
ok, detail := Summarize("hello\r\nworld", nil)
|
||||
if !ok || detail != "hello" {
|
||||
t.Fatalf("got %v %q", ok, detail)
|
||||
}
|
||||
ok, detail = Summarize("", context.DeadlineExceeded)
|
||||
if ok || detail != "执行超时" {
|
||||
t.Fatalf("got %v %q", ok, detail)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user