45 lines
1.6 KiB
Bash
Executable File
45 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Render every fixture with router/mihomo-kit.sh and compare with tests/expected/,
|
|
# validate with `mihomo -t` when MIHOMO points to a mihomo binary, and check
|
|
# luci/servers.js (share links, YAML) against the outputs of mihomo's own Go code.
|
|
# tools/test.sh
|
|
# UPDATE=1 tools/test.sh rewrite tests/expected/ (review the diff)
|
|
# MIHOMO=/path/to/mihomo tools/test.sh
|
|
set -u
|
|
cd "$(dirname "$0")/.."
|
|
out=$(mktemp -d)
|
|
fail=0
|
|
if [ -n "${MIHOMO:-}" ]; then
|
|
# rule-sets are fetched over http: put a local copy in place for an offline check
|
|
mkdir -p "$out/home/ruleset"
|
|
echo '+.example.ru' > "$out/ru-inside.txt"
|
|
"$MIHOMO" convert-ruleset domain text "$out/ru-inside.txt" "$out/home/ruleset/ru-inside.mrs" >/dev/null
|
|
fi
|
|
mkdir -p tests/expected
|
|
for f in tests/fixtures/*.env; do
|
|
n=$(basename "$f" .env)
|
|
[ "$n" = common ] && continue
|
|
sh router/mihomo-kit.sh render tests/fixtures/common.env "$f" > "$out/$n.yaml" || { echo "FAIL $n: render"; fail=1; continue; }
|
|
if [ "${UPDATE:-0}" = 1 ]; then
|
|
cp "$out/$n.yaml" "tests/expected/$n.yaml"
|
|
elif ! diff -u "tests/expected/$n.yaml" "$out/$n.yaml"; then
|
|
echo "FAIL $n: differs from tests/expected/$n.yaml (UPDATE=1 if intended)"
|
|
fail=1
|
|
continue
|
|
fi
|
|
if [ -n "${MIHOMO:-}" ]; then
|
|
cp "$out/$n.yaml" "$out/home/$n.yaml"
|
|
if ! "$MIHOMO" -t -d "$out/home" -f "$out/home/$n.yaml" >"$out/$n.log" 2>&1; then
|
|
echo "FAIL $n: mihomo -t"; tail -3 "$out/$n.log"; fail=1; continue
|
|
fi
|
|
fi
|
|
echo "ok $n"
|
|
done
|
|
if command -v node >/dev/null 2>&1; then
|
|
node tools/test-servers.js || fail=1
|
|
else
|
|
echo "skip luci/servers.js: no node"
|
|
fi
|
|
rm -rf "$out"
|
|
exit $fail
|