aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/tst-sessions.sh
blob: 107e635c4577d359fa63493d8f3c4919dd899e14 (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
39
40
41
42
43
44
45
test_db_path="$tests_dir/data/test_db.csv"
readonly test_db_path

_test_format() {
    local output_path
    output_path="$( mktemp --tmpdir="$test_root_dir" )"

    test_run_module vk.tracking.sessions "$@" "$test_db_path" "$output_path"

    if [ ! -s "$output_path" ]; then
        fail "Output file '$output_path' either doesn't exists or is empty"
        return 1
    fi

    local file_output=
    file_output="$( file --brief --dereference --mime -- "$output_path" )"

    if echo "$file_output" | grep --quiet -- 'charset=binary$'; then
        log 'Output is a binary file, not going to show that'
        return 0
    fi

    cat -- "$output_path" >&2
}

_test_group_by() {
    local group_by
    for group_by; do
        local format
        for format in csv json plot; do
            _test_format --output-format "$format" --group-by "$group_by"
        done
    done
}

_test_main() {
    _test_group_by user
    _test_group_by hour
    _test_group_by date
    _test_group_by weekday
}

test_run() {
    _test_main
}