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();
|
2024-02-13 14:16:24 +03:00
|
|
|
Controller::try_from(&data_dir).unwrap()
|
2023-10-12 11:36:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2023-10-18 17:39:14 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|