-
Notifications
You must be signed in to change notification settings - Fork 1
/
rules_test.sh
64 lines (59 loc) · 1.92 KB
/
rules_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
#!/bin/bash
# shellcheck disable=SC1091
# Source the common test functions
source common_test.sh
# Source the bash file containing the functions to be tested
source rules.sh
# Test function for check_rules_file
test_check_rules_file() {
# Test with existing and readable rules file
test_check_rules_file_with_existing_readable_file() {
local temp_file
temp_file=$(mktemp /tmp/rules.XXXXXX)
touch "$temp_file"
chmod u+r "$temp_file"
assert_no_error "$(check_rules_file "$temp_file")" "${FUNCNAME[0]}"
rm "$temp_file"
}
test_check_rules_file_with_existing_readable_file
# Test with non-existent file
test_check_rules_file_with_nonexistent_file() {
local temp_file
temp_file=$(mktemp /tmp/rules.XXXXXX)
rm "$temp_file"
local expected_return_code=1
assert_is_error "$(
check_rules_file "$temp_file"
echo $?
)" "${expected_return_code}" "${FUNCNAME[0]}"
}
test_check_rules_file_with_nonexistent_file
# Test with non-readable file
test_check_rules_file_with_nonreadable_file() {
local temp_file
temp_file=$(mktemp /tmp/rules.XXXXXX)
touch "$temp_file"
chmod u-r "$temp_file"
local expected_return_code=1
assert_is_error "$(
check_rules_file "$temp_file"
echo $?
)" "${expected_return_code}" "${FUNCNAME[0]}"
rm "$temp_file"
}
test_check_rules_file_with_nonreadable_file
# Test with empty file
test_check_rules_file_with_empty_file() {
local temp_file
temp_file=$(mktemp /tmp/rules.XXXXXX)
local expected_return_code=1
assert_is_error "$(
check_rules_file "$temp_file"
echo $?
)" "${expected_return_code}" "${FUNCNAME[0]}"
rm "$temp_file"
}
test_check_rules_file_with_empty_file
}
# Run all test functions
test_check_rules_file