Files
docker-docs/scripts/test_go_redirects.sh
David Karlsson f58694d9d1 test: add check for validating go-redirects
Test ensures that:

- Go redirects are unique (this is actually enforced by YAML already
  because it requires keys to be unique, but just in case someone
  'echo >>'es into the file or whatever
- Go redirects always resolve to an index.html in the public output dir

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
2024-06-27 13:45:30 +02:00

26 lines
745 B
Bash
Executable File

#!/usr/bin/env sh
echo "Testing redirects in data/redirects.yml..."
# Get all redirects from data/redirects.yml
REDIRECTS=$(yq eval 'keys | .[]' data/redirects.yml)
LOCAL_REDIRECTS=$(echo $REDIRECTS | awk 'BEGIN { RS = " " } /^\// { print $1 }')
echo "Checking for duplicate redirects..."
DUPLICATES=$(echo $LOCAL_REDIRECTS | tr ' ' '\n' | sort | uniq -d)
if [ -n "$DUPLICATES" ]; then
echo "Duplicate redirects found:"
echo $DUPLICATES
exit 1
fi
echo "Checking for redirects to nonexistent paths..."
for file in $(echo REDIRECTS | awk 'BEGIN { RS = " " } /^\// { print $1 }'); do
if [ ! -e "./public/${file%/*}/index.html" ]; then
echo "Redirect to nonexistent path: $file"
exit 1
fi
done
echo "All redirects are valid."