Files
FileHost/server/utils/storage-backends.test.ts
T
O96u 8408d01197
GitHub Release / release (push) Canceled after 0s
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
Publish Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Canceled after 0s
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Canceled after 0s
Publish Docker image / merge (push) Canceled after 0s
release: v1.2.6 — 新 UI 体验优化与存储标识规则
2026-09-01 21:31:02 +08:00

41 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
generateStorageBackendId,
resolveObjectStorageIdPrefix
} from './storage-backends'
describe('resolveObjectStorageIdPrefix', () => {
it('uses explicit provider when given', () => {
expect(resolveObjectStorageIdPrefix(
{ endpoint: 'https://example.com' },
'r2'
)).toBe('r2')
expect(resolveObjectStorageIdPrefix(
{ endpoint: 'https://example.com' },
'aws'
)).toBe('s3')
})
it('detects provider from endpoint', () => {
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://abc123.r2.cloudflarestorage.com'
})).toBe('r2')
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://cos.ap-guangzhou.myqcloud.com'
})).toBe('cos')
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com'
})).toBe('oss')
expect(resolveObjectStorageIdPrefix({
endpoint: 'https://s3.us-east-1.amazonaws.com'
})).toBe('s3')
})
})
describe('generateStorageBackendId', () => {
it('uses provider-specific prefix', () => {
expect(generateStorageBackendId('r2')).toMatch(/^r2-[0-9a-f]{8}$/)
expect(generateStorageBackendId('s3')).toMatch(/^s3-[0-9a-f]{8}$/)
})
})