generated from nhcarrigan/template
feat: actually sort, add test for sorting
This commit is contained in:
24
test.sh
Executable file
24
test.sh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONF="configs/prod.conf"
|
||||
|
||||
# Extract server_name values in order, ignoring commented lines
|
||||
mapfile -t domains < <(grep -oP '^\s*server_name\s+\K[^;]+' "$CONF")
|
||||
|
||||
sorted=($(printf "%s\n" "${domains[@]}" | sort))
|
||||
|
||||
# Print the sorted list for debugging
|
||||
echo "Auditing servers:"
|
||||
printf "%s " "${sorted[@]}"
|
||||
echo ""
|
||||
|
||||
for i in "${!domains[@]}"; do
|
||||
if [[ "${domains[$i]}" != "${sorted[$i]}" ]]; then
|
||||
echo "Domain list is not sorted alphabetically."
|
||||
echo "First out-of-order entry: '${domains[$i]}' (should be '${sorted[$i]}')"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "All server_name entries are sorted alphabetically."
|
||||
exit 0
|
Reference in New Issue
Block a user