Debian Codegraph @

debian/tests/smoke-test

raw
1 #!/bin/sh
2
3 if [ -z "${AUTOPKGTEST_TMP:-}" ]; then
4 export PATH="${0%/*}/../../src:$PATH"
5 fi
6
7 config=${0%/*}/goaccess.conf
8 logfile=${0%/*}/log
9
10 oneTimeSetUp() {
11 tmpdir=$(mktemp --tmpdir --directory goaccess.autopkgtest.XXXXXXXXXX)
12 stats_output="$tmpdir/output"
13 stats_db="$tmpdir/db"
14 mkdir -p "$stats_output" "$stats_db"
15
16 htmlrc=0
17 goaccess \
18 --config-file="$config" \
19 --db-path="$stats_db" \
20 --restore \
21 --persist \
22 --html-prefs='{"theme":"bright","perPage":20,"layout":"vertical","showTables":true}' \
23 --html-report-title="access statistics" \
24 --output "$stats_output/index.html" \
25 "$logfile" || htmlrc=$?
26
27 jsonrc=0
28 goaccess \
29 --config-file="$config" \
30 --db-path="$stats_db" \
31 --restore \
32 --persist \
33 --output "$stats_output/data.json" \
34 "$logfile" || jsonrc=$?
35 }
36
37 oneTimeTearDown() {
38 if [ -n "${DISPLAY:-}" ]; then
39 echo "I: not removing tmpdir ${tmpdir} so that you can inspect the results in a browser"
40 echo "I: please check file://${stats_output}/index.html"
41 else
42 rm -rf "$tmpdir"
43 fi
44 }
45
46 test_db() {
47 size="$(du -sh "$stats_db" | awk '{print($1)}')"
48 assertEquals "$size" "$(printf "0M\n%s\n" $size | sort --human | tail -1)"
49 }
50
51 test_html_rc() {
52 assertEquals "HTML output failed" 0 "$htmlrc"
53 }
54
55 test_html() {
56 assertTrue "HTML output: index.html created" "test -f $stats_output/index.html"
57 }
58
59 test_json_rc() {
60 assertEquals "JSON output failed" 0 "$jsonrc"
61 }
62
63 test_json() {
64 assertTrue "JSON output: data.json created" "test -f $stats_output/data.json"
65 }
66
67 test_html_visual() {
68 if [ -n "${DISPLAY:-}" ]; then
69 x-www-browser "$stats_output/index.html"
70 fi
71 }
72
73 . shunit2