use std::{ fs::{self, read_to_string}, }; use super::*; macro_rules! test_case { ($fname:expr) => { concat!(env!("CARGO_MANIFEST_DIR"), "/resources/test", $fname) // assumes Linux ('/')! }; } #[test] pub fn test_config_read() { let config = read_config::get_config(test_case!("/config.test.0.json").to_string()); assert_eq!(config.git_host_dir_path, "/path/to/git/host/dir"); assert_eq!(config.cgitrepos_file_path, "/path/to/cgitrepos"); assert_eq!(config.authorized_owners.len(), 1); let test_owner = &config.authorized_owners[0]; assert_eq!(test_owner.name, "johndoe"); assert_eq!(test_owner.email, "eg@example.com"); assert_eq!(test_owner.gpg_pubkey_id, "XXXXXXXXXXXXXXXX"); } #[test] pub fn test_make_repository() { let mut config = read_config::get_config(test_case!("/config.test.1.json").to_string()); fs::create_dir(test_case!("/put_git_repo_here")).expect("cannot create test directory"); fs::copy(test_case!("/testcgitrepos"), test_case!("/testcgitrepos.1")) .expect("cannot duplicate test cgitrepos file"); let test_git_path = test_case!("/put_git_repo_here").to_string(); config.cgitrepos_file_path = test_case!("/testcgitrepos.1").to_string(); config.git_host_dir_path = test_git_path; make_repo_request_handler( config, MakeRepoRequest { repo_name: "test".to_string(), author: "testuser".to_string(), section: "custom".to_string(), description: "test description".to_string(), }, ); let new_file = read_to_string(test_case!("/testcgitrepos.1")).expect("read new file error"); let test_file = read_to_string(test_case!("/testcgitrepos.1.test")).expect("read old file error"); assert_ne!( fs::read_dir(test_case!("/put_git_repo_here/test.git")) .into_iter() .len(), 0 ); assert_eq!(new_file, test_file); // cleanup fs::remove_dir_all(test_case!("/put_git_repo_here")) .expect("expecting cleanup to run correctly"); fs::remove_file(test_case!("/testcgitrepos.1")) .expect("expecting temp file to be cleaned up correctly"); }