start integration testing
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
ci/woodpecker/push/publish-docs Pipeline failed

This commit is contained in:
2025-12-08 18:12:31 -06:00
parent 2824f8c703
commit 803b039849
3 changed files with 71 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ commands:
success:
- successCmd
errorCmd:
successCmd:
name: get docker version
cmd: docker
getOutput: true

View File

@@ -7,9 +7,16 @@ import (
)
func TestRunCommandFileTest(t *testing.T) {
filePath := "packageCommands.yml"
cmdLineStr := fmt.Sprintf("go run ../backy.go exec host -c checkDockerNoVersion -m localhost --cmdStdOut -f %s", filePath)
exec.Command("bash", "-c", cmdLineStr).Output()
cmd := exec.Command("bash", "-c", cmdLineStr)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Command failed: %v, Output: %s", err, string(output))
}
if len(output) == 0 {
t.Fatal("Expected command output, got none")
}
}

61
tests/integration_test.go Normal file
View File

@@ -0,0 +1,61 @@
package tests
import (
"os"
"os/exec"
"testing"
)
func TestIntegration_ExecuteCommand(t *testing.T) {
tests := []struct {
name string
args []string
expectFail bool
}{
{
name: "Version Command",
args: []string{"version"},
expectFail: false,
},
{
name: "Invalid Command",
args: []string{"invalid"},
expectFail: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := exec.Command("go", append([]string{"run", "../backy.go"}, tt.args...)...)
output, err := cmd.CombinedOutput()
if tt.expectFail && err == nil {
t.Fatalf("Expected failure but got success. Output: %s", string(output))
}
if !tt.expectFail && err != nil {
t.Fatalf("Expected success but got failure. Error: %v, Output: %s", err, string(output))
}
})
}
}
func TestIntegration_ExecuteCommandWithConfig(t *testing.T) {
configFile := "./SuccessHook.yml"
if _, err := os.Stat(configFile); os.IsNotExist(err) {
t.Fatalf("Config file not found: %s", configFile)
}
cmd := exec.Command("go", "run", "../backy.go", "exec", "--config", configFile, "echoTestSuccess")
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("Command execution failed. Error: %v, Output: %s", err, string(output))
}
if len(output) == 0 {
t.Fatal("Expected command output, got none")
}
t.Logf("Command output: %s", string(output))
}