Skip to content

Commit ed43cdc

Browse files
committed
TESTS - Check files, folders and symlinks are present after installation
1 parent cab65b1 commit ed43cdc

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/test.bats

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,61 @@ teardown() {
2020
[ -n "$TESTDIR" ] && rm -rf "$TESTDIR"
2121
}
2222

23+
# Internal helper function to check existence of items from external list.
24+
#
25+
# WARNING: Do not call this function directly. Use check_required_folders or
26+
# check_required_files instead. The wrong parameters may lead to unexpected
27+
# results.
28+
#
29+
# Parameters:
30+
# $1: item_type - "folder" or "file"
31+
# $2: list_file - path to the file containing items to check
32+
# $3: test_flag - "-d" for folders, "-f" for files
33+
check_required_items() {
34+
local item_type="$1"
35+
local list_file="$2"
36+
local test_flag="$3"
37+
local failed=0
38+
39+
echo "Checking required ${item_type}s:"
40+
41+
# Read required items from external file
42+
while IFS='#' read -r item comment || [ -n "$item" ]; do
43+
# Skip empty lines and comments
44+
[[ -z "$item" || "$item" =~ ^[[:space:]]*# ]] && continue
45+
46+
# Trim whitespace
47+
item=$(echo "$item" | xargs)
48+
comment=$(echo "$comment" | xargs)
49+
50+
if test "$test_flag" "${TESTDIR}/${item}"; then
51+
echo "Checking if ${item_type} '${item}' exists... Ok. (${comment})"
52+
else
53+
echo "Checking if ${item_type} '${item}' exists... Missing. (${comment})"
54+
failed=1
55+
fi
56+
done < "$list_file"
57+
58+
return $failed
59+
}
60+
61+
62+
# Check a list of required folders.
63+
check_required_folders() {
64+
check_required_items "folder" "${DIR}/tests/required_folders.txt" "-d"
65+
}
66+
67+
68+
# Check a list of required files.
69+
check_required_files() {
70+
check_required_items "file" "${DIR}/tests/required_files.txt" "-f"
71+
}
72+
73+
# Check a list of required symlinks.
74+
check_required_symlinks() {
75+
check_required_items "symlinks" "${DIR}/tests/required_symlinks.txt" "-L"
76+
}
77+
2378
check_services() {
2479
echo "Checking services:"
2580
INSTALLED_SERVICES=$(ddev get --installed)
@@ -59,6 +114,19 @@ check_drupal_admin_access() {
59114
ddev restart >/dev/null
60115
ddev aljibe-assistant --auto
61116

117+
# Checks on files and folders required after installation.
118+
run check_required_folders
119+
echo "$output" >&3
120+
[ "$status" -eq 0 ]
121+
122+
run check_required_files
123+
echo "$output" >&3
124+
[ "$status" -eq 0 ]
125+
126+
run check_required_symlinks
127+
echo "$output" >&3
128+
[ "$status" -eq 0 ]
129+
62130
check_services >&3
63131
check_project_browse >&3
64132
## Todo Make this test work

0 commit comments

Comments
 (0)