sal/kubernetes/tests/rhai/pod_env_vars_test.rhai
Mahmoud-Emad 6b12001ca2 feat: Add Kubernetes examples and update dependencies
- Add Kubernetes examples demonstrating deployment of various
  applications (PostgreSQL, Redis, generic). This improves the
  documentation and provides practical usage examples.
- Add `tokio` dependency for async examples. This enables the use
  of asynchronous operations in the examples.
- Add `once_cell` dependency for improved resource management in
  Kubernetes module. This allows efficient management of
  singletons and other resources.
2025-07-10 00:40:11 +03:00

143 lines
4.2 KiB
Plaintext

// Rhai test for pod creation with environment variables functionality
// This test verifies that the enhanced pod_create function works correctly with environment variables
print("=== Testing Pod Environment Variables in Rhai ===");
// Create Kubernetes manager
print("Creating Kubernetes manager...");
let km = kubernetes_manager_new("default");
print("✓ Kubernetes manager created");
// Test 1: Create pod with environment variables
print("\n--- Test 1: Create Pod with Environment Variables ---");
// Clean up any existing resources
try {
delete_pod(km, "rhai-pod-env-test");
print("✓ Cleaned up existing pod");
} catch(e) {
print("✓ No existing pod to clean up");
}
// Create pod with both labels and environment variables
try {
let result = km.create_pod_with_env("rhai-pod-env-test", "nginx:latest", #{
"app": "rhai-pod-env-test",
"test": "pod-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("✓ Created pod with environment variables: " + result);
} catch(e) {
print("❌ Failed to create pod with env vars: " + e);
throw e;
}
// Test 2: Create pod without environment variables
print("\n--- Test 2: Create Pod without Environment Variables ---");
try {
delete_pod(km, "rhai-pod-no-env-test");
} catch(e) {
// Ignore cleanup errors
}
try {
let result = km.create_pod("rhai-pod-no-env-test", "nginx:latest", #{
"app": "rhai-pod-no-env-test",
"test": "no-environment-variables"
});
print("✓ Created pod without environment variables: " + result);
} catch(e) {
print("❌ Failed to create pod without env vars: " + e);
throw e;
}
// Test 3: Create pod with special characters in env vars
print("\n--- Test 3: Create Pod with Special Characters in Env Vars ---");
try {
delete_pod(km, "rhai-pod-special-env-test");
} catch(e) {
// Ignore cleanup errors
}
try {
let result = km.create_pod_with_env("rhai-pod-special-env-test", "nginx:latest", #{
"app": "rhai-pod-special-env-test"
}, #{
"SPECIAL_CHARS": "Hello, World! @#$%^&*()",
"JSON_CONFIG": "{\"key\": \"value\", \"number\": 123}",
"URL_WITH_PARAMS": "https://api.example.com/v1/data?param1=value1&param2=value2"
});
print("✓ Created pod with special characters in env vars: " + result);
} catch(e) {
print("❌ Failed to create pod with special env vars: " + e);
throw e;
}
// Test 4: Verify resource listing
print("\n--- Test 4: Verify Pod Listing ---");
try {
let pods = pods_list(km);
print("✓ Found " + pods.len() + " pods");
let found_env_test = false;
let found_no_env_test = false;
let found_special_env_test = false;
for pod in pods {
if pod.contains("rhai-pod-env-test") {
found_env_test = true;
print("✓ Found rhai-pod-env-test pod");
}
if pod.contains("rhai-pod-no-env-test") {
found_no_env_test = true;
print("✓ Found rhai-pod-no-env-test pod");
}
if pod.contains("rhai-pod-special-env-test") {
found_special_env_test = true;
print("✓ Found rhai-pod-special-env-test pod");
}
}
if found_env_test && found_no_env_test && found_special_env_test {
print("✓ All expected pods found");
} else {
print("❌ Some expected pods not found");
}
} catch(e) {
print("❌ Failed to list pods: " + e);
}
// Cleanup
print("\n--- Cleanup ---");
try {
delete_pod(km, "rhai-pod-env-test");
print("✓ Deleted pod: rhai-pod-env-test");
} catch(e) {
print("⚠ Failed to delete rhai-pod-env-test: " + e);
}
try {
delete_pod(km, "rhai-pod-no-env-test");
print("✓ Deleted pod: rhai-pod-no-env-test");
} catch(e) {
print("⚠ Failed to delete rhai-pod-no-env-test: " + e);
}
try {
delete_pod(km, "rhai-pod-special-env-test");
print("✓ Deleted pod: rhai-pod-special-env-test");
} catch(e) {
print("⚠ Failed to delete rhai-pod-special-env-test: " + e);
}
print("\n=== Pod Environment Variables Rhai Test Complete ===");
print("✅ All tests passed successfully!");