新增 fetchAllPages 的 AbortError 逾時與非陣列回應測試、loadConfig 的 GITEA_TOKEN 邊界測試,以及 logger.failError 測試。測試共 47 項全數通過。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
73 lines
2.1 KiB
JavaScript
73 lines
2.1 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { loadConfig } from '../config.js'
|
|
|
|
const base = {
|
|
GITEA_SERVER_URL: 'https://gitea.example.com',
|
|
GITEA_REPOSITORY: 'owner/repo',
|
|
KEEP_COUNT: '2',
|
|
}
|
|
|
|
test('loadConfig 在缺少 GITEA_SERVER_URL 時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ GITEA_REPOSITORY: 'owner/repo', KEEP_COUNT: '2' }),
|
|
/GITEA_SERVER_URL is required/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在 KEEP_COUNT 非整數時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ ...base, KEEP_COUNT: 'abc' }),
|
|
/non-negative integer/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在 GITEA_SERVER_URL 非合法 URL 時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ ...base, GITEA_SERVER_URL: 'not a url' }),
|
|
/must be a valid URL/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在 GITEA_REPOSITORY 含路徑穿越時丟出', () => {
|
|
assert.throws(
|
|
() => loadConfig({ ...base, GITEA_REPOSITORY: '../evil' }),
|
|
/owner\/repo without path traversal/,
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在有效輸入時回傳完整設定物件', () => {
|
|
const cfg = loadConfig(base)
|
|
assert.equal(cfg.serverUrl, 'https://gitea.example.com')
|
|
assert.equal(cfg.repository, 'owner/repo')
|
|
assert.equal(cfg.token, null)
|
|
assert.equal(cfg.keepCount, 2)
|
|
assert.equal(
|
|
cfg.releaseApiUrl,
|
|
'https://gitea.example.com/api/v1/repos/owner/repo/releases',
|
|
)
|
|
assert.equal(
|
|
cfg.tagApiUrl,
|
|
'https://gitea.example.com/api/v1/repos/owner/repo/tags',
|
|
)
|
|
})
|
|
|
|
test('loadConfig 在提供 token 時保留 token 值', () => {
|
|
const cfg = loadConfig({ ...base, GITEA_TOKEN: 'secret' })
|
|
assert.equal(cfg.token, 'secret')
|
|
})
|
|
|
|
test('loadConfig 在 GITEA_TOKEN 為空字串時視為匿名(token 為 null)', () => {
|
|
const cfg = loadConfig({ ...base, GITEA_TOKEN: '' })
|
|
assert.equal(cfg.token, null)
|
|
})
|
|
|
|
test('loadConfig 接受極短與極長的 GITEA_TOKEN', () => {
|
|
const short = loadConfig({ ...base, GITEA_TOKEN: 'x' })
|
|
assert.equal(short.token, 'x')
|
|
|
|
const longToken = 'a'.repeat(1000)
|
|
const long = loadConfig({ ...base, GITEA_TOKEN: longToken })
|
|
assert.equal(long.token, longToken)
|
|
})
|