style: format code and reorganize imports across rfsclient codebase
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! Integration tests for RFS client Rhai wrappers
|
||||
//!
|
||||
//! These tests verify that the Rhai wrappers work correctly with the RFS client.
|
||||
//!
|
||||
//!
|
||||
//! Test Categories:
|
||||
//! - Unit tests: Test wrapper logic without requiring a running server
|
||||
//! - Integration tests: Test with a real RFS server (when available)
|
||||
@@ -15,7 +15,14 @@ use tempfile::NamedTempFile;
|
||||
fn is_server_running(url: &str) -> bool {
|
||||
// Try to make a simple HTTP request to check if server is available
|
||||
match std::process::Command::new("curl")
|
||||
.args(["-s", "-o", "/dev/null", "-w", "%{http_code}", &format!("{}/api/v1", url)])
|
||||
.args([
|
||||
"-s",
|
||||
"-o",
|
||||
"/dev/null",
|
||||
"-w",
|
||||
"%{http_code}",
|
||||
&format!("{}/api/v1", url),
|
||||
])
|
||||
.output()
|
||||
{
|
||||
Ok(output) => {
|
||||
@@ -39,15 +46,15 @@ const TEST_PASSWORD: &str = "password";
|
||||
fn test_rhai_engine_setup() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Test that we can create a client successfully
|
||||
let script = r#"
|
||||
rfs_create_client("http://localhost:8080", "user", "password", 30)
|
||||
"#;
|
||||
|
||||
|
||||
let result: bool = engine.eval(script)?;
|
||||
assert!(result);
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -56,15 +63,15 @@ fn test_rhai_engine_setup() -> Result<(), Box<EvalAltResult>> {
|
||||
fn test_rfs_create_client() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
let script = r#"
|
||||
let result = rfs_create_client("http://localhost:8080", "user", "password", 30);
|
||||
result
|
||||
"#;
|
||||
|
||||
|
||||
let result: bool = engine.eval(script)?;
|
||||
assert!(result);
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -73,15 +80,15 @@ fn test_rfs_create_client() -> Result<(), Box<EvalAltResult>> {
|
||||
fn test_rfs_create_client_no_credentials() -> Result<(), Box<EvalAltResult>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
let script = r#"
|
||||
let result = rfs_create_client("http://localhost:8080", "", "", 30);
|
||||
result
|
||||
"#;
|
||||
|
||||
|
||||
let result: bool = engine.eval(script)?;
|
||||
assert!(result);
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -92,36 +99,48 @@ fn test_rfs_flist_management_integration() {
|
||||
println!("Skipping FList integration test - no server detected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).expect("Failed to register RFS module");
|
||||
|
||||
|
||||
// Test FList listing with proper credentials
|
||||
let list_script = format!(r#"
|
||||
let list_script = format!(
|
||||
r#"
|
||||
rfs_create_client("{}", "{}", "{}", 30);
|
||||
rfs_authenticate();
|
||||
rfs_list_flists()
|
||||
"#, TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
let result = engine.eval::<String>(&list_script);
|
||||
match result {
|
||||
Ok(flists_json) => {
|
||||
println!("FLists retrieved: {}", flists_json);
|
||||
// Should be valid JSON
|
||||
assert!(serde_json::from_str::<serde_json::Value>(&flists_json).is_ok(),
|
||||
"FList data should be valid JSON");
|
||||
assert!(
|
||||
serde_json::from_str::<serde_json::Value>(&flists_json).is_ok(),
|
||||
"FList data should be valid JSON"
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
let error_msg = e.to_string();
|
||||
println!("FList preview error: {}", error_msg);
|
||||
|
||||
|
||||
// Check if it's an authentication error (shouldn't happen with valid creds)
|
||||
if error_msg.contains("Authentication") {
|
||||
panic!("❌ Authentication should work with valid credentials: {}", error_msg);
|
||||
panic!(
|
||||
"❌ Authentication should work with valid credentials: {}",
|
||||
error_msg
|
||||
);
|
||||
} else {
|
||||
// Other errors are acceptable (not found, permissions, etc.)
|
||||
println!("Server error (may be expected): {}", error_msg);
|
||||
assert!(error_msg.contains("OpenAPI") || error_msg.contains("FList") || error_msg.contains("not found"));
|
||||
assert!(
|
||||
error_msg.contains("OpenAPI")
|
||||
|| error_msg.contains("FList")
|
||||
|| error_msg.contains("not found")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,23 +152,26 @@ fn test_rfs_create_flist_integration() {
|
||||
println!("Skipping FList creation test - no server detected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).expect("Failed to register RFS module");
|
||||
|
||||
|
||||
// Test FList creation with proper authentication
|
||||
let create_script = format!(r#"
|
||||
let create_script = format!(
|
||||
r#"
|
||||
rfs_create_client("{}", "{}", "{}", 30);
|
||||
rfs_authenticate();
|
||||
rfs_create_flist("busybox:latest", "docker.io", "", "")
|
||||
"#, TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
let result = engine.eval::<String>(&create_script);
|
||||
match result {
|
||||
Ok(job_id) => {
|
||||
println!("✅ FList creation job started: {}", job_id);
|
||||
assert!(!job_id.is_empty(), "Job ID should not be empty");
|
||||
|
||||
|
||||
// Test getting FList state with the job ID
|
||||
let state_script = format!("rfs_get_flist_state(\"{}\")", job_id);
|
||||
let state_result = engine.eval::<String>(&state_script);
|
||||
@@ -166,12 +188,15 @@ fn test_rfs_create_flist_integration() {
|
||||
Err(e) => {
|
||||
let error_msg = e.to_string();
|
||||
println!("FList creation error: {}", error_msg);
|
||||
|
||||
|
||||
// Check if it's a 409 Conflict (FList already exists) - this is acceptable
|
||||
if error_msg.contains("409 Conflict") {
|
||||
println!("✅ FList already exists (409 Conflict) - this is expected behavior");
|
||||
} else if error_msg.contains("Authentication") {
|
||||
panic!("❌ Authentication should work with valid credentials: {}", error_msg);
|
||||
panic!(
|
||||
"❌ Authentication should work with valid credentials: {}",
|
||||
error_msg
|
||||
);
|
||||
} else {
|
||||
// Other server errors are acceptable (permissions, etc.)
|
||||
println!("Server error (may be expected): {}", error_msg);
|
||||
@@ -187,17 +212,20 @@ fn test_rfs_preview_flist_integration() {
|
||||
println!("Skipping FList preview test - no server detected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).expect("Failed to register RFS module");
|
||||
|
||||
|
||||
// Test FList preview with proper authentication and correct path format
|
||||
let preview_script = format!(r#"
|
||||
let preview_script = format!(
|
||||
r#"
|
||||
rfs_create_client("{}", "{}", "{}", 30);
|
||||
rfs_authenticate();
|
||||
rfs_preview_flist("flists/user/alpine-latest.fl")
|
||||
"#, TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
let result = engine.eval::<String>(&preview_script);
|
||||
match result {
|
||||
Ok(preview_json) => {
|
||||
@@ -206,10 +234,17 @@ fn test_rfs_preview_flist_integration() {
|
||||
}
|
||||
Err(e) => {
|
||||
let error_msg = e.to_string();
|
||||
println!("Expected FList preview error (not found/auth): {}", error_msg);
|
||||
println!(
|
||||
"Expected FList preview error (not found/auth): {}",
|
||||
error_msg
|
||||
);
|
||||
// Should be a proper server error
|
||||
assert!(error_msg.contains("Authentication") || error_msg.contains("OpenAPI") ||
|
||||
error_msg.contains("FList") || error_msg.contains("not found"));
|
||||
assert!(
|
||||
error_msg.contains("Authentication")
|
||||
|| error_msg.contains("OpenAPI")
|
||||
|| error_msg.contains("FList")
|
||||
|| error_msg.contains("not found")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,12 +254,12 @@ fn test_rfs_preview_flist_integration() {
|
||||
fn test_rfs_get_system_info_wrapper() {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
let script = r#"
|
||||
rfs_create_client("http://localhost:8080", "", "", 30);
|
||||
rfs_get_system_info()
|
||||
"#;
|
||||
|
||||
|
||||
let result = engine.eval::<String>(script);
|
||||
match result {
|
||||
Ok(info) => {
|
||||
@@ -246,12 +281,12 @@ fn test_rfs_get_system_info_wrapper() {
|
||||
fn test_rfs_authenticate_wrapper() {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
let script = r#"
|
||||
rfs_create_client("http://localhost:8080", "user", "password", 30);
|
||||
rfs_authenticate()
|
||||
"#;
|
||||
|
||||
|
||||
let result = engine.eval::<bool>(script);
|
||||
match result {
|
||||
Ok(success) => {
|
||||
@@ -273,17 +308,20 @@ fn test_rfs_authenticate_wrapper() {
|
||||
fn test_rfs_upload_file_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a temporary file for testing
|
||||
let temp_file = NamedTempFile::new()?;
|
||||
fs::write(&temp_file, b"test content")?;
|
||||
let file_path = temp_file.path().to_string_lossy();
|
||||
|
||||
let script = format!(r#"
|
||||
|
||||
let script = format!(
|
||||
r#"
|
||||
rfs_create_client("http://localhost:8080", "", "", 30);
|
||||
rfs_upload_file("{}", 0, false)
|
||||
"#, file_path);
|
||||
|
||||
"#,
|
||||
file_path
|
||||
);
|
||||
|
||||
let result = engine.eval::<String>(&script);
|
||||
match result {
|
||||
Ok(upload_result) => {
|
||||
@@ -298,7 +336,7 @@ fn test_rfs_upload_file_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
assert!(error_msg.contains("RFS error") || error_msg.contains("OpenAPI"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -307,7 +345,7 @@ fn test_rfs_upload_file_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_complete_rhai_script() {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
let script = r#"
|
||||
// Create client
|
||||
let client_created = rfs_create_client("http://localhost:8080", "user", "password", 60);
|
||||
@@ -315,7 +353,7 @@ fn test_complete_rhai_script() {
|
||||
// Return success if we got this far
|
||||
client_created
|
||||
"#;
|
||||
|
||||
|
||||
let result: bool = engine.eval(script).unwrap();
|
||||
assert!(result);
|
||||
}
|
||||
@@ -325,17 +363,17 @@ fn test_complete_rhai_script() {
|
||||
fn test_error_handling() {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
// Test calling a protected endpoint without authentication - should fail
|
||||
// Note: get_system_info is NOT protected, but create_flist IS protected
|
||||
let script = r#"
|
||||
rfs_create_client("http://localhost:8080", "", "", 30);
|
||||
rfs_create_flist("test:latest", "docker.io", "", "")
|
||||
"#;
|
||||
|
||||
|
||||
let result = engine.eval::<String>(script);
|
||||
assert!(result.is_err());
|
||||
|
||||
|
||||
// Check that the error message contains authentication error
|
||||
let error_msg = result.unwrap_err().to_string();
|
||||
println!("Expected authentication error: {}", error_msg);
|
||||
@@ -347,23 +385,26 @@ fn test_error_handling() {
|
||||
fn test_rfs_is_authenticated_wrapper() {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
// Test without authenticating first
|
||||
let script1 = r#"
|
||||
rfs_create_client("http://localhost:8080", "", "", 30);
|
||||
rfs_is_authenticated()
|
||||
"#;
|
||||
|
||||
|
||||
let result1 = engine.eval::<bool>(script1).unwrap();
|
||||
assert!(!result1, "Should not be authenticated before calling authenticate()");
|
||||
|
||||
assert!(
|
||||
!result1,
|
||||
"Should not be authenticated before calling authenticate()"
|
||||
);
|
||||
|
||||
// Test after authenticating (may still fail if server requires valid credentials)
|
||||
let script2 = r#"
|
||||
rfs_create_client("http://localhost:8080", "user", "password", 30);
|
||||
rfs_authenticate();
|
||||
rfs_is_authenticated()
|
||||
"#;
|
||||
|
||||
|
||||
let result2 = engine.eval::<bool>(script2);
|
||||
match result2 {
|
||||
Ok(auth_status) => {
|
||||
@@ -382,12 +423,12 @@ fn test_rfs_is_authenticated_wrapper() {
|
||||
fn test_rfs_health_check_wrapper() {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
let script = r#"
|
||||
rfs_create_client("http://localhost:8080", "", "", 30);
|
||||
rfs_health_check()
|
||||
"#;
|
||||
|
||||
|
||||
let result = engine.eval::<String>(script);
|
||||
match result {
|
||||
Ok(health_status) => {
|
||||
@@ -400,9 +441,9 @@ fn test_rfs_health_check_wrapper() {
|
||||
println!("Health check error (may be expected): {}", error_msg);
|
||||
// Acceptable errors if server is not running or requires auth
|
||||
assert!(
|
||||
error_msg.contains("RFS error") ||
|
||||
error_msg.contains("OpenAPI") ||
|
||||
error_msg.contains("failed")
|
||||
error_msg.contains("RFS error")
|
||||
|| error_msg.contains("OpenAPI")
|
||||
|| error_msg.contains("failed")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -415,17 +456,20 @@ fn test_rfs_get_website_wrapper() {
|
||||
println!("Skipping website test - no server detected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
// Test with a non-existent website (should fail gracefully)
|
||||
let script = format!(r#"
|
||||
let script = format!(
|
||||
r#"
|
||||
rfs_create_client("{}", "{}", "{}", 30);
|
||||
rfs_authenticate();
|
||||
rfs_get_website("nonexistent-website", "index.html")
|
||||
"#, TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
let result = engine.eval::<String>(&script);
|
||||
match result {
|
||||
Ok(content) => {
|
||||
@@ -437,10 +481,10 @@ fn test_rfs_get_website_wrapper() {
|
||||
let error_msg = e.to_string();
|
||||
println!("Expected website error: {}", error_msg);
|
||||
assert!(
|
||||
error_msg.contains("404") ||
|
||||
error_msg.contains("not found") ||
|
||||
error_msg.contains("OpenAPI") ||
|
||||
error_msg.contains("RFS error")
|
||||
error_msg.contains("404")
|
||||
|| error_msg.contains("not found")
|
||||
|| error_msg.contains("OpenAPI")
|
||||
|| error_msg.contains("RFS error")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -455,7 +499,7 @@ fn test_rfs_get_website_wrapper() {
|
||||
fn test_rfs_list_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -463,10 +507,10 @@ fn test_rfs_list_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Authenticate before invoking operations that require it
|
||||
let auth_script = r#"
|
||||
rfs_authenticate()
|
||||
@@ -481,10 +525,10 @@ fn test_rfs_list_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
true
|
||||
"#;
|
||||
|
||||
|
||||
let result: bool = engine.eval(list_script)?;
|
||||
assert!(result, "Failed to list blocks");
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -493,7 +537,7 @@ fn test_rfs_list_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_rfs_download_block_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -501,18 +545,18 @@ fn test_rfs_download_block_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Authenticate before invoking operations that require it
|
||||
let authed: bool = engine.eval(r#" rfs_authenticate() "#)?;
|
||||
assert!(authed, "Authentication failed in download wrapper test");
|
||||
|
||||
|
||||
// Create a temporary file for download
|
||||
let temp_file = NamedTempFile::new()?;
|
||||
let temp_path = temp_file.path().to_str().unwrap();
|
||||
|
||||
|
||||
// Test downloading a block (assuming test block hash exists)
|
||||
let download_script = format!(
|
||||
r#"
|
||||
@@ -522,13 +566,13 @@ fn test_rfs_download_block_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}}
|
||||
true
|
||||
"#,
|
||||
temp_path.replace('\\', "\\\\") // Escape backslashes for Windows paths
|
||||
temp_path.replace('\\', "\\\\") // Escape backslashes for Windows paths
|
||||
);
|
||||
|
||||
|
||||
// This might fail if the test block doesn't exist, but we're testing the wrapper, not the actual download
|
||||
let result: bool = engine.eval(&download_script).unwrap_or_else(|_| true);
|
||||
assert!(result, "Failed to execute download block script");
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -537,7 +581,7 @@ fn test_rfs_download_block_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_rfs_verify_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -545,10 +589,10 @@ fn test_rfs_verify_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Test verifying blocks with a test hash
|
||||
let verify_script = r#"
|
||||
let hashes = "[\"test_block_hash\"]";
|
||||
@@ -558,10 +602,10 @@ fn test_rfs_verify_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}}
|
||||
true
|
||||
"#;
|
||||
|
||||
|
||||
let result: bool = engine.eval(verify_script)?;
|
||||
assert!(result, "Failed to verify blocks");
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -570,7 +614,7 @@ fn test_rfs_verify_blocks_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_rfs_get_block_info_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -578,10 +622,10 @@ fn test_rfs_get_block_info_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Test getting block info with a test hash
|
||||
let info_script = r#"
|
||||
let result = rfs_get_blocks_by_hash("test_block_hash");
|
||||
@@ -590,7 +634,7 @@ fn test_rfs_get_block_info_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
true
|
||||
"#;
|
||||
|
||||
|
||||
match engine.eval::<bool>(info_script) {
|
||||
Ok(result) => {
|
||||
assert!(result, "Failed to get block info");
|
||||
@@ -600,10 +644,10 @@ fn test_rfs_get_block_info_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let error_msg = e.to_string();
|
||||
println!("Block info error (may be expected): {}", error_msg);
|
||||
assert!(
|
||||
error_msg.contains("404") ||
|
||||
error_msg.contains("not found") ||
|
||||
error_msg.contains("OpenAPI") ||
|
||||
error_msg.contains("RFS error")
|
||||
error_msg.contains("404")
|
||||
|| error_msg.contains("not found")
|
||||
|| error_msg.contains("OpenAPI")
|
||||
|| error_msg.contains("RFS error")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -619,7 +663,7 @@ fn test_rfs_get_block_info_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_rfs_download_file_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -627,14 +671,14 @@ fn test_rfs_download_file_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Create a temporary file for download
|
||||
let temp_file = NamedTempFile::new()?;
|
||||
let temp_path = temp_file.path().to_str().unwrap();
|
||||
|
||||
|
||||
// Test downloading a file (assuming test file hash exists)
|
||||
let download_script = format!(
|
||||
r#"
|
||||
@@ -645,13 +689,13 @@ fn test_rfs_download_file_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}}
|
||||
true
|
||||
"#,
|
||||
temp_path.replace('\\', "\\\\") // Escape backslashes for Windows paths
|
||||
temp_path.replace('\\', "\\\\") // Escape backslashes for Windows paths
|
||||
);
|
||||
|
||||
|
||||
// This might fail if the test file doesn't exist, but we're testing the wrapper
|
||||
let result: bool = engine.eval(&download_script).unwrap_or_else(|_| true);
|
||||
assert!(result, "Failed to execute download file script");
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -678,7 +722,7 @@ fn test_flist_operations_workflow() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let temp_dir = tempfile::tempdir()?;
|
||||
let output_path = temp_dir.path().join("downloaded_flist.fl");
|
||||
let output_path_str = output_path.to_str().unwrap();
|
||||
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).expect("Failed to register RFS module");
|
||||
|
||||
@@ -808,19 +852,19 @@ fn test_flist_operations_workflow() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
// Add a helper function to parse JSON in Rhai
|
||||
engine.register_fn("parse_json", |json_str: &str| -> String {
|
||||
// Just return the JSON string as is - Rhai can work with it directly
|
||||
json_str.to_string()
|
||||
});
|
||||
|
||||
|
||||
// Execute the script
|
||||
match engine.eval::<bool>(&script) {
|
||||
Ok(success) => {
|
||||
assert!(success, "FList operations workflow test failed");
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error in FList operations workflow test: {}", e);
|
||||
// Don't fail the test if the server doesn't have the expected data
|
||||
@@ -843,7 +887,7 @@ fn test_flist_operations_workflow() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_rfs_download_flist_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -851,14 +895,14 @@ fn test_rfs_download_flist_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Create a temporary file for download
|
||||
let temp_file = NamedTempFile::new()?;
|
||||
let temp_path = temp_file.path().to_str().unwrap();
|
||||
|
||||
|
||||
// Test downloading an FList (assuming test flist exists)
|
||||
let download_script = format!(
|
||||
r#"
|
||||
@@ -868,13 +912,13 @@ fn test_rfs_download_flist_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}}
|
||||
true
|
||||
"#,
|
||||
temp_path.replace('\\', "\\\\") // Escape backslashes for Windows paths
|
||||
temp_path.replace('\\', "\\\\") // Escape backslashes for Windows paths
|
||||
);
|
||||
|
||||
|
||||
// This might fail if the test flist doesn't exist, but we're testing the wrapper
|
||||
let result: bool = engine.eval(&download_script).unwrap_or_else(|_| true);
|
||||
assert!(result, "Failed to execute download flist script");
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -883,7 +927,7 @@ fn test_rfs_download_flist_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn test_rfs_wait_for_flist_creation_wrapper() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine)?;
|
||||
|
||||
|
||||
// Create a client first
|
||||
let create_script = format!(
|
||||
r#"
|
||||
@@ -891,14 +935,14 @@ fn test_rfs_wait_for_flist_creation_wrapper() -> Result<(), Box<dyn std::error::
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
|
||||
let result: bool = engine.eval(&create_script)?;
|
||||
assert!(result, "Failed to create RFS client");
|
||||
|
||||
|
||||
// Authenticate before invoking operations that require it
|
||||
let authed: bool = engine.eval(r#" rfs_authenticate() "#)?;
|
||||
assert!(authed, "Authentication failed in wait wrapper test");
|
||||
|
||||
|
||||
// Intentionally use a dummy job id and assert the wrapper returns a meaningful error
|
||||
let wait_script = r#"
|
||||
// This call should fail because the job id is dummy; we want to see the error path
|
||||
@@ -907,13 +951,20 @@ fn test_rfs_wait_for_flist_creation_wrapper() -> Result<(), Box<dyn std::error::
|
||||
|
||||
let eval_res = engine.eval::<String>(wait_script);
|
||||
match eval_res {
|
||||
Ok(s) => panic!("Expected failure for dummy job id, but got success with result: {}", s),
|
||||
Ok(s) => panic!(
|
||||
"Expected failure for dummy job id, but got success with result: {}",
|
||||
s
|
||||
),
|
||||
Err(e) => {
|
||||
let msg = e.to_string();
|
||||
assert!(msg.contains("Operation timed out"), "Unexpected error message: {}", msg);
|
||||
assert!(
|
||||
msg.contains("Operation timed out"),
|
||||
"Unexpected error message: {}",
|
||||
msg
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -925,18 +976,24 @@ fn test_rfs_wait_for_flist_creation_wrapper() -> Result<(), Box<dyn std::error::
|
||||
#[test]
|
||||
fn test_rfs_get_system_info_with_server() {
|
||||
if !is_server_running(TEST_SERVER_URL) {
|
||||
println!("Skipping integration test - no RFS server running at {}", TEST_SERVER_URL);
|
||||
println!(
|
||||
"Skipping integration test - no RFS server running at {}",
|
||||
TEST_SERVER_URL
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
let script = format!(r#"
|
||||
|
||||
let script = format!(
|
||||
r#"
|
||||
rfs_create_client("{}", "", "", 30);
|
||||
rfs_get_system_info()
|
||||
"#, TEST_SERVER_URL);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL
|
||||
);
|
||||
|
||||
let result = engine.eval::<String>(&script);
|
||||
match result {
|
||||
Ok(info) => {
|
||||
@@ -954,19 +1011,25 @@ fn test_rfs_get_system_info_with_server() {
|
||||
#[test]
|
||||
fn test_rfs_authenticate_with_server() {
|
||||
if !is_server_running(TEST_SERVER_URL) {
|
||||
println!("Skipping integration test - no RFS server running at {}", TEST_SERVER_URL);
|
||||
println!(
|
||||
"Skipping integration test - no RFS server running at {}",
|
||||
TEST_SERVER_URL
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
|
||||
// Test with dummy credentials (will likely fail, but tests the flow)
|
||||
let script = format!(r#"
|
||||
let script = format!(
|
||||
r#"
|
||||
rfs_create_client("{}", "{}", "{}", 30);
|
||||
rfs_authenticate()
|
||||
"#, TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL, TEST_USERNAME, TEST_PASSWORD
|
||||
);
|
||||
|
||||
let result = engine.eval::<bool>(&script);
|
||||
match result {
|
||||
Ok(success) => {
|
||||
@@ -974,7 +1037,10 @@ fn test_rfs_authenticate_with_server() {
|
||||
assert!(success);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Expected authentication failure with dummy credentials: {}", e);
|
||||
println!(
|
||||
"Expected authentication failure with dummy credentials: {}",
|
||||
e
|
||||
);
|
||||
// This is expected with dummy credentials
|
||||
assert!(e.to_string().contains("Authentication failed"));
|
||||
}
|
||||
@@ -985,14 +1051,18 @@ fn test_rfs_authenticate_with_server() {
|
||||
#[test]
|
||||
fn test_complete_workflow_with_server() {
|
||||
if !is_server_running(TEST_SERVER_URL) {
|
||||
println!("Skipping integration test - no RFS server running at {}", TEST_SERVER_URL);
|
||||
println!(
|
||||
"Skipping integration test - no RFS server running at {}",
|
||||
TEST_SERVER_URL
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut engine = Engine::new();
|
||||
register_rfs_module(&mut engine).unwrap();
|
||||
|
||||
let script = format!(r#"
|
||||
|
||||
let script = format!(
|
||||
r#"
|
||||
// Create client
|
||||
let client_created = rfs_create_client("{}", "", "", 60);
|
||||
print("Client created: " + client_created);
|
||||
@@ -1003,8 +1073,10 @@ fn test_complete_workflow_with_server() {
|
||||
|
||||
// Return success
|
||||
client_created && info_result.len() > 0
|
||||
"#, TEST_SERVER_URL);
|
||||
|
||||
"#,
|
||||
TEST_SERVER_URL
|
||||
);
|
||||
|
||||
let result = engine.eval::<bool>(&script);
|
||||
match result {
|
||||
Ok(success) => {
|
||||
|
Reference in New Issue
Block a user