1
use web::Config;
2

            
3
#[test]
4
1
fn test_config_structure() {
5
1
    let config = Config {
6
1
        site_url: "http://localhost:3000".to_string(),
7
1
        redis_url: "redis://localhost:6379".to_string(),
8
1
        access_token_max_age: 15,
9
1
        refresh_token_max_age: 60,
10
1
        ssh: web::config::SshConnectInfo {
11
1
            hostname: "ssh.example.invalid".to_string(),
12
1
            port: 2222,
13
1
            host_fingerprint: "(test)".to_string(),
14
1
        },
15
1
    };
16

            
17
1
    assert_eq!(config.site_url, "http://localhost:3000");
18
1
    assert_eq!(config.redis_url, "redis://localhost:6379");
19
1
    assert_eq!(config.access_token_max_age, 15);
20
1
    assert_eq!(config.refresh_token_max_age, 60);
21
1
}
22

            
23
/// REDIS_URL is a deployment endpoint, so a value in the environment must beat
24
/// the seeded row — otherwise a fresh install crash-loops against
25
/// redis://127.0.0.1:6379/ until someone rewrites the row by hand.
26
#[test]
27
1
fn env_supplies_the_redis_url_when_set() {
28
1
    assert_eq!(
29
1
        web::config::env_override(Some("redis://redis.redis.svc:6379/1".to_string())),
30
1
        Some("redis://redis.redis.svc:6379/1".to_string()),
31
    );
32
1
}
33

            
34
/// An unset key falls through to the configured row.
35
#[test]
36
1
fn an_absent_key_does_not_override() {
37
1
    assert_eq!(web::config::env_override(None), None);
38
1
}
39

            
40
/// A ConfigMap can carry an empty string. Taking it literally would replace
41
/// working configuration with a URL that cannot parse, so it counts as unset.
42
#[test]
43
1
fn an_empty_key_counts_as_unset() {
44
1
    assert_eq!(web::config::env_override(Some(String::new())), None);
45
1
    assert_eq!(web::config::env_override(Some("   ".to_string())), None);
46
1
}