codex-memory 3.0.15

A simple memory storage service with MCP interface for Claude Desktop
Documentation
use codex_memory::Error;

#[test]
fn test_error_display() {
    // Config error with string
    let config_error = Error::Config("missing variable".to_string());
    assert_eq!(
        config_error.to_string(),
        "Configuration error: missing variable"
    );

    // Other error with string
    let other_error = Error::Other("something went wrong".to_string());
    assert_eq!(other_error.to_string(), "Error: something went wrong");
}

#[test]
fn test_error_from_io() {
    use std::io;

    let io_error = io::Error::new(io::ErrorKind::NotFound, "file not found");
    let error: Error = io_error.into();

    match error {
        Error::Io(e) => assert_eq!(e.kind(), io::ErrorKind::NotFound),
        _ => panic!("Should be Io variant"),
    }
}

#[test]
fn test_error_from_serde_json() {
    let json_str = "{ invalid json }";
    let result: Result<serde_json::Value, _> = serde_json::from_str(json_str);

    if let Err(e) = result {
        let error: Error = e.into();
        match error {
            Error::Json(_) => (), // Json error variant exists
            _ => panic!("Should be Json variant"),
        }
    }
}

#[test]
fn test_error_from_anyhow() {
    let anyhow_error = anyhow::anyhow!("custom error");
    let error: Error = anyhow_error.into();

    match error {
        Error::Other(msg) => assert_eq!(msg, "custom error"),
        _ => panic!("Should be Other variant"),
    }
}

#[test]
fn test_error_debug_format() {
    let error = Error::Config("test error".to_string());
    let debug_str = format!("{:?}", error);

    // Debug format should contain the variant name
    assert!(debug_str.contains("Config"));
    assert!(debug_str.contains("test error"));
}