-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.sh
executable file
·132 lines (116 loc) · 2.66 KB
/
test.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
TEST_BASE_URL='http://localhost:8080/'
PASSCOUNT=0
FAILCOUNT=0
echo testing tooltool\'s command line interface
function fail() {
echo TEST-FAIL: "$@"
FAILCOUNT=$((FAILCOUNT + 1))
}
function pass() {
echo TEST-PASS: "$@"
PASSCOUNT=$((PASSCOUNT + 1))
}
function error() {
echo TEST-ERROR: "$@"
}
function info() {
echo TEST-INFO: "$@"
}
function setup() {
#cleanup
rm -rf manifest.tt a b c d test_file.ogg
echo 1 > a
echo 2 > b
echo 3 > c
echo 4 > d
}
function assert_zero() {
if [ $1 -ne 0 ] ; then
fail "$2"
else
pass "$2"
fi
}
function assert_nonzero() {
if [ $1 -eq 0 ] ; then
fail "$2"
else
pass "$2"
fi
}
mkdir -p testdir && cd testdir
tt="../tooltool.py --url $TEST_BASE_URL -v --ignore-config-files"
info "$tt"
###############
setup
$tt list
assert_nonzero $? "listing empty manifest"
###############
setup
$tt add a
assert_zero $? "adding file to manifest"
test -f manifest.tt
assert_zero $? "manifest file created"
###############
$tt add a
# TODO assert_nonzero $? "adding the same file a second time"
###############
$tt add notafile
#TODO this will always pass until the program is fixed
assert_nonzero $? "adding non-existant file"
###############
$tt list
assert_zero $? "listing valid manifest"
###############
rm a
$tt list
assert_zero $? "listing should work when there are absent files"
###############
$tt add b
assert_zero $? "adding a second file"
###############
$tt add b
assert_nonzero $? "adding a duplicate file shouldn't work"
###############
curl -LI $TEST_BASE_URL &> /dev/null
assert_zero $? "need a webserver, trying $TEST_BASE_URL"
###############
rm -f a b
$tt fetch a
assert_zero $? "fetching a single file"
echo 1 > ta
diff a ta &> /dev/null
assert_zero $? "a fetched correctly"
rm -f ta
test ! -e b
assert_zero $? "un-fetched file should be absent"
##############
$tt fetch
assert_zero $? "fetching all files in manifest"
test -f a
assert_zero $? "a fetched"
test -f b
assert_zero $? "b fetched"
##############
echo OMGWTFBBQ > a
$tt fetch a
assert_nonzero $? "without overwriting, shouldn't overwrite"
test `cat a` = "OMGWTFBBQ\n" # hmm, feels flakey
assert_nonzero $? "contents should be per local changes"
$tt fetch a --overwrite
assert_zero $? "with overwriting, should overwrite"
test `cat a` -eq 1
assert_zero $? "contents should be per manifest"
#############
$tt validate
assert_zero $? "validate works"
echo ==============================================
echo TEST-PASSES: $PASSCOUNT, TEST-FAILS: $FAILCOUNT
if [[ $FAILCOUNT -ne 0 || $PASSCOUNT -lt 1 ]] ; then
echo TESTS FAILED
exit 1
else
(cd .. && rm -rf testdir)
exit 0
fi