gitbutler/gitbutler-app/tests/projects.rs

70 lines
1.8 KiB
Rust
Raw Normal View History

2023-12-05 17:58:43 +03:00
mod common;
2023-10-12 11:36:48 +03:00
2023-12-05 17:58:43 +03:00
use self::common::paths;
use gblib::projects::Controller;
2023-10-12 11:36:48 +03:00
pub fn new() -> Controller {
let data_dir = paths::data_dir();
Controller::from(&data_dir)
}
mod add {
use super::*;
#[test]
fn success() {
let controller = new();
2023-10-12 15:25:01 +03:00
let repository = common::TestProject::default();
let path = repository.path();
2023-10-12 11:36:48 +03:00
let project = controller.add(path).unwrap();
assert_eq!(project.path, path);
assert_eq!(project.title, path.iter().last().unwrap().to_str().unwrap());
}
mod error {
use gblib::projects::AddError;
2023-10-12 11:59:52 +03:00
2023-10-12 11:36:48 +03:00
use super::*;
#[test]
fn missing() {
let controller = new();
let path = tempfile::tempdir().unwrap().into_path();
2023-10-12 11:59:52 +03:00
assert!(matches!(
controller.add(&path.join("missing")),
Err(AddError::PathNotFound)
));
2023-10-12 11:36:48 +03:00
}
#[test]
fn not_git() {
let controller = new();
let path = tempfile::tempdir().unwrap().into_path();
std::fs::write(path.join("file.txt"), "hello world").unwrap();
2023-10-12 11:59:52 +03:00
assert!(matches!(
controller.add(&path),
Err(AddError::NotAGitRepository)
));
2023-10-12 11:36:48 +03:00
}
#[test]
fn empty() {
let controller = new();
let path = tempfile::tempdir().unwrap().into_path();
2023-10-12 11:59:52 +03:00
assert!(matches!(
controller.add(&path),
Err(AddError::NotAGitRepository)
));
2023-10-12 11:36:48 +03:00
}
#[test]
fn twice() {
let controller = new();
2023-10-12 15:25:01 +03:00
let repository = common::TestProject::default();
let path = repository.path();
2023-10-12 11:36:48 +03:00
controller.add(path).unwrap();
2023-10-12 11:59:52 +03:00
assert!(matches!(controller.add(path), Err(AddError::AlreadyExists)));
2023-10-12 11:36:48 +03:00
}
}
}