github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/exec/cmd_test.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package executils_test 4 5 import ( 6 executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec" 7 "testing" 8 "time" 9 ) 10 11 func TestNewTimeoutCmd_Sleep(t *testing.T) { 12 var cmd = executils.NewTimeoutCmd(1*time.Second, "sleep", "3") 13 cmd.WithStdout() 14 cmd.WithStderr() 15 err := cmd.Run() 16 t.Log("error:", err) 17 t.Log("stdout:", cmd.Stdout()) 18 t.Log("stderr:", cmd.Stderr()) 19 } 20 21 func TestNewTimeoutCmd_Echo(t *testing.T) { 22 var cmd = executils.NewTimeoutCmd(10*time.Second, "echo", "-n", "hello") 23 cmd.WithStdout() 24 cmd.WithStderr() 25 err := cmd.Run() 26 t.Log("error:", err) 27 t.Log("stdout:", cmd.Stdout()) 28 t.Log("stderr:", cmd.Stderr()) 29 } 30 31 func TestNewTimeoutCmd_Echo2(t *testing.T) { 32 var cmd = executils.NewCmd("echo", "hello") 33 cmd.WithStdout() 34 cmd.WithStderr() 35 err := cmd.Run() 36 t.Log("error:", err) 37 t.Log("stdout:", cmd.Stdout()) 38 t.Log("raw stdout:", cmd.RawStdout()) 39 t.Log("stderr:", cmd.Stderr()) 40 t.Log("raw stderr:", cmd.RawStderr()) 41 } 42 43 func TestNewTimeoutCmd_Echo3(t *testing.T) { 44 var cmd = executils.NewCmd("echo", "-n", "hello") 45 err := cmd.Run() 46 t.Log("error:", err) 47 t.Log("stdout:", cmd.Stdout()) 48 t.Log("stderr:", cmd.Stderr()) 49 } 50 51 func TestCmd_Process(t *testing.T) { 52 var cmd = executils.NewCmd("echo", "-n", "hello") 53 err := cmd.Run() 54 t.Log("error:", err) 55 t.Log(cmd.Process()) 56 } 57 58 func TestNewTimeoutCmd_String(t *testing.T) { 59 var cmd = executils.NewCmd("echo", "-n", "hello") 60 t.Log("stdout:", cmd.String()) 61 }