/
ssh-to-test
executable file
·123 lines (98 loc) · 2.51 KB
/
ssh-to-test
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
#!/bin/bash
#
# Script to test our ssh-to script.
#
#
# Run an assert
#
# @param $1 string Our condition which should be a string for the test command
# @param $2 integer This should be $LINENO passed in from the parent, for error reporting.
#
function assert() {
COND1=$1
COND2=$2
LINE=$3
#
# Filter out newlines, otherwise
#
#echo "COND: $COND1 = $COND2" # Debugging
if ! test "$COND1" = "$COND2"
then
echo "! "
echo "! Assertion Failed: $COND1 = $COND2"
echo "! File: $0, Line: $LINE"
echo "! "
#
# Remove our temp servers.json file
#
rm -f servers.json
exit 1
else
echo "# Assertion PASS: $COND1 = $COND2"
fi
} # End of assert()
#
# Path to our SSH-to command
#
CMD=$(dirname $0)/ssh-to
#
# Copy our sample in for working
#
cp $(dirname $0)/servers.json.example servers.json
#
# Turn on debugging
#
export DEBUG=1
RESULT=$($CMD -h 2>&1 | grep "^all=")
#echo "$RESULT"
assert "$RESULT" "all=-h,," $LINENO
RESULT=$($CMD 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=,,,,./servers.json," $LINENO
RESULT=$($CMD hadoop 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,,,,./servers.json," $LINENO
RESULT=$($CMD hadoop 1 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,1,,,./servers.json," $LINENO
RESULT=$($CMD hadoop 1 "test cmd" 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,1,,,./servers.json,test cmd" $LINENO
RESULT=$($CMD --loop hadoop "test cmd" 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,,,1,./servers.json,test cmd" $LINENO
RESULT=$($CMD hadoop --loop "test cmd" 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,,,1,./servers.json,test cmd" $LINENO
RESULT=$($CMD --dump hadoop 1 "test cmd" 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,1,1,,./servers.json,test cmd" $LINENO
RESULT=$($CMD hadoop 1 --dump "test cmd" 2>&1 | grep "^all2=")
#echo "$RESULT"
assert "$RESULT" "all2=hadoop,1,1,,./servers.json,--dump test cmd" $LINENO
#
# Test without a servers.json file
#
rm -f servers.json
HOME=notahomedirectory ./$CMD >/dev/null 2>&1
RESULT=$?
assert "$RESULT" 1 $LINENO
#
# Test creating a servers.json file
#
HOME=notahomedirectory ./$CMD --create >/dev/null 2>&1
RESULT=$?
assert "$RESULT" 0 $LINENO
test -f servers.json
RESULT=$?
assert "$RESULT" 0 $LINENO
#
# Don't let us create a file that already exists
#
HOME=notahomedirectory ./$CMD --create >/dev/null 2>&1
RESULT=$?
assert "$RESULT" 1 $LINENO
#
# Remove the servers.json file
#
rm -f servers.json