start integration testing
This commit is contained in:
@@ -7,7 +7,7 @@ commands:
|
||||
success:
|
||||
- successCmd
|
||||
|
||||
errorCmd:
|
||||
successCmd:
|
||||
name: get docker version
|
||||
cmd: docker
|
||||
getOutput: true
|
||||
|
||||
@@ -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
61
tests/integration_test.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user