fix(wiki): 依頁面類型解析 wiki repo 並統一 hash
This commit is contained in:
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env sh
|
||||
# check-wiki-rules — 驗證 wiki repo 解析與 hash-id 規則。
|
||||
set -eu
|
||||
|
||||
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
gitea="$dir/gitea.sh"
|
||||
hash_id="$dir/hash-id"
|
||||
|
||||
fail() {
|
||||
printf '%s\n' "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
expect_eq() {
|
||||
got=$1
|
||||
want=$2
|
||||
label=$3
|
||||
[ "$got" = "$want" ] || fail "$label: want=$want got=$got"
|
||||
}
|
||||
|
||||
check_repo() {
|
||||
type=$1
|
||||
label=$2
|
||||
want=$3
|
||||
shift 3
|
||||
got=$(env -i PATH="${PATH:-/usr/bin:/bin}" "$@" "$gitea" wiki-repo "$type")
|
||||
expect_eq "$got" "$want" "$label"
|
||||
}
|
||||
|
||||
check_hash() {
|
||||
input=$1
|
||||
want=$2
|
||||
got=$("$hash_id" "$input")
|
||||
expect_eq "$got" "$want" "hash-id $input"
|
||||
}
|
||||
|
||||
check_repo REPO 'REPO specific wins' 'records/REPO' \
|
||||
JSC_WIKI_REPO_REPO='records/REPO' \
|
||||
JSC_WIKI_REPO_ANALYZE='knowledges/ANALYZE' \
|
||||
JSC_WIKI_REPO='shared/wiki'
|
||||
|
||||
check_repo REPO 'REPO falls back to shared only' 'shared/wiki' \
|
||||
JSC_WIKI_REPO_ANALYZE='knowledges/ANALYZE' \
|
||||
JSC_WIKI_REPO='shared/wiki'
|
||||
|
||||
check_repo ANALYZE 'ANALYZE specific wins' 'knowledges/ANALYZE' \
|
||||
JSC_WIKI_REPO_REPO='records/REPO' \
|
||||
JSC_WIKI_REPO_ANALYZE='knowledges/ANALYZE' \
|
||||
JSC_WIKI_REPO='shared/wiki'
|
||||
|
||||
check_repo ANALYZE 'ANALYZE falls back to shared only' 'shared/wiki' \
|
||||
JSC_WIKI_REPO_REPO='records/REPO' \
|
||||
JSC_WIKI_REPO='shared/wiki'
|
||||
|
||||
check_repo ERROR 'ERROR uses its own repo' 'errors/wiki' \
|
||||
JSC_WIKI_REPO_ERROR='errors/wiki' \
|
||||
JSC_WIKI_REPO='shared/wiki'
|
||||
|
||||
check_hash 'case-2' 'H5172CB7'
|
||||
check_hash 'case-11' 'HA9A6662'
|
||||
check_hash 'case-1' 'HB6EC7FD'
|
||||
check_hash 'case-12' 'HCCA8D42'
|
||||
|
||||
printf '%s\n' 'OK'
|
||||
Reference in New Issue
Block a user