118 lines
3.5 KiB
JavaScript
118 lines
3.5 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
/**
|
||
* Configuration Validation Script
|
||
* Tests that all configuration modules can be loaded and validated
|
||
*/
|
||
|
||
// Set test environment variables
|
||
process.env.NODE_ENV = 'test';
|
||
process.env.PORT = '3001';
|
||
|
||
// Database configs
|
||
process.env.DB_HOST = 'localhost';
|
||
process.env.DB_PORT = '5432';
|
||
process.env.DB_NAME = 'test_db';
|
||
process.env.DB_USER = 'test_user';
|
||
process.env.DB_PASSWORD = 'test_pass';
|
||
|
||
// QuestDB configs
|
||
process.env.QUESTDB_HOST = 'localhost';
|
||
process.env.QUESTDB_HTTP_PORT = '9000';
|
||
process.env.QUESTDB_PG_PORT = '8812';
|
||
|
||
// MongoDB configs
|
||
process.env.MONGODB_HOST = 'localhost';
|
||
process.env.MONGODB_PORT = '27017';
|
||
process.env.MONGODB_DATABASE = 'test_db';
|
||
|
||
// Dragonfly configs
|
||
process.env.DRAGONFLY_HOST = 'localhost';
|
||
process.env.DRAGONFLY_PORT = '6379';
|
||
|
||
// Monitoring configs
|
||
process.env.PROMETHEUS_HOST = 'localhost';
|
||
process.env.PROMETHEUS_PORT = '9090';
|
||
process.env.GRAFANA_HOST = 'localhost';
|
||
process.env.GRAFANA_PORT = '3000';
|
||
|
||
// Loki configs
|
||
process.env.LOKI_HOST = 'localhost';
|
||
process.env.LOKI_PORT = '3100';
|
||
|
||
// Logging configs
|
||
process.env.LOG_LEVEL = 'info';
|
||
process.env.LOG_FORMAT = 'json';
|
||
|
||
try {
|
||
console.log('🔍 Validating configuration modules...\n');
|
||
|
||
// Test each configuration module
|
||
const modules = [
|
||
{ name: 'Database', path: './dist/database.js' },
|
||
{ name: 'QuestDB', path: './dist/questdb.js' },
|
||
{ name: 'MongoDB', path: './dist/mongodb.js' },
|
||
{ name: 'Dragonfly', path: './dist/dragonfly.js' },
|
||
{ name: 'Monitoring', path: './dist/monitoring.js' },
|
||
{ name: 'Loki', path: './dist/loki.js' },
|
||
{ name: 'Logging', path: './dist/logging.js' },
|
||
];
|
||
|
||
const results = [];
|
||
|
||
for (const module of modules) {
|
||
try {
|
||
const config = require(module.path);
|
||
const configKeys = Object.keys(config);
|
||
|
||
if (configKeys.length === 0) {
|
||
throw new Error('No exported configuration found');
|
||
}
|
||
|
||
// Try to access the main config object
|
||
const mainConfig = config[configKeys[0]];
|
||
if (!mainConfig || typeof mainConfig !== 'object') {
|
||
throw new Error('Invalid configuration object');
|
||
}
|
||
|
||
console.log(`✅ ${module.name}: ${configKeys.length} config(s) loaded`);
|
||
results.push({ name: module.name, status: 'success', configs: configKeys });
|
||
|
||
} catch (error) {
|
||
console.log(`❌ ${module.name}: ${error.message}`);
|
||
results.push({ name: module.name, status: 'error', error: error.message });
|
||
}
|
||
}
|
||
|
||
// Test main index exports
|
||
try {
|
||
const indexExports = require('./dist/index.js');
|
||
const exportCount = Object.keys(indexExports).length;
|
||
console.log(`\n✅ Index exports: ${exportCount} modules exported`);
|
||
results.push({ name: 'Index', status: 'success', exports: exportCount });
|
||
} catch (error) {
|
||
console.log(`\n❌ Index exports: ${error.message}`);
|
||
results.push({ name: 'Index', status: 'error', error: error.message });
|
||
}
|
||
|
||
// Summary
|
||
const successful = results.filter(r => r.status === 'success').length;
|
||
const total = results.length;
|
||
|
||
console.log(`\n📊 Validation Summary:`);
|
||
console.log(` Total modules: ${total}`);
|
||
console.log(` Successful: ${successful}`);
|
||
console.log(` Failed: ${total - successful}`);
|
||
|
||
if (successful === total) {
|
||
console.log('\n🎉 All configuration modules validated successfully!');
|
||
process.exit(0);
|
||
} else {
|
||
console.log('\n⚠️ Some configuration modules failed validation.');
|
||
process.exit(1);
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('❌ Validation script failed:', error.message);
|
||
process.exit(1);
|
||
}
|