aboutsummaryrefslogtreecommitdiff
path: root/src/archiver/raw.rs
blob: d0f40d7fb13e559b09fcd8e0504f9973198827de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::template::Context;
use crate::utils::recursively_copy;
use std::io::Result;
use std::path::Path;

pub fn archive(archive_directory: &Path, _: &Path, target: &Path, _: &Context) -> Result<()> {
    if archive_directory.exists() {
        return recursively_copy(archive_directory, target);
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use std::collections::HashMap;
    use std::fs::create_dir_all;

    use super::*;

    use test_utilities::*;

    #[test]
    fn test_copies_files() {
        let test_dir = setup_test_dir();
        let archive_dir = test_dir.join("archive");
        let output_dir = test_dir.join("output");
        create_dir_all(&archive_dir).expect("Could not create archive test directory");
        create_dir_all(&output_dir).expect("Could not create output test directory");

        create_test_file(&archive_dir.join("🤠"), "beep boop boop beep");

        let context: Context = HashMap::new();

        archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed");

        assert_file_contents(&output_dir.join("🤠"), "beep boop boop beep");
        cleanup_test_dir(&test_dir);
    }

    #[test]
    fn test_ignores_if_no_archive() {
        let test_dir = setup_test_dir();
        let archive_dir = test_dir.join("archive");
        let output_dir = test_dir.join("output");

        let context: Context = HashMap::new();

        archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed");
        cleanup_test_dir(&test_dir);
    }
}