use gor::commands::init::{Config, create};
use std::{env, fs, path::Path};
#[test]
fn test_build_with_no_args() {
let args = vec!["gor".to_string(), "init".to_string()];
let config = Config::build(&args).unwrap();
assert_eq!(config.file_path, env::current_dir().unwrap().to_str().unwrap());
}
#[test]
fn test_build_with_path() {
let args = vec!["gor".to_string(), "init".to_string(), "custom_test".to_string()];
let config = Config::build(&args).unwrap();
assert_eq!(config.file_path, env::current_dir().unwrap().join(Path::new("custom_test")).to_str().unwrap());
fs::remove_dir_all("custom_test").unwrap();
}
#[test]
fn test_build_not_dir() {
let args = vec!["gor".to_string(), "init".to_string(), "Cargo.toml".to_string()];
let config = Config::build(&args);
assert!(config.is_err());
}
#[test]
fn test_build_already_exists() {
let args = vec!["gor".to_string(), "init".to_string(), "custom_test".to_string()];
let config = Config::build(&args).unwrap();
let _ = create::repo(&config);
let result = Config::build(&args);
assert!(result.is_err());
fs::remove_dir_all("custom_test").unwrap();
}
#[test]
fn test_run() {
let args = vec!["gor".to_string(), "init".to_string(), "custom_test".to_string()];
let config = Config::build(&args).unwrap();
let result = create::repo(&config);
assert!(result.is_ok());
fs::remove_dir_all("custom_test").unwrap();
}