[Agent] [Executor] fix bugs

This commit is contained in:
zeaslity
2023-11-08 14:57:40 +08:00
parent ee1ed8c02b
commit ce108b2f4d
3 changed files with 16 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ func BasicCommandExists(commandName string) bool {
cmd := exec.Command("command", "-v", commandName) cmd := exec.Command("command", "-v", commandName)
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
log.DebugF("指令 %s 不存在", commandName) log.DebugF("指令 %s 不存在 => %s", commandName, err.Error())
return false return false
} else { } else {
return true return true

View File

@@ -2,6 +2,7 @@ package executor
import ( import (
"github.com/magiconair/properties/assert" "github.com/magiconair/properties/assert"
"strconv"
"testing" "testing"
) )
@@ -57,3 +58,11 @@ func TestBasicSystemdUp(t *testing.T) {
t.Logf("result ok is %v resultLog is %v", ok, resultLog) t.Logf("result ok is %v resultLog is %v", ok, resultLog)
} }
func TestBasicCommandExists(t *testing.T) {
exists := BasicCommandExists("docker-compose")
t.Logf("command exists is => %s", strconv.FormatBool(exists))
}

View File

@@ -34,6 +34,11 @@ var wgetCommand = []string{
"/home/wdd/IdeaProjects/ProjectOctopus/agent-go/executor/script/123", "/home/wdd/IdeaProjects/ProjectOctopus/agent-go/executor/script/123",
} }
var echoPathCommand = []string{
"echo",
"$PATH",
}
var pipelineCommandFalse = []string{ var pipelineCommandFalse = []string{
"ls", "ls",
"/etc", "/etc",
@@ -67,7 +72,7 @@ func TestReadTimeOutput(t *testing.T) {
} }
func TestAllCommandExecutor(t *testing.T) { func TestAllCommandExecutor(t *testing.T) {
ok, result := AllCommandExecutor(wgetCommand) ok, result := AllCommandExecutor(echoPathCommand)
t.Logf("执行结果为 => %#v", ok) t.Logf("执行结果为 => %#v", ok)
t.Logf("执行日志为 => %#v", result) t.Logf("执行日志为 => %#v", result)