1
use super::{DEGRADED, HEALTHY, UNUSABLE, report_outcome, verdict};
2
use server::db::DBError;
3
use server::fleet::FleetReport;
4
use sqlx::types::Uuid;
5

            
6
5
fn degraded(report: FleetReport) -> Result<FleetReport, DBError> {
7
5
    Ok(report)
8
5
}
9

            
10
#[test]
11
1
fn a_fully_verified_fleet_exits_zero() {
12
1
    let outcome = degraded(FleetReport {
13
1
        migrated: 12,
14
1
        ..FleetReport::default()
15
1
    });
16

            
17
1
    assert_eq!(verdict(&outcome), HEALTHY);
18
1
    report_outcome(&outcome);
19
1
}
20

            
21
#[test]
22
1
fn an_empty_fleet_exits_zero() {
23
    // The state Release 1 ships in: nothing to migrate is success, not a fault.
24
1
    assert_eq!(verdict(&degraded(FleetReport::default())), HEALTHY);
25
1
}
26

            
27
#[test]
28
1
fn a_quarantined_tenant_degrades_the_run() {
29
1
    let outcome = degraded(FleetReport {
30
1
        migrated: 3,
31
1
        quarantined: vec![(Uuid::nil(), "unreachable".to_owned())],
32
1
        ..FleetReport::default()
33
1
    });
34

            
35
1
    assert_eq!(verdict(&outcome), DEGRADED);
36
1
    report_outcome(&outcome);
37
1
}
38

            
39
#[test]
40
1
fn a_tenant_this_run_never_verified_degrades_it_too() {
41
    // Another worker held the claim to the end. It may since have died, and a
42
    // zero here would gate a rollout on a database nobody looked at.
43
1
    let outcome = degraded(FleetReport {
44
1
        unresolved: vec![Uuid::nil()],
45
1
        ..FleetReport::default()
46
1
    });
47

            
48
1
    assert_eq!(verdict(&outcome), DEGRADED);
49
1
    report_outcome(&outcome);
50
1
}
51

            
52
#[test]
53
1
fn a_verdict_that_could_not_be_written_degrades_it() {
54
    // The dangerous case: the tenant failed, its quarantine did not stick, and
55
    // it is still being served.
56
1
    let outcome = degraded(FleetReport {
57
1
        migrated: 5,
58
1
        unpublished: vec![(Uuid::nil(), "directory unreachable".to_owned())],
59
1
        ..FleetReport::default()
60
1
    });
61

            
62
1
    assert_eq!(verdict(&outcome), DEGRADED);
63
1
    report_outcome(&outcome);
64
1
}
65

            
66
#[test]
67
1
fn a_run_that_could_not_happen_is_distinct_from_a_degraded_one() {
68
1
    let outcome = Err(DBError::MissingUrl);
69

            
70
1
    assert_eq!(
71
1
        verdict(&outcome),
72
        UNUSABLE,
73
        "an unusable run must be distinguishable from one that ran and found problems"
74
    );
75
1
    report_outcome(&outcome);
76
1
}