#[ allow( unused_imports ) ]
use super::*;
use std::env;
#[ test ]
#[ cfg( feature = "integration" ) ]
#[ allow( clippy::too_many_lines ) ]
fn test_error_handling_integration()
{
println!("๐งช Manual Testing : Error Handling When No Secrets Available");
println!("==========================================================");
println!("\n๐งน Step 1: Removing environment variable...");
env::remove_var("ANTHROPIC_API_KEY");
println!("โ
ANTHROPIC_API_KEY environment variable removed");
println!("\n๐ Step 2: Temporarily removing workspace secret file...");
let secret_file = std::path::Path::new("../../secret/-secrets.sh");
let backup_file = std::path::Path::new("../../secret/-secrets.sh.backup.test");
let file_existed = if secret_file.exists()
{
std::fs::rename(secret_file, backup_file).expect("INTEGRATION: File operation must succeed");
println!("โ
Workspace secret file moved to backup");
true
} else {
println!("โน๏ธ Workspace secret file doesn't exist");
false
};
println!("\n๐ Step 3: Testing Secret::from_workspace() error handling...");
match the_module::Secret::from_workspace()
{
Ok(_secret) => {
println!("โ Unexpected : Secret::from_workspace() succeeded when no secrets should be available!");
},
Err(e) => {
println!("โ
Secret::from_workspace() correctly failed with error:");
println!(" ๐ Error : {e}");
let error_msg = e.to_string();
if error_msg.contains("ANTHROPIC_API_KEY") && error_msg.contains("-secrets.sh")
{
println!("โ
Error message contains helpful information about both workspace file and environment variable");
} else {
println!("โ ๏ธ Error message could be more helpful");
}
}
}
println!("\n๐ง Step 4: Testing Client::from_workspace() error handling...");
match the_module::Client::from_workspace()
{
Ok(_client) => {
println!("โ Unexpected : Client::from_workspace() succeeded when no secrets should be available!");
},
Err(e) => {
println!("โ
Client::from_workspace() correctly failed with error:");
println!(" ๐ Error : {e}");
}
}
println!("\n๐ Step 5: Testing Secret::load_from_workspace() with non-existent file...");
match the_module::Secret::load_from_workspace("ANTHROPIC_API_KEY", "-nonexistent-file.sh")
{
Ok(_secret) => {
println!("โ Unexpected : load_from_workspace succeeded with non-existent file!");
},
Err(e) => {
println!("โ
load_from_workspace correctly failed with non-existent file:");
println!(" ๐ Error : {e}");
}
}
println!("\n๐ Step 6: Testing Secret::load_from_workspace() with invalid key...");
if file_existed
{
std::fs::rename(backup_file, secret_file).expect("INTEGRATION: File operation must succeed");
}
match the_module::Secret::load_from_workspace("INVALID_KEY_NAME", "-secrets.sh")
{
Ok(_secret) => {
println!("โ Unexpected : load_from_workspace succeeded with invalid key name!");
},
Err(e) => {
println!("โ
load_from_workspace correctly failed with invalid key name:");
println!(" ๐ Error : {e}");
}
}
if file_existed
{
std::fs::rename(secret_file, backup_file).expect("INTEGRATION: File operation must succeed");
}
println!("\n๐ Step 7: Testing Secret::load_from_env() with no environment variable...");
match the_module::Secret::load_from_env("ANTHROPIC_API_KEY")
{
Ok(_secret) => {
println!("โ Unexpected : load_from_env succeeded when no env var is set!");
},
Err(e) => {
println!("โ
load_from_env correctly failed:");
println!(" ๐ Error : {e}");
}
}
if file_existed
{
println!("\n๐ Step 8: Restoring workspace secret file...");
std::fs::rename(backup_file, secret_file).expect("INTEGRATION: File operation must succeed");
println!("โ
Workspace secret file restored");
match the_module::Secret::from_workspace()
{
Ok(_secret) => {
println!("โ
Secret loading working again after restoration");
},
Err(e) => {
println!("โ ๏ธ Secret loading still failing after restoration : {e}");
}
}
}
println!("\n๐ Error handling testing completed!");
println!("\n๐ Summary:");
println!(" โ
All methods correctly fail when no secrets are available");
println!(" โ
Error messages provide helpful information");
println!(" โ
System gracefully handles missing files and environment variables");
println!(" โ
Restoration works correctly");
}