update: Added Longhorn installation process and updated memory allocation for VMs
update: Added 'git' and 'vagrant' to required tools in pre-flight checks fix: configured k3s install to use internal nic for flanel network update: Added Longhorn installation process and updated memory allocation for VMs update: Added 'git' and 'vagrant' to required tools in pre-flight checks fix: configured k3s install to use internal nic for flanel network fix: corrected JSON formatting for config json update: reduce VM memory allocation to 2GB, add Longhorn installation scripts and prerequisites, and implement checks for existing pods fix: merge issues fix: merge issues update: Added Longhorn installation process and updated memory allocation for VMs update: Added 'git' and 'vagrant' to required tools in pre-flight checks fix: configured k3s install to use internal nic for flanel network update: Added Longhorn installation process and updated memory allocation for VMs update: Added 'git' and 'vagrant' to required tools in pre-flight checks fix: configured k3s install to use internal nic for flanel network fix: corrected JSON formatting for config json update: reduce VM memory allocation to 2GB, add Longhorn installation scripts and prerequisites, and implement checks for existing pods update: improve error logging in RunJsonDeployment and RunCommand functions update: add jq installation to provision script update: add version flag bump version fix: improve error messages for config file reading feat: add Windows gitbash installation support and improve binary download process clean up tmp code fix: increase timeout for some slower windows clients feat: add Ingress and Service configurations for nginx deployment, and implement MetalLB and Traeik installation scripts refactor: remove obsolete Traefik installation script feat: add environment checks and configurations for Vagrant setup, including dnsmasq MetalLB and ingress feat: add deployment and installation scripts for infmon-cli, including Kubernetes configurations feat: refactor customer project creation and add success/failure job scripts refactor: rename customer references to project in configuration and application logic feat: enhance JSON deployment handling with retry logic and command execution improvements feat: enhance RunJsonDeployment with error handling and retry logic; add tests for configuration reading feat: add automatic creation of base and config JSON files from examples if they do not exist refactor: remove database package and related functionality; update app state initialization and error handling refactor: update deployment handling to use ProjectConfig; improve error messages and logging feat: enhance RunJsonDeployment retry logic with configurable delay; improve logging for retries feat: implement LoadConfigs function for improved configuration loading; add logger setup refactor: remove unused fields from BaseConfig and ProjectConfig structs for cleaner configuration management refactor: clean up tests by removing obsolete functions and simplifying test cases chore: update version to v0.0.5 in install script feat: implement default configuration creation for BaseConfig and ProjectConfig; enhance validation logic fix: enhance configuration parsing and loading; streamline flag handling and error reporting refactor: remove obsolete configuration download logic from installation script
This commit is contained in:
parent
d839fd5687
commit
11b1f1b637
61 changed files with 1573 additions and 761 deletions
138
app/app_test.go
138
app/app_test.go
|
|
@ -2,129 +2,31 @@ package app
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"headshed/infctl-cli/config"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"headshed/infctl-cli/config"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// Setup: Set TEST_ENV=true for all tests
|
||||
err := os.Setenv("TEST_ENV", "true")
|
||||
if err != nil {
|
||||
panic("Failed to set TEST_ENV")
|
||||
}
|
||||
|
||||
// Run all tests
|
||||
code := m.Run()
|
||||
|
||||
// Teardown: Unset TEST_ENV after all tests
|
||||
os.Unsetenv("TEST_ENV")
|
||||
|
||||
// Exit with the test result code
|
||||
os.Exit(code)
|
||||
}
|
||||
// Test only pipeline execution and shell command running
|
||||
|
||||
func TestRunPipeline(t *testing.T) {
|
||||
// Create a temporary directory for test assets
|
||||
tempDir, err := os.MkdirTemp("", "smoke-test")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir) // Cleanup after test
|
||||
|
||||
// Create test scripts
|
||||
scripts := map[string]string{
|
||||
"good.sh": "#!/bin/bash\necho 'Good script executed'\nexit 0",
|
||||
"warning.sh": "#!/bin/bash\necho 'Warning script executed'\nexit 0",
|
||||
"error.sh": "#!/bin/bash\necho 'Error script executed'\nexit 1",
|
||||
}
|
||||
|
||||
for name, content := range scripts {
|
||||
scriptPath := filepath.Join(tempDir, name)
|
||||
if err := os.WriteFile(scriptPath, []byte(content), 0755); err != nil {
|
||||
t.Fatalf("Failed to create script %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create a test JSON pipeline file
|
||||
pipeline := []PipelineStep{
|
||||
{Name: "Good Step", Function: "RunCommand", Params: []string{filepath.Join(tempDir, "good.sh")}, RetryCount: 0, ShouldAbort: false},
|
||||
{Name: "Warning Step", Function: "RunCommand", Params: []string{filepath.Join(tempDir, "warning.sh")}, RetryCount: 0, ShouldAbort: false},
|
||||
{Name: "Error Step", Function: "RunCommand", Params: []string{filepath.Join(tempDir, "error.sh")}, RetryCount: 0, ShouldAbort: true},
|
||||
}
|
||||
|
||||
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{
|
||||
Config: config.BaseConfig{
|
||||
DeploymentFile: pipelineFile,
|
||||
},
|
||||
}
|
||||
|
||||
// Run the pipeline
|
||||
err = app.runPipeline(pipeline)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error due to 'Error Step', but got none")
|
||||
}
|
||||
}
|
||||
|
||||
func randomString(length int) string {
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = charset[rand.Intn(len(charset))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TestK3DNamespaceCreation(t *testing.T) {
|
||||
// Check if k3d is installed
|
||||
_, err := exec.LookPath("k3d")
|
||||
if err != nil {
|
||||
t.Fatal("k3d is not installed. Please install k3d to run this test.")
|
||||
}
|
||||
|
||||
// Create a test cluster
|
||||
clusterName := "test-" + randomString(6)
|
||||
|
||||
cmd := exec.Command("k3d", "cluster", "create", clusterName, "--servers", "1")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Failed to create k3d cluster: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
// Clean up the test cluster
|
||||
cmd := exec.Command("k3d", "cluster", "delete", clusterName)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Errorf("Failed to delete k3d cluster: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Create a temporary directory for the pipeline config
|
||||
tempDir, err := os.MkdirTemp("", "k3d-test")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Create a test JSON pipeline file
|
||||
pipeline := []PipelineStep{
|
||||
{Name: "Ensure Namespace Exists", Function: "k8sNamespaceExists", Params: []string{"test-namespace"}, RetryCount: 0, ShouldAbort: true},
|
||||
{Name: "Good Step", Function: "RunCommand", Params: []string{scriptPath}, RetryCount: 0, ShouldAbort: false},
|
||||
}
|
||||
pipelineFile := filepath.Join(tempDir, "pipeline.json")
|
||||
pipelineData, err := json.Marshal(pipeline)
|
||||
|
|
@ -137,22 +39,20 @@ func TestK3DNamespaceCreation(t *testing.T) {
|
|||
|
||||
// Set up AppState
|
||||
app := &AppState{
|
||||
Config: config.BaseConfig{
|
||||
Config: config.BaseConfig{},
|
||||
Project: config.ProjectConfig{
|
||||
DeploymentFile: pipelineFile,
|
||||
},
|
||||
}
|
||||
|
||||
// Run the pipeline
|
||||
err = app.runPipeline(pipeline)
|
||||
err = app.RunJsonDeployment()
|
||||
if err != nil {
|
||||
t.Fatalf("Pipeline execution failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify the namespace exists
|
||||
cmd = exec.Command("kubectl", "get", "ns", "test-namespace")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Namespace 'test-namespace' was not created: %v", err)
|
||||
t.Errorf("Expected no error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Removed randomString: not needed for current tests
|
||||
|
||||
// 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue