feat: Add redisclient package to the monorepo
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Integrate the redisclient package into the workspace. - Update the MONOREPO_CONVERSION_PLAN.md to reflect the completion of the redisclient package conversion. This includes marking its conversion as complete and updating the success metrics. - Add the redisclient package's Cargo.toml file. - Add the redisclient package's source code files. - Add tests for the redisclient package. - Add README file for the redisclient package.
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
// 01_redis_connection.rhai
|
||||
// Tests for Redis client connection and basic operations
|
||||
|
||||
// Custom assert function
|
||||
fn assert_true(condition, message) {
|
||||
if !condition {
|
||||
print(`ASSERTION FAILED: ${message}`);
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to check if Redis is available
|
||||
fn is_redis_available() {
|
||||
try {
|
||||
// Try to execute a simple PING command
|
||||
let ping_result = redis_ping();
|
||||
return ping_result == "PONG";
|
||||
} catch(err) {
|
||||
print(`Redis connection error: ${err}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
print("=== Testing Redis Client Connection ===");
|
||||
|
||||
// Check if Redis is available
|
||||
let redis_available = is_redis_available();
|
||||
if !redis_available {
|
||||
print("Redis server is not available. Skipping Redis tests.");
|
||||
// Exit gracefully without error
|
||||
return;
|
||||
}
|
||||
|
||||
print("✓ Redis server is available");
|
||||
|
||||
// Test redis_ping function
|
||||
print("Testing redis_ping()...");
|
||||
let ping_result = redis_ping();
|
||||
assert_true(ping_result == "PONG", "PING should return PONG");
|
||||
print(`✓ redis_ping(): Returned ${ping_result}`);
|
||||
|
||||
// Test redis_set and redis_get functions
|
||||
print("Testing redis_set() and redis_get()...");
|
||||
let test_key = "rhai_test_key";
|
||||
let test_value = "Hello from Rhai test";
|
||||
|
||||
// Set a value
|
||||
let set_result = redis_set(test_key, test_value);
|
||||
assert_true(set_result, "SET operation should succeed");
|
||||
print(`✓ redis_set(): Successfully set key ${test_key}`);
|
||||
|
||||
// Get the value back
|
||||
let get_result = redis_get(test_key);
|
||||
assert_true(get_result == test_value, "GET should return the value we set");
|
||||
print(`✓ redis_get(): Successfully retrieved value for key ${test_key}`);
|
||||
|
||||
// Test redis_del function
|
||||
print("Testing redis_del()...");
|
||||
let del_result = redis_del(test_key);
|
||||
assert_true(del_result, "DEL operation should succeed");
|
||||
print(`✓ redis_del(): Successfully deleted key ${test_key}`);
|
||||
|
||||
// Verify the key was deleted
|
||||
let get_after_del = redis_get(test_key);
|
||||
assert_true(get_after_del == "", "Key should not exist after deletion");
|
||||
print("✓ Key was successfully deleted");
|
||||
|
||||
print("All Redis connection tests completed successfully!");
|
@@ -1,109 +0,0 @@
|
||||
// 02_redis_operations.rhai
|
||||
// Tests for advanced Redis operations
|
||||
|
||||
// Custom assert function
|
||||
fn assert_true(condition, message) {
|
||||
if !condition {
|
||||
print(`ASSERTION FAILED: ${message}`);
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to check if Redis is available
|
||||
fn is_redis_available() {
|
||||
try {
|
||||
// Try to execute a simple PING command
|
||||
let ping_result = redis_ping();
|
||||
return ping_result == "PONG";
|
||||
} catch(err) {
|
||||
print(`Redis connection error: ${err}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
print("=== Testing Advanced Redis Operations ===");
|
||||
|
||||
// Check if Redis is available
|
||||
let redis_available = is_redis_available();
|
||||
if !redis_available {
|
||||
print("Redis server is not available. Skipping Redis tests.");
|
||||
// Exit gracefully without error
|
||||
return;
|
||||
}
|
||||
|
||||
print("✓ Redis server is available");
|
||||
|
||||
// Test prefix for all keys to avoid conflicts
|
||||
let prefix = "rhai_test_";
|
||||
|
||||
// Test redis_hset and redis_hget functions
|
||||
print("Testing redis_hset() and redis_hget()...");
|
||||
let hash_key = prefix + "hash";
|
||||
let field1 = "field1";
|
||||
let value1 = "value1";
|
||||
let field2 = "field2";
|
||||
let value2 = "value2";
|
||||
|
||||
// Set hash fields
|
||||
let hset_result1 = redis_hset(hash_key, field1, value1);
|
||||
assert_true(hset_result1, "HSET operation should succeed for field1");
|
||||
let hset_result2 = redis_hset(hash_key, field2, value2);
|
||||
assert_true(hset_result2, "HSET operation should succeed for field2");
|
||||
print(`✓ redis_hset(): Successfully set fields in hash ${hash_key}`);
|
||||
|
||||
// Get hash fields
|
||||
let hget_result1 = redis_hget(hash_key, field1);
|
||||
assert_true(hget_result1 == value1, "HGET should return the value we set for field1");
|
||||
let hget_result2 = redis_hget(hash_key, field2);
|
||||
assert_true(hget_result2 == value2, "HGET should return the value we set for field2");
|
||||
print(`✓ redis_hget(): Successfully retrieved values from hash ${hash_key}`);
|
||||
|
||||
// Test redis_hgetall function
|
||||
print("Testing redis_hgetall()...");
|
||||
let hgetall_result = redis_hgetall(hash_key);
|
||||
assert_true(hgetall_result.len() == 2, "HGETALL should return 2 fields");
|
||||
assert_true(hgetall_result[field1] == value1, "HGETALL should include field1 with correct value");
|
||||
assert_true(hgetall_result[field2] == value2, "HGETALL should include field2 with correct value");
|
||||
print(`✓ redis_hgetall(): Successfully retrieved all fields from hash ${hash_key}`);
|
||||
|
||||
// Test redis_hdel function
|
||||
print("Testing redis_hdel()...");
|
||||
let hdel_result = redis_hdel(hash_key, field1);
|
||||
assert_true(hdel_result, "HDEL operation should succeed");
|
||||
print(`✓ redis_hdel(): Successfully deleted field from hash ${hash_key}`);
|
||||
|
||||
// Verify the field was deleted
|
||||
let hget_after_del = redis_hget(hash_key, field1);
|
||||
assert_true(hget_after_del == "", "Field should not exist after deletion");
|
||||
print("✓ Field was successfully deleted from hash");
|
||||
|
||||
// Test redis_list operations
|
||||
print("Testing redis list operations...");
|
||||
let list_key = prefix + "list";
|
||||
|
||||
// Push items to list
|
||||
let rpush_result = redis_rpush(list_key, "item1");
|
||||
assert_true(rpush_result > 0, "RPUSH operation should succeed");
|
||||
redis_rpush(list_key, "item2");
|
||||
redis_rpush(list_key, "item3");
|
||||
print(`✓ redis_rpush(): Successfully pushed items to list ${list_key}`);
|
||||
|
||||
// Get list length
|
||||
let llen_result = redis_llen(list_key);
|
||||
assert_true(llen_result == 3, "List should have 3 items");
|
||||
print(`✓ redis_llen(): List has ${llen_result} items`);
|
||||
|
||||
// Get list range
|
||||
let lrange_result = redis_lrange(list_key, 0, -1);
|
||||
assert_true(lrange_result.len() == 3, "LRANGE should return 3 items");
|
||||
assert_true(lrange_result[0] == "item1", "First item should be 'item1'");
|
||||
assert_true(lrange_result[2] == "item3", "Last item should be 'item3'");
|
||||
print(`✓ redis_lrange(): Successfully retrieved all items from list ${list_key}`);
|
||||
|
||||
// Clean up
|
||||
print("Cleaning up...");
|
||||
redis_del(hash_key);
|
||||
redis_del(list_key);
|
||||
print("✓ Cleanup: All test keys removed");
|
||||
|
||||
print("All Redis operations tests completed successfully!");
|
@@ -1,59 +0,0 @@
|
||||
// 03_redis_authentication.rhai
|
||||
// Tests for Redis client authentication (placeholder for future implementation)
|
||||
|
||||
// Custom assert function
|
||||
fn assert_true(condition, message) {
|
||||
if !condition {
|
||||
print(`ASSERTION FAILED: ${message}`);
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to check if Redis is available
|
||||
fn is_redis_available() {
|
||||
try {
|
||||
// Try to execute a simple ping
|
||||
let ping_result = redis_ping();
|
||||
return ping_result == "PONG";
|
||||
} catch(err) {
|
||||
print(`Redis connection error: ${err}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
print("=== Testing Redis Client Authentication ===");
|
||||
|
||||
// Check if Redis is available
|
||||
let redis_available = is_redis_available();
|
||||
if !redis_available {
|
||||
print("Redis server is not available. Skipping Redis authentication tests.");
|
||||
// Exit gracefully without error
|
||||
return;
|
||||
}
|
||||
|
||||
print("✓ Redis server is available");
|
||||
|
||||
print("Authentication support will be implemented in a future update.");
|
||||
print("The backend implementation is ready, but the Rhai bindings are still in development.");
|
||||
|
||||
// For now, just test basic Redis functionality
|
||||
print("\nTesting basic Redis functionality...");
|
||||
|
||||
// Test a simple operation
|
||||
let test_key = "auth_test_key";
|
||||
let test_value = "auth_test_value";
|
||||
|
||||
let set_result = redis_set(test_key, test_value);
|
||||
assert_true(set_result, "Should be able to set a key");
|
||||
print("✓ Set key");
|
||||
|
||||
let get_result = redis_get(test_key);
|
||||
assert_true(get_result == test_value, "Should be able to get the key");
|
||||
print("✓ Got key");
|
||||
|
||||
// Clean up
|
||||
let del_result = redis_del(test_key);
|
||||
assert_true(del_result, "Should be able to delete the key");
|
||||
print("✓ Deleted test key");
|
||||
|
||||
print("All Redis tests completed successfully!");
|
@@ -1,154 +0,0 @@
|
||||
// run_all_tests.rhai
|
||||
// Runs all Redis client module tests
|
||||
|
||||
print("=== Running Redis Client Module Tests ===");
|
||||
|
||||
// Custom assert function
|
||||
fn assert_true(condition, message) {
|
||||
if !condition {
|
||||
print(`ASSERTION FAILED: ${message}`);
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to check if Redis is available
|
||||
fn is_redis_available() {
|
||||
try {
|
||||
// Try to execute a simple PING command
|
||||
let ping_result = redis_ping();
|
||||
return ping_result == "PONG";
|
||||
} catch(err) {
|
||||
print(`Redis connection error: ${err}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Run each test directly
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
let skipped = 0;
|
||||
|
||||
// Check if Redis is available
|
||||
let redis_available = is_redis_available();
|
||||
if !redis_available {
|
||||
print("Redis server is not available. Skipping all Redis tests.");
|
||||
skipped = 3; // Skip all three tests
|
||||
} else {
|
||||
// Test 1: Redis Connection
|
||||
print("\n--- Running Redis Connection Tests ---");
|
||||
try {
|
||||
// Test redis_ping function
|
||||
print("Testing redis_ping()...");
|
||||
let ping_result = redis_ping();
|
||||
assert_true(ping_result == "PONG", "PING should return PONG");
|
||||
print(`✓ redis_ping(): Returned ${ping_result}`);
|
||||
|
||||
// Test redis_set and redis_get functions
|
||||
print("Testing redis_set() and redis_get()...");
|
||||
let test_key = "rhai_test_key";
|
||||
let test_value = "Hello from Rhai test";
|
||||
|
||||
// Set a value
|
||||
let set_result = redis_set(test_key, test_value);
|
||||
assert_true(set_result, "SET operation should succeed");
|
||||
print(`✓ redis_set(): Successfully set key ${test_key}`);
|
||||
|
||||
// Get the value back
|
||||
let get_result = redis_get(test_key);
|
||||
assert_true(get_result == test_value, "GET should return the value we set");
|
||||
print(`✓ redis_get(): Successfully retrieved value for key ${test_key}`);
|
||||
|
||||
// Clean up
|
||||
redis_del(test_key);
|
||||
|
||||
print("--- Redis Connection Tests completed successfully ---");
|
||||
passed += 1;
|
||||
} catch(err) {
|
||||
print(`!!! Error in Redis Connection Tests: ${err}`);
|
||||
failed += 1;
|
||||
}
|
||||
|
||||
// Test 2: Redis Operations
|
||||
print("\n--- Running Redis Operations Tests ---");
|
||||
try {
|
||||
// Test prefix for all keys to avoid conflicts
|
||||
let prefix = "rhai_test_";
|
||||
|
||||
// Test redis_hset and redis_hget functions
|
||||
print("Testing redis_hset() and redis_hget()...");
|
||||
let hash_key = prefix + "hash";
|
||||
let field = "field1";
|
||||
let value = "value1";
|
||||
|
||||
// Set hash field
|
||||
let hset_result = redis_hset(hash_key, field, value);
|
||||
assert_true(hset_result, "HSET operation should succeed");
|
||||
print(`✓ redis_hset(): Successfully set field in hash ${hash_key}`);
|
||||
|
||||
// Get hash field
|
||||
let hget_result = redis_hget(hash_key, field);
|
||||
assert_true(hget_result == value, "HGET should return the value we set");
|
||||
print(`✓ redis_hget(): Successfully retrieved value from hash ${hash_key}`);
|
||||
|
||||
// Clean up
|
||||
redis_del(hash_key);
|
||||
|
||||
print("--- Redis Operations Tests completed successfully ---");
|
||||
passed += 1;
|
||||
} catch(err) {
|
||||
print(`!!! Error in Redis Operations Tests: ${err}`);
|
||||
failed += 1;
|
||||
}
|
||||
|
||||
// Test 3: Redis Authentication
|
||||
print("\n--- Running Redis Authentication Tests ---");
|
||||
try {
|
||||
print("Authentication support will be implemented in a future update.");
|
||||
print("The backend implementation is ready, but the Rhai bindings are still in development.");
|
||||
|
||||
// For now, just test basic Redis functionality
|
||||
print("\nTesting basic Redis functionality...");
|
||||
|
||||
// Test a simple operation
|
||||
let test_key = "auth_test_key";
|
||||
let test_value = "auth_test_value";
|
||||
|
||||
let set_result = redis_set(test_key, test_value);
|
||||
assert_true(set_result, "Should be able to set a key");
|
||||
print("✓ Set key");
|
||||
|
||||
let get_result = redis_get(test_key);
|
||||
assert_true(get_result == test_value, "Should be able to get the key");
|
||||
print("✓ Got key");
|
||||
|
||||
// Clean up
|
||||
let del_result = redis_del(test_key);
|
||||
assert_true(del_result, "Should be able to delete the key");
|
||||
print("✓ Deleted test key");
|
||||
|
||||
print("--- Redis Authentication Tests completed successfully ---");
|
||||
passed += 1;
|
||||
} catch(err) {
|
||||
print(`!!! Error in Redis Authentication Tests: ${err}`);
|
||||
failed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
print("\n=== Test Summary ===");
|
||||
print(`Passed: ${passed}`);
|
||||
print(`Failed: ${failed}`);
|
||||
print(`Skipped: ${skipped}`);
|
||||
print(`Total: ${passed + failed + skipped}`);
|
||||
|
||||
if failed == 0 {
|
||||
if skipped > 0 {
|
||||
print("\n⚠️ All tests skipped or passed!");
|
||||
} else {
|
||||
print("\n✅ All tests passed!");
|
||||
}
|
||||
} else {
|
||||
print("\n❌ Some tests failed!");
|
||||
}
|
||||
|
||||
// Return the number of failed tests (0 means success)
|
||||
failed;
|
Reference in New Issue
Block a user