105 lines
2.5 KiB
TypeScript
105 lines
2.5 KiB
TypeScript
|
|
/**
|
||
|
|
* Storage helper - S3/MinIO verification utilities for tests
|
||
|
|
*
|
||
|
|
* NOTE: These are stub implementations for testing.
|
||
|
|
* The actual smartbucket API should be verified against the real library.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { testConfig } from '../test.config.ts';
|
||
|
|
|
||
|
|
// Storage is optional for unit/integration tests
|
||
|
|
// E2E tests with actual S3 operations would need proper implementation
|
||
|
|
let storageAvailable = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if test storage is available
|
||
|
|
*/
|
||
|
|
export async function checkStorageAvailable(): Promise<boolean> {
|
||
|
|
try {
|
||
|
|
// Try to connect to MinIO
|
||
|
|
const response = await fetch(`${testConfig.s3.endpoint}/minio/health/live`, {
|
||
|
|
method: 'GET',
|
||
|
|
});
|
||
|
|
storageAvailable = response.ok;
|
||
|
|
return storageAvailable;
|
||
|
|
} catch {
|
||
|
|
storageAvailable = false;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Initialize test storage connection
|
||
|
|
*/
|
||
|
|
export async function setupTestStorage(): Promise<void> {
|
||
|
|
await checkStorageAvailable();
|
||
|
|
if (storageAvailable) {
|
||
|
|
console.log('[Test Storage] MinIO available at', testConfig.s3.endpoint);
|
||
|
|
} else {
|
||
|
|
console.log('[Test Storage] MinIO not available, storage tests will be skipped');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if an object exists in storage (stub)
|
||
|
|
*/
|
||
|
|
export async function objectExists(_key: string): Promise<boolean> {
|
||
|
|
if (!storageAvailable) return false;
|
||
|
|
// Would implement actual check here
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* List objects with a given prefix (stub)
|
||
|
|
*/
|
||
|
|
export async function listObjects(_prefix: string): Promise<string[]> {
|
||
|
|
if (!storageAvailable) return [];
|
||
|
|
// Would implement actual list here
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Delete an object from storage (stub)
|
||
|
|
*/
|
||
|
|
export async function deleteObject(_key: string): Promise<void> {
|
||
|
|
if (!storageAvailable) return;
|
||
|
|
// Would implement actual delete here
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Delete all objects with a given prefix
|
||
|
|
*/
|
||
|
|
export async function deletePrefix(prefix: string): Promise<void> {
|
||
|
|
const objects = await listObjects(prefix);
|
||
|
|
for (const key of objects) {
|
||
|
|
await deleteObject(key);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Clean up test storage
|
||
|
|
*/
|
||
|
|
export async function cleanupTestStorage(): Promise<void> {
|
||
|
|
if (!storageAvailable) return;
|
||
|
|
|
||
|
|
try {
|
||
|
|
// Delete all test objects
|
||
|
|
await deletePrefix('npm/');
|
||
|
|
await deletePrefix('oci/');
|
||
|
|
await deletePrefix('maven/');
|
||
|
|
await deletePrefix('cargo/');
|
||
|
|
await deletePrefix('pypi/');
|
||
|
|
await deletePrefix('composer/');
|
||
|
|
await deletePrefix('rubygems/');
|
||
|
|
} catch {
|
||
|
|
// Ignore errors
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if storage is available
|
||
|
|
*/
|
||
|
|
export function isStorageAvailable(): boolean {
|
||
|
|
return storageAvailable;
|
||
|
|
}
|