-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration-tests.sh
executable file
·171 lines (133 loc) · 3.55 KB
/
integration-tests.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
binary=target/release/unzipr
if [ ! -e "$binary" ]; then
binary=target/debug/unzipr
fi
function assert_code() {
expected=$1
code=$2
if [ "$code" -ne "$expected" ]; then
echo "Exit code $code is not 0"
exit 1;
fi
}
function assert_eq() {
expected=$1
output=$2
if [ "$output" != "$expected" ]; then
echo "'$output' does not equal '$expected'"
exit 1
fi
}
function assert_success_code() {
assert_code 0 $1
}
function assert_failure_code() {
assert_code 1 $1
}
# Test 1
# Test listing files in a zip file
echo "Running test 1"
output=`$binary -l tests/resources/test.zip`
code=$?
expected="test/
test/test.txt"
assert_eq "$expected" "$output"
assert_success_code $code
# Test 2
# Test listing files in nested zip file
echo "Running test 2"
output=`$binary -l tests/resources/test-test.zip test.zip`
code=$?
expected="test/
test/test.txt"
assert_eq "$expected" "$output"
assert_success_code $code
# Test 3
# Test unpacking files in nested zip file
echo "Running test 3"
output=`$binary -p tests/resources/test-test.zip test.zip test/test.txt`
code=$?
expected="Hello"
assert_eq "$expected" "$output"
assert_success_code $code
# Test 4
# Test failure unpacking a txt file
echo "Running test 4"
output=`$binary -l tests/resources/test.txt`
code=$?
expected="File 'tests/resources/test.txt' is not a zip archive"
assert_eq "$expected" "$output"
assert_failure_code $code
# Test 5
# Test failure unpacking a non-existent file
echo "Running test 5"
output=`$binary -l tests/resources/asdf`
code=$?
expected="No such file or directory 'tests/resources/asdf'"
assert_eq "$expected" "$output"
assert_failure_code $code
# Test 6
# Test unpacking to current directory
echo "Running test 6"
cur_dir=$(pwd)
test_dir=target/tests/test6
rm -rf $test_dir
mkdir -p $test_dir
cd $test_dir
expected_contents="Hello"
output=`"$cur_dir/$binary" "$cur_dir/tests/resources/test-test.zip" test.zip`
code=$?
contents=`cat test/test.txt`
assert_eq "" "$output"
assert_eq "$expected_contents" "$contents"
assert_success_code $code
cd $cur_dir
# Test 7
# Test unpacking to specific directory
echo "Running test 7"
test_dir=target/tests/test7
rm -rf $test_dir
mkdir -p $test_dir
expected_contents="Hello"
output=`$binary -d $test_dir tests/resources/test-test.zip test.zip`
code=$?
contents=`cat "$test_dir/test/test.txt"`
assert_eq "" "$output"
assert_eq "$expected_contents" "$contents"
assert_success_code $code
# Test 8
# Test unpacking to specific directory containing ..
echo "Running test 8"
test_dir=target/tests/test8
rm -rf $test_dir
mkdir -p "$test_dir/deep"
expected_contents="Hello"
output=`$binary -d "$test_dir/deep/.." tests/resources/test-test.zip test.zip`
code=$?
contents=`cat "$test_dir/test/test.txt"`
assert_eq "" "$output"
assert_eq "$expected_contents" "$contents"
assert_success_code $code
# Test 9
# Test unpack doesn't overwrite files
echo "Running test 9"
test_dir=target/tests/test9
rm -rf $test_dir
mkdir -p $test_dir
expected_contents="Hello"
output=`$binary -d $test_dir tests/resources/test-test.zip test.zip`
output=`$binary -d $test_dir tests/resources/test-test.zip test.zip`
code=$?
assert_eq "Unpack target 'target/tests/test9/test/test.txt' already exists" "$output"
assert_failure_code $code
# Test 10
# Test unpacking to dir fails for non-existent file
echo "Running test 10"
test_dir=target/tests/test10
rm -rf $test_dir
mkdir -p $test_dir
output=`$binary -d $test_dir tests/resources/asdf`
code=$?
assert_eq "No such file or directory 'tests/resources/asdf'" "$output"
assert_failure_code $code