chore: turn clippy on for test code (#4817)
This commit is contained in:
@@ -192,7 +192,7 @@ response:
|
||||
let url = result.unwrap();
|
||||
assert!(url.starts_with("goose://recipe?config="));
|
||||
let encoded_part = url.strip_prefix("goose://recipe?config=").unwrap();
|
||||
assert!(encoded_part.len() > 0);
|
||||
assert!(!encoded_part.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -248,7 +248,7 @@ mod tests {
|
||||
);
|
||||
|
||||
// Create a proper temporary directory that will be automatically cleaned up
|
||||
let _temp_dir = TempDir::with_prefix(&format!("goose_test_{}_", test_id)).unwrap();
|
||||
let _temp_dir = TempDir::with_prefix(format!("goose_test_{}_", test_id)).unwrap();
|
||||
let test_dir = _temp_dir.path();
|
||||
|
||||
// Set up environment
|
||||
@@ -275,7 +275,7 @@ mod tests {
|
||||
if log_dir.exists() {
|
||||
for entry in std::fs::read_dir(&log_dir).unwrap() {
|
||||
let entry = entry.unwrap();
|
||||
if entry.path().extension().map_or(false, |ext| ext == "log") {
|
||||
if entry.path().extension().is_some_and(|ext| ext == "log") {
|
||||
std::fs::remove_file(entry.path()).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -315,7 +315,7 @@ mod tests {
|
||||
|
||||
let log_count = all_files
|
||||
.iter()
|
||||
.filter(|e| e.path().extension().map_or(false, |ext| ext == "log"))
|
||||
.filter(|e| e.path().extension().is_some_and(|ext| ext == "log"))
|
||||
.count();
|
||||
|
||||
println!("Found {} log files in directory", log_count);
|
||||
@@ -358,8 +358,8 @@ mod tests {
|
||||
.iter()
|
||||
.filter(|e| {
|
||||
let path = e.path();
|
||||
let matches = path.extension().map_or(false, |ext| ext == "log")
|
||||
&& path.file_name().map_or(false, |name| {
|
||||
let matches = path.extension().is_some_and(|ext| ext == "log")
|
||||
&& path.file_name().is_some_and(|name| {
|
||||
let name = name.to_string_lossy();
|
||||
if let Some(session) = session_name {
|
||||
name.ends_with(&format!("{}.log", session))
|
||||
@@ -411,7 +411,7 @@ mod tests {
|
||||
})
|
||||
.collect();
|
||||
|
||||
log_files.sort_by(|a, b| a.file_name().cmp(&b.file_name()));
|
||||
log_files.sort_by_key(|a| a.file_name());
|
||||
assert_eq!(log_files.len(), 1, "Expected exactly one matching log file");
|
||||
|
||||
let log_file_name = log_files[0].file_name().to_string_lossy().into_owned();
|
||||
|
||||
@@ -14,9 +14,11 @@ use std::collections::HashMap;
|
||||
use tokio::sync::mpsc::{self, Receiver};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
type Handler = Box<dyn Fn(&Value) -> Result<Vec<Content>, ErrorData> + Send + Sync>;
|
||||
|
||||
pub struct MockClient {
|
||||
tools: HashMap<String, Tool>,
|
||||
handlers: HashMap<String, Box<dyn Fn(&Value) -> Result<Vec<Content>, ErrorData> + Send + Sync>>,
|
||||
handlers: HashMap<String, Handler>,
|
||||
}
|
||||
|
||||
impl MockClient {
|
||||
|
||||
@@ -180,7 +180,7 @@ where
|
||||
|
||||
let original_env = setup_environment(config)?;
|
||||
|
||||
let inner_provider = create(&factory_name, ModelConfig::new(&config.model_name)?)?;
|
||||
let inner_provider = create(&factory_name, ModelConfig::new(config.model_name)?)?;
|
||||
|
||||
let test_provider = Arc::new(TestProvider::new_recording(inner_provider, &file_path));
|
||||
(
|
||||
|
||||
@@ -443,18 +443,14 @@ mod tests {
|
||||
let mut cache = CompletionCache::new();
|
||||
|
||||
// Add some test prompts
|
||||
let mut extension1_prompts = Vec::new();
|
||||
extension1_prompts.push("test_prompt1".to_string());
|
||||
extension1_prompts.push("test_prompt2".to_string());
|
||||
cache
|
||||
.prompts
|
||||
.insert("extension1".to_string(), extension1_prompts);
|
||||
cache.prompts.insert(
|
||||
"extension1".to_string(),
|
||||
vec!["test_prompt1".to_string(), "test_prompt2".to_string()],
|
||||
);
|
||||
|
||||
let mut extension2_prompts = Vec::new();
|
||||
extension2_prompts.push("other_prompt".to_string());
|
||||
cache
|
||||
.prompts
|
||||
.insert("extension2".to_string(), extension2_prompts);
|
||||
.insert("extension2".to_string(), vec!["other_prompt".to_string()]);
|
||||
|
||||
// Add prompt info with arguments
|
||||
let test_prompt1_args = vec![
|
||||
@@ -519,7 +515,7 @@ mod tests {
|
||||
let (pos, candidates) = completer.complete_slash_commands("/e").unwrap();
|
||||
assert_eq!(pos, 0);
|
||||
// There might be multiple commands starting with "e" like "/exit" and "/extension"
|
||||
assert!(candidates.len() >= 1);
|
||||
assert!(!candidates.is_empty());
|
||||
|
||||
// Test multiple matches
|
||||
let (pos, candidates) = completer.complete_slash_commands("/").unwrap();
|
||||
|
||||
@@ -34,7 +34,7 @@ fn test_format_result_data_for_display() {
|
||||
assert_eq!(format_result_data_for_display(&json!(true)), "true");
|
||||
assert_eq!(format_result_data_for_display(&json!(false)), "false");
|
||||
assert_eq!(format_result_data_for_display(&json!(42)), "42");
|
||||
assert_eq!(format_result_data_for_display(&json!(3.14)), "3.14");
|
||||
assert_eq!(format_result_data_for_display(&json!(3.41)), "3.41");
|
||||
assert_eq!(format_result_data_for_display(&json!(null)), "null");
|
||||
|
||||
let partial_obj = json!({
|
||||
|
||||
Reference in New Issue
Block a user