diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-12-25 01:04:07 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-12-25 01:04:07 +0200 |
commit | 2c38482061c5f9f4485c421f3faae92e49afcd2a (patch) | |
tree | 8f76ab334af3e630d4be0df955e56f830ceee831 /src | |
parent | 59319c4a0127766028aaf6f8404e0d3e239beba2 (diff) | |
download | git_service-master.tar.gz git_service-master.tar.bz2 git_service-master.zip |
test_config_read: tests if config can be read normally
test_make_repo: checks if repo has been created and if cgitrepos updated
Diffstat (limited to 'src')
-rw-r--r-- | src/test.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test.rs b/src/test.rs new file mode 100644 index 0000000..68212c3 --- /dev/null +++ b/src/test.rs @@ -0,0 +1,61 @@ +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"); +} |