sal/kubernetes/tests/rhai/namespace_operations.rhai
Mahmoud-Emad 52f2f7e3c4 feat: Add Kubernetes module to SAL
- Add Kubernetes cluster management and operations
- Include pod, service, and deployment management
- Implement pattern-based resource deletion
- Support namespace creation and management
- Provide Rhai scripting wrappers for all functions
- Include production safety features (timeouts, retries, rate limiting)
2025-06-30 14:56:54 +03:00

86 lines
2.6 KiB
Plaintext

//! Namespace operations test
//!
//! This script tests namespace creation and management operations.
print("=== Namespace Operations Test ===");
// Test 1: Create manager
print("Test 1: Creating KubernetesManager...");
let km = kubernetes_manager_new("default");
print("✓ Manager created for namespace: " + namespace(km));
// Test 2: Namespace existence checks
print("\nTest 2: Testing namespace existence...");
try {
// Test that default namespace exists
let default_exists = namespace_exists(km, "default");
print("✓ Default namespace exists: " + default_exists);
assert(default_exists, "Default namespace should exist");
// Test non-existent namespace
let fake_exists = namespace_exists(km, "definitely-does-not-exist-12345");
print("✓ Non-existent namespace check: " + fake_exists);
assert(!fake_exists, "Non-existent namespace should not exist");
} catch(e) {
print("Note: Namespace existence tests failed (likely no cluster): " + e);
}
// Test 3: Namespace creation (if cluster is available)
print("\nTest 3: Testing namespace creation...");
let test_namespaces = [
"rhai-test-namespace-1",
"rhai-test-namespace-2"
];
for test_ns in test_namespaces {
try {
print("Creating namespace: " + test_ns);
namespace_create(km, test_ns);
print("✓ Created namespace: " + test_ns);
// Verify it exists
let exists = namespace_exists(km, test_ns);
print("✓ Verified namespace exists: " + exists);
// Test idempotent creation
namespace_create(km, test_ns);
print("✓ Idempotent creation successful for: " + test_ns);
} catch(e) {
print("Note: Namespace creation failed for " + test_ns + " (likely no cluster or permissions): " + e);
}
}
// Test 4: List all namespaces
print("\nTest 4: Listing all namespaces...");
try {
let all_namespaces = namespaces_list(km);
print("✓ Found " + all_namespaces.len() + " total namespaces");
// Check for our test namespaces
for test_ns in test_namespaces {
let found = false;
for ns in all_namespaces {
if ns == test_ns {
found = true;
break;
}
}
if found {
print("✓ Found test namespace in list: " + test_ns);
}
}
} catch(e) {
print("Note: Namespace listing failed (likely no cluster): " + e);
}
print("\n--- Cleanup Instructions ---");
print("To clean up test namespaces, run:");
for test_ns in test_namespaces {
print(" kubectl delete namespace " + test_ns);
}
print("\n=== Namespace operations test completed! ===");