-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·105 lines (91 loc) · 2.81 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
#!/bin/sh
# sanitize PATH variable
PATH=$(command -p getconf PATH)
# setup test environment
echo 'Setting up test environment...'
PROJECT_DIR=$(pwd)
TESTDIR="$(pwd)/sandbox"
mkdir -p "$TESTDIR"
# subshelled because we don't need DESTDIR set in this script
(DESTDIR=$TESTDIR make install >/dev/null 2>&1)
EXE="$TESTDIR/usr/local/bin/ec2-backup"
# enter test environment
cd "$TESTDIR" || { echo 'cd failed'; exit 1; }
# run tests
# using while loop so we can break after failed tests
while true; do
printf '%s' 'Test 1: checking usage message...'
if ! OUTPUT=$($EXE); then
USAGE='usage: ec2-backup [-h] [-l filter] [-r filter] [-v volume-id] dir'
if [ "$OUTPUT" = "$USAGE" ]; then
echo 'Success'
else
echo 'Failed'
break
fi
else
echo 'Failed'
break
fi
printf '%s' 'Test 2: checking help message...'
if OUTPUT=$($EXE -h); then
HELP=\
'usage: ec2-backup [-h] [-l filter] [-r filter] [-v volume-id] dir
-h Print this help message.
-l filter Pass data through the given filter command on the local host
before copying the data to the remote system.
-r filter Pass data through the given filter command on the remote host
before writing the data to the volume.
-v volume-id Use the given volume instead of creating a new one.'
if [ "$OUTPUT" = "$HELP" ]; then
echo 'Success'
else
echo 'Failed'
break
fi
else
echo 'Failed'
break
fi
printf '%s' 'Test 3: checking invalid backup...'
echo 'This is not a directory.' > notadirectory
if ! $EXE notadirectory; then
echo 'Success'
else
echo 'Failed'
break
fi
printf '%s' 'Test 4: checking valid backup...'
mkdir -p dir
echo 'Hello World.' > dir/file
if OUTPUT=$($EXE dir); then
#TODO check file exists on volume saved in OUTPUT
echo 'Success'
else
echo 'Failed'
break
fi
printf '%s' 'Test 5: checking valid local filter...'
if OUTPUT=$($EXE -l 'tar -czf -' dir); then
#TODO check file exists on volume saved in OUTPUT
echo 'Success'
else
echo 'Failed'
break
fi
printf '%s' 'Test 6: checking valid local and remote filters...'
if OUTPUT=$($EXE -l 'tar -czf -' -r 'tar -xzf -' dir); then
#TODO check file exists on volume saved in OUTPUT
echo 'Success'
else
echo 'Failed'
break
fi
# TODO: add more test cases, need to check volume flag (-v)
# we only want the loop to execute once anyway
break
done
# tear down test environment
echo 'Breaking down test environment...'
cd "$PROJECT_DIR" || { echo 'cd failed'; exit 1; }
[ -n "$TESTDIR" ] && rm -rf "$TESTDIR"