...
This commit is contained in:
199
packages/system/kubernetes/tests/rhai/env_vars_test.rhai
Normal file
199
packages/system/kubernetes/tests/rhai/env_vars_test.rhai
Normal file
@@ -0,0 +1,199 @@
|
||||
// Rhai test for environment variables functionality
|
||||
// This test verifies that the enhanced deploy_application function works correctly with environment variables
|
||||
|
||||
print("=== Testing Environment Variables in Rhai ===");
|
||||
|
||||
// Create Kubernetes manager
|
||||
print("Creating Kubernetes manager...");
|
||||
let km = kubernetes_manager_new("default");
|
||||
print("✓ Kubernetes manager created");
|
||||
|
||||
// Test 1: Deploy application with environment variables
|
||||
print("\n--- Test 1: Deploy with Environment Variables ---");
|
||||
|
||||
// Clean up any existing resources
|
||||
try {
|
||||
delete_deployment(km, "rhai-env-test");
|
||||
print("✓ Cleaned up existing deployment");
|
||||
} catch(e) {
|
||||
print("✓ No existing deployment to clean up");
|
||||
}
|
||||
|
||||
try {
|
||||
delete_service(km, "rhai-env-test");
|
||||
print("✓ Cleaned up existing service");
|
||||
} catch(e) {
|
||||
print("✓ No existing service to clean up");
|
||||
}
|
||||
|
||||
// Deploy with both labels and environment variables
|
||||
try {
|
||||
let result = deploy_application(km, "rhai-env-test", "nginx:latest", 1, 80, #{
|
||||
"app": "rhai-env-test",
|
||||
"test": "environment-variables",
|
||||
"language": "rhai"
|
||||
}, #{
|
||||
"NODE_ENV": "test",
|
||||
"DATABASE_URL": "postgres://localhost:5432/test",
|
||||
"API_KEY": "test-api-key-12345",
|
||||
"LOG_LEVEL": "debug",
|
||||
"PORT": "80"
|
||||
});
|
||||
print("✓ " + result);
|
||||
} catch(e) {
|
||||
print("❌ Failed to deploy with env vars: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Verify deployment was created
|
||||
try {
|
||||
let deployment_name = get_deployment(km, "rhai-env-test");
|
||||
print("✓ Deployment verified: " + deployment_name);
|
||||
} catch(e) {
|
||||
print("❌ Failed to verify deployment: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Test 2: Deploy application without environment variables
|
||||
print("\n--- Test 2: Deploy without Environment Variables ---");
|
||||
|
||||
// Clean up
|
||||
try {
|
||||
delete_deployment(km, "rhai-no-env-test");
|
||||
delete_service(km, "rhai-no-env-test");
|
||||
} catch(e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
// Deploy with labels only, empty env vars map
|
||||
try {
|
||||
let result = deploy_application(km, "rhai-no-env-test", "nginx:alpine", 1, 8080, #{
|
||||
"app": "rhai-no-env-test",
|
||||
"test": "no-environment-variables"
|
||||
}, #{
|
||||
// Empty environment variables map
|
||||
});
|
||||
print("✓ " + result);
|
||||
} catch(e) {
|
||||
print("❌ Failed to deploy without env vars: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Test 3: Deploy with special characters in environment variables
|
||||
print("\n--- Test 3: Deploy with Special Characters in Env Vars ---");
|
||||
|
||||
// Clean up
|
||||
try {
|
||||
delete_deployment(km, "rhai-special-env-test");
|
||||
delete_service(km, "rhai-special-env-test");
|
||||
} catch(e) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
// Deploy with special characters
|
||||
try {
|
||||
let result = deploy_application(km, "rhai-special-env-test", "nginx:latest", 1, 3000, #{
|
||||
"app": "rhai-special-env-test"
|
||||
}, #{
|
||||
"DATABASE_URL": "postgres://user:pass@host:5432/db?ssl=true&timeout=30",
|
||||
"JSON_CONFIG": `{"server": {"port": 3000, "host": "0.0.0.0"}}`,
|
||||
"SPECIAL_CHARS": "!@#$%^&*()_+-=[]{}|;:,.<>?",
|
||||
"MULTILINE": "line1\nline2\nline3"
|
||||
});
|
||||
print("✓ " + result);
|
||||
} catch(e) {
|
||||
print("❌ Failed to deploy with special chars: " + e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Test 4: Test resource listing after deployments
|
||||
print("\n--- Test 4: Verify Resource Listing ---");
|
||||
|
||||
try {
|
||||
let deployments = deployments_list(km);
|
||||
print("✓ Found " + deployments.len() + " deployments");
|
||||
|
||||
// Check that our test deployments are in the list
|
||||
let found_env_test = false;
|
||||
let found_no_env_test = false;
|
||||
let found_special_test = false;
|
||||
|
||||
for deployment in deployments {
|
||||
if deployment == "rhai-env-test" {
|
||||
found_env_test = true;
|
||||
} else if deployment == "rhai-no-env-test" {
|
||||
found_no_env_test = true;
|
||||
} else if deployment == "rhai-special-env-test" {
|
||||
found_special_test = true;
|
||||
}
|
||||
}
|
||||
|
||||
if found_env_test {
|
||||
print("✓ Found rhai-env-test deployment");
|
||||
} else {
|
||||
print("❌ rhai-env-test deployment not found in list");
|
||||
}
|
||||
|
||||
if found_no_env_test {
|
||||
print("✓ Found rhai-no-env-test deployment");
|
||||
} else {
|
||||
print("❌ rhai-no-env-test deployment not found in list");
|
||||
}
|
||||
|
||||
if found_special_test {
|
||||
print("✓ Found rhai-special-env-test deployment");
|
||||
} else {
|
||||
print("❌ rhai-special-env-test deployment not found in list");
|
||||
}
|
||||
} catch(e) {
|
||||
print("❌ Failed to list deployments: " + e);
|
||||
}
|
||||
|
||||
// Test 5: Test services listing
|
||||
print("\n--- Test 5: Verify Services ---");
|
||||
|
||||
try {
|
||||
let services = services_list(km);
|
||||
print("✓ Found " + services.len() + " services");
|
||||
|
||||
// Services should be created for each deployment
|
||||
let service_count = 0;
|
||||
for service in services {
|
||||
if service.contains("rhai-") && service.contains("-test") {
|
||||
service_count = service_count + 1;
|
||||
print("✓ Found test service: " + service);
|
||||
}
|
||||
}
|
||||
|
||||
if service_count >= 3 {
|
||||
print("✓ All expected services found");
|
||||
} else {
|
||||
print("⚠️ Expected at least 3 test services, found " + service_count);
|
||||
}
|
||||
} catch(e) {
|
||||
print("❌ Failed to list services: " + e);
|
||||
}
|
||||
|
||||
// Cleanup all test resources
|
||||
print("\n--- Cleanup ---");
|
||||
|
||||
let cleanup_items = ["rhai-env-test", "rhai-no-env-test", "rhai-special-env-test"];
|
||||
|
||||
for item in cleanup_items {
|
||||
try {
|
||||
delete_deployment(km, item);
|
||||
print("✓ Deleted deployment: " + item);
|
||||
} catch(e) {
|
||||
print("⚠️ Could not delete deployment " + item + ": " + e);
|
||||
}
|
||||
|
||||
try {
|
||||
delete_service(km, item);
|
||||
print("✓ Deleted service: " + item);
|
||||
} catch(e) {
|
||||
print("⚠️ Could not delete service " + item + ": " + e);
|
||||
}
|
||||
}
|
||||
|
||||
print("\n=== Environment Variables Rhai Test Complete ===");
|
||||
print("✅ All tests passed successfully!");
|
Reference in New Issue
Block a user