2025-07-09 13:19:43 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2025-08-16 18:00:28 +01:00
|
|
|
"headshed/infctl-cli/config"
|
2025-07-09 13:19:43 +01:00
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-16 18:00:28 +01:00
|
|
|
// Test only pipeline execution and shell command running
|
2025-07-09 13:19:43 +01:00
|
|
|
|
|
|
|
|
func TestRunPipeline(t *testing.T) {
|
|
|
|
|
tempDir, err := os.MkdirTemp("", "smoke-test")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Failed to create temp directory: %v", err)
|
|
|
|
|
}
|
2025-08-16 18:00:28 +01:00
|
|
|
defer os.RemoveAll(tempDir)
|
2025-07-09 13:19:43 +01:00
|
|
|
|
2025-08-16 18:00:28 +01:00
|
|
|
// Create a test script
|
|
|
|
|
scriptPath := filepath.Join(tempDir, "good.sh")
|
|
|
|
|
scriptContent := "#!/bin/bash\necho 'Good script executed'\nexit 0"
|
|
|
|
|
if err := os.WriteFile(scriptPath, []byte(scriptContent), 0755); err != nil {
|
|
|
|
|
t.Fatalf("Failed to create script: %v", err)
|
2025-07-09 13:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a test JSON pipeline file
|
|
|
|
|
pipeline := []PipelineStep{
|
2025-08-16 18:00:28 +01:00
|
|
|
{Name: "Good Step", Function: "RunCommand", Params: []string{scriptPath}, RetryCount: 0, ShouldAbort: false},
|
2025-07-09 13:19:43 +01:00
|
|
|
}
|
|
|
|
|
pipelineFile := filepath.Join(tempDir, "pipeline.json")
|
|
|
|
|
pipelineData, err := json.Marshal(pipeline)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Failed to marshal pipeline: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(pipelineFile, pipelineData, 0644); err != nil {
|
|
|
|
|
t.Fatalf("Failed to write pipeline file: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set up AppState
|
|
|
|
|
app := &AppState{
|
2025-08-16 18:00:28 +01:00
|
|
|
Config: config.BaseConfig{},
|
|
|
|
|
Project: config.ProjectConfig{
|
2025-07-09 13:19:43 +01:00
|
|
|
DeploymentFile: pipelineFile,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run the pipeline
|
2025-08-16 18:00:28 +01:00
|
|
|
err = app.RunJsonDeployment()
|
2025-07-09 13:19:43 +01:00
|
|
|
if err != nil {
|
2025-08-16 18:00:28 +01:00
|
|
|
t.Errorf("Expected no error, got: %v", err)
|
2025-07-09 13:19:43 +01:00
|
|
|
}
|
2025-08-16 18:00:28 +01:00
|
|
|
}
|
2025-07-09 13:19:43 +01:00
|
|
|
|
2025-08-16 18:00:28 +01:00
|
|
|
// Removed randomString: not needed for current tests
|
2025-07-09 13:19:43 +01:00
|
|
|
|
2025-08-16 18:00:28 +01:00
|
|
|
// Removed TestK3DNamespaceCreation: k3d and k8s namespace logic is no longer part of the app
|
|
|
|
|
// Removed TestSetUpNewProject: advanced project setup logic is no longer part of the app
|