- CLI 定义迁移至 src/bashly.yml(bashly 1.4 生成参数解析),入口收敛为 src/root_command.sh - 源码按功能域重组:config/storage/integrate/media/pipeline,消除扁平散落 - 新增零依赖测试框架 tests/(123 用例)与 CI 流水线(lint + test + build + 产物一致性) - build.sh 支持版本单一来源注入与 --check 产物校验;新增 lint.sh(bash -n + shellcheck 零容忍) - 删除旧单文件 media_organizer.sh 与旧扁平模块
68 lines
2.0 KiB
Bash
68 lines
2.0 KiB
Bash
# ============================================================================
|
||
# 缓存管理模块测试(src/lib/cache.sh)
|
||
# ============================================================================
|
||
|
||
setup() {
|
||
CACHE_DIR="$(mktemp -d)"
|
||
TMDB_LANG="zh-CN"
|
||
}
|
||
|
||
teardown() {
|
||
rm -rf "$CACHE_DIR"
|
||
}
|
||
|
||
# cache_path:搜索类用 md5 哈希文件名
|
||
test_cache_path_search_endpoint() {
|
||
local p
|
||
p="$(cache_path "/search/movie" "query=刀剑&year=2020")"
|
||
assert_eq "$CACHE_DIR/tmdb/search/movie/$(cache_key_hash "query=刀剑&year=2020").json" "$p"
|
||
}
|
||
|
||
# cache_path:tv 详情含语言段
|
||
test_cache_path_tv_detail() {
|
||
assert_eq "$CACHE_DIR/tmdb/tv/12345.zh-CN.json" "$(cache_path "/tv/12345" "x")"
|
||
}
|
||
|
||
# cache_path:季数据含语言段
|
||
test_cache_path_tv_season() {
|
||
assert_eq "$CACHE_DIR/tmdb/tv/12345/season/1.zh-CN.json" "$(cache_path "/tv/12345/season/1" "x")"
|
||
}
|
||
|
||
# cache_path:movie 详情含语言段
|
||
test_cache_path_movie_detail() {
|
||
assert_eq "$CACHE_DIR/tmdb/movie/6789.zh-CN.json" "$(cache_path "/movie/6789" "x")"
|
||
}
|
||
|
||
# cache_path:语言切换后路径变化(缓存自动失效)
|
||
test_cache_path_lang_switch_changes_path() {
|
||
TMDB_LANG="ja-JP"
|
||
assert_eq "$CACHE_DIR/tmdb/tv/12345.ja-JP.json" "$(cache_path "/tv/12345" "x")"
|
||
}
|
||
|
||
# cache_key:拼接参数并追加 lang
|
||
test_cache_key_joins_args_with_lang() {
|
||
assert_eq "query=刀剑&lang=zh-CN" "$(cache_key "query=刀剑")"
|
||
assert_eq "a=1&b=2&lang=zh-CN" "$(cache_key "a=1" "&b=2")"
|
||
}
|
||
|
||
# cache_key_hash:md5 稳定
|
||
test_cache_key_hash_stable() {
|
||
local h1 h2
|
||
h1="$(cache_key_hash "query=hello")"
|
||
h2="$(cache_key_hash "query=hello")"
|
||
assert_eq "$h1" "$h2"
|
||
assert_eq "5d41402abc4b2a76b9719d911017c592" "$(cache_key_hash "hello")"
|
||
}
|
||
|
||
# cache_expired:TTL 内不失效,超期失效
|
||
test_cache_expired_ttl() {
|
||
local f="$CACHE_DIR/f.json"
|
||
echo '{}' >"$f"
|
||
touch -d "2 days ago" "$f"
|
||
assert_success cache_expired "$f" 1
|
||
assert_failure cache_expired "$f" 30
|
||
# 新文件不失效
|
||
echo '{}' >"$f"
|
||
assert_failure cache_expired "$f" 1
|
||
}
|