1
use super::*;
2

            
3
#[test]
4
1
fn the_database_url_replaces_nothing_but_appends_the_name() {
5
1
    assert_eq!(
6
1
        database_url("postgres://ray@localhost/", "snap"),
7
1
        "postgres://ray@localhost/snap"
8
    );
9
1
    assert_eq!(
10
1
        database_url("postgres://ray@localhost", "snap"),
11
1
        "postgres://ray@localhost/snap"
12
    );
13
1
}
14

            
15
#[test]
16
1
fn tenants_are_the_dumps_except_the_directory() -> Result<()> {
17
1
    let dir = tempfile::tempdir()?;
18
1
    for file in [
19
1
        "nomisync.dump",
20
1
        "nomi_user_b.dump",
21
1
        "nomi_user_a.dump",
22
1
        "notes.txt",
23
1
    ] {
24
4
        std::fs::write(dir.path().join(file), "")?;
25
    }
26

            
27
1
    assert_eq!(tenant_names(dir.path())?, ["nomi_user_a", "nomi_user_b"]);
28
1
    Ok(())
29
1
}
30

            
31
#[test]
32
1
fn a_missing_dump_directory_is_an_error() {
33
1
    assert!(tenant_names(Path::new("/nonexistent/dumps")).is_err());
34
1
}
35

            
36
#[test]
37
1
fn a_tenant_is_repointed_to_its_prefixed_copy() {
38
1
    let copy = tenant_copy_name("nomi_user_a");
39
1
    assert!(copy.starts_with("pf") && copy.ends_with("_nomi_user_a"));
40
1
    assert_eq!(
41
1
        repoint("nomi_user_a", &copy),
42
1
        format!("UPDATE users SET database_name = '{copy}' WHERE database_name = 'nomi_user_a'")
43
    );
44
1
}
45

            
46
#[test]
47
1
fn the_reference_check_passes_the_sources_directory_when_given() {
48
1
    assert_eq!(references_args(None), ["check-references"]);
49
1
    assert_eq!(
50
1
        references_args(Some(Path::new("doc/scripts"))),
51
1
        ["check-references", "--sources", "doc/scripts"]
52
    );
53
1
}