...
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
//! 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! ===");
|
Reference in New Issue
Block a user