test(calculate-version): 整併重複測試至 app/test 並新增 logger 測試
This commit is contained in:
+42
-4
@@ -36,6 +36,7 @@ test('normalizeBetaFlag 僅將字面值 "true" 視為啟用', () => {
|
||||
assert.equal(normalizeBetaFlag('yes'), false);
|
||||
assert.equal(normalizeBetaFlag(undefined), false);
|
||||
assert.equal(normalizeBetaFlag('null'), false);
|
||||
assert.equal(normalizeBetaFlag('TRUE'), false);
|
||||
});
|
||||
|
||||
test('loadConfig 從環境變數組出設定', () => {
|
||||
@@ -53,16 +54,53 @@ test('loadConfig 從環境變數組出設定', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('loadConfig 將未提供的 token 正規化為 null,beta 預設 false', () => {
|
||||
const config = loadConfig({
|
||||
test('loadConfig 將未提供或字面 "null" 的 token 正規化為 null,beta 預設 false', () => {
|
||||
const omitted = loadConfig({
|
||||
GITEA_SERVER_URL: 'https://gitea.example.com',
|
||||
GITEA_REPOSITORY: 'owner/repo',
|
||||
});
|
||||
assert.equal(config.token, null);
|
||||
assert.equal(config.isBeta, false);
|
||||
assert.equal(omitted.token, null);
|
||||
assert.equal(omitted.isBeta, false);
|
||||
|
||||
const literalNull = loadConfig({
|
||||
GITEA_SERVER_URL: 'https://gitea.example.com',
|
||||
GITEA_REPOSITORY: 'owner/repo',
|
||||
GITEA_TOKEN: 'null',
|
||||
});
|
||||
assert.equal(literalNull.token, null);
|
||||
});
|
||||
|
||||
test('loadConfig 在缺少必填環境變數時丟出錯誤', () => {
|
||||
assert.throws(() => loadConfig({ GITEA_REPOSITORY: 'owner/repo' }), /GITEA_SERVER_URL 未設定/);
|
||||
assert.throws(() => loadConfig({ GITEA_SERVER_URL: 'https://x' }), /GITEA_REPOSITORY 未設定/);
|
||||
});
|
||||
|
||||
test('loadConfig 於 GITEA_SERVER_URL 非合法 URL 時拋錯', () => {
|
||||
assert.throws(() => loadConfig({
|
||||
GITEA_SERVER_URL: 'not-a-url',
|
||||
GITEA_REPOSITORY: 'owner/repo',
|
||||
}), /GITEA_SERVER_URL 格式錯誤/);
|
||||
});
|
||||
|
||||
test('loadConfig 於 GITEA_SERVER_URL 使用非 http(s) 協定時拋錯', () => {
|
||||
assert.throws(() => loadConfig({
|
||||
GITEA_SERVER_URL: 'ftp://gitea.example.com',
|
||||
GITEA_REPOSITORY: 'owner/repo',
|
||||
}), /必須使用 http 或 https/);
|
||||
});
|
||||
|
||||
test('loadConfig 於 GITEA_REPOSITORY 非 owner/repo 形式或含路徑穿越時拋錯', () => {
|
||||
const base = { GITEA_SERVER_URL: 'https://gitea.example.com' };
|
||||
assert.throws(() => loadConfig({ ...base, GITEA_REPOSITORY: 'no-slash' }), /GITEA_REPOSITORY 格式錯誤/);
|
||||
assert.throws(() => loadConfig({ ...base, GITEA_REPOSITORY: 'owner/repo/extra' }), /GITEA_REPOSITORY 格式錯誤/);
|
||||
assert.throws(() => loadConfig({ ...base, GITEA_REPOSITORY: '../owner/repo' }), /GITEA_REPOSITORY 格式錯誤/);
|
||||
assert.throws(() => loadConfig({ ...base, GITEA_REPOSITORY: 'owner/..' }), /GITEA_REPOSITORY 格式錯誤/);
|
||||
});
|
||||
|
||||
test('loadConfig 接受含點號的合法 owner/repo', () => {
|
||||
const config = loadConfig({
|
||||
GITEA_SERVER_URL: 'https://gitea.example.com',
|
||||
GITEA_REPOSITORY: 'my.org/my.repo',
|
||||
});
|
||||
assert.equal(config.repository, 'my.org/my.repo');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user