#[ cfg( test ) ]
mod tests
{
use api_ollama::{ OllamaClient, ChatMessage, MessageRole };
#[ tokio::test ]
async fn test_chatbot_assistant_basic_functionality()
{
let mut client = OllamaClient::new( "http://localhost:11434".to_string(), OllamaClient::recommended_timeout_fast() );
assert!( !client.is_available().await || client.is_available().await );
let message = ChatMessage
{
role : MessageRole::User,
content : "Hello".to_string(),
images : None,
#[ cfg( feature = "tool_calling" ) ]
tool_calls : None,
};
assert_eq!( message.content, "Hello" );
}
#[ tokio::test ]
async fn test_input_loop_doesnt_hang()
{
let mut conversation_history = vec![
ChatMessage
{
role : MessageRole::System,
content : "You are a helpful assistant.".to_string(),
images : None,
#[ cfg( feature = "tool_calling" ) ]
tool_calls : None,
}
];
let user_input = "test input";
conversation_history.push( ChatMessage
{
role : MessageRole::User,
content : user_input.to_string(),
images : None,
#[ cfg( feature = "tool_calling" ) ]
tool_calls : None,
} );
assert_eq!( conversation_history.len(), 2 );
for i in 0..25
{
conversation_history.push( ChatMessage
{
role : MessageRole::User,
content : format!( "Message {i}" ),
images : None,
#[ cfg( feature = "tool_calling" ) ]
tool_calls : None,
} );
}
if conversation_history.len() > 21
{
conversation_history.drain( 1..conversation_history.len() - 20 );
}
assert!( conversation_history.len() <= 21 );
}
#[ tokio::test ]
async fn test_examples_can_initialize_without_hanging()
{
let _client = OllamaClient::new( "http://localhost:11434".to_string(), OllamaClient::recommended_timeout_fast() );
let mut conversation_history = vec![
ChatMessage
{
role : MessageRole::System,
content : "You are a helpful assistant.".to_string(),
images : None,
#[ cfg( feature = "tool_calling" ) ]
tool_calls : None,
}
];
let test_inputs = vec![ "hello", "quit" ];
for input in test_inputs
{
if input == "quit" { break; }
conversation_history.push( ChatMessage
{
role : MessageRole::User,
content : input.to_string(),
images : None,
#[ cfg( feature = "tool_calling" ) ]
tool_calls : None,
} );
}
assert!( conversation_history.len() >= 2 ); }
}