-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_commands.sh
95 lines (81 loc) · 1.95 KB
/
test_commands.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
#!/bin/sh
# Test script for testing command entry points
name="oval-graph"
test_file_src="./arf.xml"
tmp_dir_src="./tmp_data"
tmp_json_file_src="${tmp_dir_src}/data.json"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
reset="$(tput sgr0)"
passed_msg="${green}passed${reset}"
failed_msg="${red}failed${reset}"
result=0
test_if_is_instaled_oval_graph() {
if ! rpm -q --quiet $name; then
echo "$name NOT installed"
exit 1
fi
}
report() {
if [ $result -eq 0 ]; then
printf "Result: %-70s %s\n" "$*" "$passed_msg"
else
printf "Result: %-70s %s\n\n" "$*" "$failed_msg"
fi
}
test() {
test_name="$1"
command="$2"
msg=""
echo "Start: $test_name"
$command >/dev/null
if [ $? -eq 0 ]; then
result=0
msg="$test_name"
else
result=1
msg="$test_name: $command"
fi
report "${msg}"
}
test_rise_error() {
test_name="$1"
command="$2"
msg=""
echo "Start: $test_name"
$command >/dev/null 2>&1
if [ $? -eq 2 ]; then
result=0
msg="$test_name"
else
result=1
msg="$test_name: $command"
fi
report "${msg}"
}
clean() {
echo "remove ${tmp_dir_src}"
rm -rf ${tmp_dir_src}
}
help_tests() {
test arf-to-graph-help "arf-to-graph -h"
test arf-to-json-help "arf-to-json -h"
test json-to-graph-help "json-to-graph -h"
}
bad_args_tests() {
test_rise_error arf-to-graph-bad_arg "arf-to-graph -hello"
test_rise_error arf-to-json-bad_arg "arf-to-json -hello"
test_rise_error json-to-graph-bad_arg "json-to-graph -hello"
}
basic_test() {
test run-arf-to-graph "arf-to-graph -o ${tmp_dir_src} ${test_file_src} fips"
test run-arf-to-json "arf-to-json -o ${tmp_json_file_src} ${test_file_src} fips"
test run-json-to-graph "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} fips"
}
test_if_is_instaled_oval_graph
help_tests
bad_args_tests
basic_test
if [ "$1" = "--clean" ]; then
clean
fi