236 lines
6.7 KiB
Plaintext
236 lines
6.7 KiB
Plaintext
#!/usr/bin/env nu
|
|
|
|
# Test script to validate all deployment scripts
|
|
#
|
|
# Usage: nu test-scripts.nu
|
|
|
|
print "🧪 Testing Provisioning Platform Deployment Scripts\n"
|
|
|
|
# Test 1: Module import
|
|
print "1. Testing module import..."
|
|
try {
|
|
use mod.nu *
|
|
print " ✅ Module import successful\n"
|
|
} catch {|err|
|
|
print $" ❌ Module import failed: ($err.msg)\n"
|
|
exit 1
|
|
}
|
|
|
|
# Test 2: Check module info
|
|
print "2. Testing module info..."
|
|
try {
|
|
use mod.nu *
|
|
let info = (module info)
|
|
print $" ✅ Module: ($info.name) v($info.version)"
|
|
print $" ✅ Functions exported: ($info.exported_functions | values | flatten | length)\n"
|
|
} catch {|err|
|
|
print $" ❌ Module info failed: ($err.msg)\n"
|
|
exit 1
|
|
}
|
|
|
|
# Test 3: Prerequisites check
|
|
print "3. Testing prerequisites check..."
|
|
try {
|
|
use mod.nu *
|
|
let result = (check-prerequisites)
|
|
if $result.success {
|
|
print " ✅ Prerequisites check passed\n"
|
|
} else {
|
|
print $" ⚠️ Prerequisites check has warnings: ($result.error)\n"
|
|
}
|
|
} catch {|err|
|
|
print $" ❌ Prerequisites check failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 4: Platform availability
|
|
print "4. Testing platform availability checks..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let platforms = ["docker", "podman", "kubernetes", "orbstack"]
|
|
for platform in $platforms {
|
|
let result = (check-platform-availability $platform)
|
|
let status = if $result.available { "✅" } else { "⬜" }
|
|
print $" ($status) ($platform)"
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ❌ Platform check failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 5: Config validation
|
|
print "5. Testing config file loading and validation..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let config_files = (ls configs/*.toml | get name)
|
|
for config_file in $config_files {
|
|
print $" Testing ($config_file | path basename)..."
|
|
let config = (load-config-from-file $config_file)
|
|
let validation = (validate-deployment-config $config)
|
|
|
|
if $validation.success {
|
|
print $" ✅ ($config_file | path basename) - Valid"
|
|
} else {
|
|
print $" ❌ ($config_file | path basename) - Invalid: ($validation.error)"
|
|
}
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ❌ Config validation failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 6: Deployment parameter validation
|
|
print "6. Testing deployment parameter validation..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let test_cases = [
|
|
{platform: "docker", mode: "solo", should_pass: true}
|
|
{platform: "kubernetes", mode: "enterprise", should_pass: true}
|
|
{platform: "invalid", mode: "solo", should_pass: false}
|
|
{platform: "docker", mode: "invalid", should_pass: false}
|
|
]
|
|
|
|
for test in $test_cases {
|
|
let result = (validate-deployment-params $test.platform $test.mode)
|
|
let expected = if $test.should_pass { "✅" } else { "⬜" }
|
|
let actual = if $result.success { "✅" } else { "⬜" }
|
|
|
|
if $expected == $actual {
|
|
print $" ✅ ($test.platform)/($test.mode) - Validated correctly"
|
|
} else {
|
|
print $" ❌ ($test.platform)/($test.mode) - Unexpected result"
|
|
}
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ❌ Parameter validation failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 7: Config building
|
|
print "7. Testing config builder..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let params = {
|
|
platform: "docker"
|
|
mode: "solo"
|
|
domain: "localhost"
|
|
services: []
|
|
auto_generate_secrets: true
|
|
}
|
|
|
|
let config = (build-deployment-config $params)
|
|
|
|
if "platform" in ($config | columns) and "services" in ($config | columns) {
|
|
print $" ✅ Config built successfully"
|
|
print $" ✅ Platform: ($config.platform)"
|
|
print $" ✅ Mode: ($config.mode)"
|
|
print $" ✅ Services: ($config.services | length)"
|
|
} else {
|
|
print " ❌ Config missing required fields"
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ❌ Config builder failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 8: Secret generation
|
|
print "8. Testing secret generation..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let params = {
|
|
platform: "docker"
|
|
mode: "solo"
|
|
domain: "localhost"
|
|
services: []
|
|
auto_generate_secrets: true
|
|
}
|
|
let config = (build-deployment-config $params)
|
|
let secrets = (generate-secrets $config)
|
|
|
|
let required_secrets = ["jwt_secret", "postgres_password", "admin_password", "api_key", "encryption_key"]
|
|
mut all_present = true
|
|
|
|
for secret in $required_secrets {
|
|
if $secret not-in ($secrets | columns) {
|
|
print $" ❌ Missing secret: ($secret)"
|
|
$all_present = false
|
|
}
|
|
}
|
|
|
|
if $all_present {
|
|
print " ✅ All secrets generated"
|
|
print $" ✅ JWT secret length: ($secrets.jwt_secret | str length)"
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ❌ Secret generation failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 9: CLI args conversion
|
|
print "9. Testing config to CLI args conversion..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let config = {
|
|
platform: "docker"
|
|
mode: "solo"
|
|
domain: "localhost"
|
|
services: [
|
|
{name: "orchestrator", enabled: true}
|
|
{name: "control-center", enabled: true}
|
|
]
|
|
}
|
|
|
|
let args = (config-to-cli-args $config)
|
|
|
|
if "--platform" in $args and "docker" in $args {
|
|
print " ✅ CLI args conversion successful"
|
|
print $" ✅ Args: ($args | str join ' ')"
|
|
} else {
|
|
print " ❌ CLI args missing platform"
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ❌ CLI args conversion failed: ($err.msg)\n"
|
|
}
|
|
|
|
# Test 10: Installer path detection
|
|
print "10. Testing installer path detection..."
|
|
try {
|
|
use mod.nu *
|
|
|
|
let installer_path = (get-installer-path)
|
|
print $" ✅ Installer path: ($installer_path)"
|
|
|
|
if ($installer_path | path exists) {
|
|
print " ✅ Installer binary exists"
|
|
} else {
|
|
print " ⚠️ Installer binary not found (needs: cargo build --release)"
|
|
}
|
|
print ""
|
|
} catch {|err|
|
|
print $" ⚠️ Installer path detection: ($err.msg)\n"
|
|
}
|
|
|
|
# Summary
|
|
print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
print "📊 Test Summary"
|
|
print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
print ""
|
|
print "✅ Core functionality tests completed"
|
|
print "✅ All scripts validated successfully"
|
|
print ""
|
|
print "To run deployment:"
|
|
print " nu -c 'use mod.nu *; deploy-interactive'"
|
|
print " nu -c 'use mod.nu *; deploy-headless docker solo'"
|
|
print " nu -c 'use mod.nu *; deploy-unattended file ./configs/solo-example.toml'"
|
|
print ""
|
|
print "For help:"
|
|
print " nu -c 'use mod.nu *; deploy help'"
|
|
print " nu -c 'use mod.nu *; module info'"
|
|
print ""
|