summaryrefslogtreecommitdiffstatshomepage
path: root/test/tst-mutuals.sh
blob: 3f40780eb6dcec2b0ad3847b039be45f56f581f2 (plain) (blame)
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
test_run() {
    test_setup

    local users=(kreed58 korya_mc)

    test_run_module vk.mutuals --format csv "${users[@]}"  > "$test_root_dir/mutuals.csv"
    test_run_module vk.mutuals --format json "${users[@]}" > "$test_root_dir/mutuals.json"

    local expected=10

    local actual_csv
    actual_csv="$( cat -- "$test_root_dir/mutuals.csv" | wc -l )"
    log "Mutuals in CSV: $actual_csv"

    if [ "$actual_csv" -lt "$expected" ]; then
        fail "Expected a lot more mutual friends in CSV output"
        fail_details "Expected: $expected"
        fail_details "Actual: $actual_csv"
        return 1
    fi

    local actual_json
    actual_json="$( grep -F -- '"id":' "$test_root_dir/mutuals.json" | wc -l )"
    log "Mutuals in JSON: $actual_json"

    if [ "$actual_json" -lt "$expected" ]; then
        fail "Expected a lot more mutual friends in JSON output"
        fail_details "Expected: $expected"
        fail_details "Actual: $actual_json"
        return 1
    fi

    if [ "$actual_csv" -ne "$actual_json" ]; then
        fail "Number of mutuals in CSV unequal to that in JSON"
        fail_details "Can technically happen, because it's kind of a race"
        return 1
    fi
}