test(release-cleanup): 補齊 cleanup/config/main 與新驗證函式測試
新增 cleanupReleases、cleanupOrphanTags 的失敗路徑與分類測試、 loadConfig 環境變數驗證測試、main 整合測試,以及 requireUrl/ requireRepository 與 content-type 檢查測試。測試共 41 項全數通過。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
154ab032bf
commit
7c225d4122
@@ -0,0 +1,43 @@
|
||||
import { test, afterEach } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { main } from '../index.js'
|
||||
|
||||
const realFetch = globalThis.fetch
|
||||
const savedEnv = { ...process.env }
|
||||
|
||||
afterEach(() => {
|
||||
globalThis.fetch = realFetch
|
||||
process.env = { ...savedEnv }
|
||||
})
|
||||
|
||||
function setEnv(env) {
|
||||
for (const key of ['GITEA_SERVER_URL', 'GITEA_REPOSITORY', 'KEEP_COUNT', 'GITEA_TOKEN']) {
|
||||
delete process.env[key]
|
||||
}
|
||||
Object.assign(process.env, env)
|
||||
}
|
||||
|
||||
test('main 在環境變數有效且 API 正常時順利完成', async () => {
|
||||
setEnv({
|
||||
GITEA_SERVER_URL: 'https://gitea.example.com',
|
||||
GITEA_REPOSITORY: 'owner/repo',
|
||||
KEEP_COUNT: '2',
|
||||
})
|
||||
// 所有清單端點皆回空陣列(無 release、無 tag)
|
||||
globalThis.fetch = async () => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: { get: () => 'application/json' },
|
||||
json: async () => [],
|
||||
})
|
||||
|
||||
await main() // 不應拋出
|
||||
})
|
||||
|
||||
test('main 在必填環境變數缺失時 reject(供整合層級驗證錯誤處理)', async () => {
|
||||
setEnv({
|
||||
GITEA_REPOSITORY: 'owner/repo',
|
||||
KEEP_COUNT: '2',
|
||||
})
|
||||
await assert.rejects(() => main(), /GITEA_SERVER_URL is required/)
|
||||
})
|
||||
Reference in New Issue
Block a user