feat(tests): integrate qenv for dynamic configuration and enhance SKR API tests
This commit is contained in:
41
test/helpers/setup.ts
Normal file
41
test/helpers/setup.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
|
||||
// Initialize qenv to load environment variables from .nogit folder
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
// Export configuration for MongoDB and S3
|
||||
export const getTestConfig = async () => {
|
||||
// Try to get individual MongoDB components first
|
||||
const mongoHost = await testQenv.getEnvVarOnDemand('MONGODB_HOST') || 'localhost';
|
||||
const mongoPort = await testQenv.getEnvVarOnDemand('MONGODB_PORT') || '27017';
|
||||
const mongoUser = await testQenv.getEnvVarOnDemand('MONGODB_USER');
|
||||
const mongoPass = await testQenv.getEnvVarOnDemand('MONGODB_PASS');
|
||||
const mongoDbName = await testQenv.getEnvVarOnDemand('MONGODB_NAME') || 'test_skr';
|
||||
|
||||
// Build MongoDB URL with authentication
|
||||
let mongoDbUrl: string;
|
||||
if (mongoUser && mongoPass) {
|
||||
// Include authSource=admin for authentication
|
||||
mongoDbUrl = `mongodb://${mongoUser}:${mongoPass}@${mongoHost}:${mongoPort}/?authSource=admin`;
|
||||
} else {
|
||||
mongoDbUrl = `mongodb://${mongoHost}:${mongoPort}`;
|
||||
}
|
||||
|
||||
// Get S3 configuration
|
||||
const s3Host = await testQenv.getEnvVarOnDemand('S3_HOST');
|
||||
const s3Port = await testQenv.getEnvVarOnDemand('S3_PORT');
|
||||
const s3User = await testQenv.getEnvVarOnDemand('S3_USER');
|
||||
const s3Pass = await testQenv.getEnvVarOnDemand('S3_PASS');
|
||||
const s3Bucket = await testQenv.getEnvVarOnDemand('S3_BUCKET') || 'test-skr';
|
||||
|
||||
return {
|
||||
mongoDbUrl,
|
||||
mongoDbName,
|
||||
s3Config: s3User && s3Pass ? {
|
||||
accessKey: s3User,
|
||||
secretKey: s3Pass,
|
||||
endpoint: s3Host && s3Port ? `http://${s3Host}:${s3Port}` : undefined,
|
||||
bucket: s3Bucket
|
||||
} : null
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user