Files
weevil/tests/unit/config_tests.rs
2026-01-31 14:17:51 -06:00

66 lines
2.0 KiB
Rust

// File: tests/config_tests.rs
// Unit tests for project configuration
use weevil::project::ProjectConfig;
use std::path::PathBuf;
use tempfile::TempDir;
use std::fs;
#[test]
fn test_config_create_and_save() {
let temp_dir = TempDir::new().unwrap();
let sdk_path = PathBuf::from("/mock/sdk/path");
let config = ProjectConfig::new("test-robot", sdk_path.clone()).unwrap();
assert_eq!(config.project_name, "test-robot");
assert_eq!(config.ftc_sdk_path, sdk_path);
assert_eq!(config.weevil_version, "1.1.0");
// Save and reload
config.save(temp_dir.path()).unwrap();
let loaded = ProjectConfig::load(temp_dir.path()).unwrap();
assert_eq!(loaded.project_name, config.project_name);
assert_eq!(loaded.ftc_sdk_path, config.ftc_sdk_path);
}
#[test]
fn test_config_load_missing_file() {
let temp_dir = TempDir::new().unwrap();
let result = ProjectConfig::load(temp_dir.path());
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("missing .weevil.toml"));
}
#[test]
fn test_config_toml_format() {
let temp_dir = TempDir::new().unwrap();
let sdk_path = PathBuf::from("/test/sdk");
let config = ProjectConfig::new("my-robot", sdk_path).unwrap();
config.save(temp_dir.path()).unwrap();
let content = fs::read_to_string(temp_dir.path().join(".weevil.toml")).unwrap();
assert!(content.contains("project_name = \"my-robot\""));
assert!(content.contains("weevil_version = \"1.1.0\""));
assert!(content.contains("ftc_sdk_path"));
}
#[test]
fn test_config_update_sdk_path() {
let temp_dir = TempDir::new().unwrap();
let old_sdk = PathBuf::from("/old/sdk");
let new_sdk = PathBuf::from("/new/sdk");
let mut config = ProjectConfig::new("test", old_sdk).unwrap();
// Note: This will fail in tests because SDK doesn't exist
// In real usage, the SDK path is validated
// For now, just test the struct update
config.ftc_sdk_path = new_sdk.clone();
assert_eq!(config.ftc_sdk_path, new_sdk);
}