package executor import ( "strconv" "testing" "wdd.io/agent-common/assert" ) var emptyFilePath = "/home/wdd/IdeaProjects/ProjectOctopus/agent-go/executor/script/123" var noExistFilePath = "/home/wdd/IdeaProjects/ProjectOctopus/agent-go/executor/script/456" func TestBasicFileExistAndNotNull(t *testing.T) { resultOK := BasicFileExistAndNotNull(emptyFilePath) assert.Equal(t, resultOK, false, "判定为空文件返回false!") } func TestBasicReplaceFileNotExists(t *testing.T) { replace := BasicReplace(noExistFilePath, "123", "123") t.Logf("replace no exists file result are => %#v", replace) } func TestBasicFileExists(t *testing.T) { exists := BasicFileExists(emptyFilePath) assert.Equal(t, exists, true, "文件存在,但是为空,应该返回true!") } func TestBasicFileExistFalse(t *testing.T) { exists := BasicFileExists(noExistFilePath) assert.Equal(t, exists, false, "文件不存在,应该返回false!") } func TestBasicSystemdShutdown(t *testing.T) { ok, resultLog := BasicSystemdShutdown("docker.service") //ok, resultLog := BasicSystemdShutdown("docker") //ok, resultLog := BasicSystemdShutdown("fwd") t.Logf("result ok is %v resultLog is %v", ok, resultLog) } func TestBasicSystemdUp(t *testing.T) { //ok, resultLog := BasicSystemdUp("docker.service") //ok, resultLog := BasicSystemdUp("docker") ok, resultLog := BasicSystemdUp("fwd") 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)) } func TestBasicDockerImageExistByFullName(t *testing.T) { // Test cases testCases := []struct { name string imageFullName string expectedResult bool }{ { name: "Image exists with full name and version", imageFullName: "harbor.cdcyy.com.cn/cmii/busybox:0326", expectedResult: true, }, { name: "Image does not exist with full name and version", imageFullName: "nonexistentImage:latest", expectedResult: false, }, { name: "Image exists with full name but no version", imageFullName: "harbor.cdcyy.com.cn/cmii/busybox", expectedResult: true, }, { name: "Image does not exist with full name but no version", imageFullName: "nonexistentImage", expectedResult: false, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { result := BasicDockerImageExistByFullName(tc.imageFullName) if result != tc.expectedResult { t.Errorf("Expected %t for imageFullName %s, but got %t", tc.expectedResult, tc.imageFullName, result) } }) } }