151 lines
5.0 KiB
JavaScript
151 lines
5.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Microservices Architecture Test Script
|
|
* Tests: Frontend (3001) → API Gateway (8000) → Git Integration (8012)
|
|
*/
|
|
|
|
const axios = require('axios');
|
|
|
|
const SERVICES = {
|
|
FRONTEND: 'http://localhost:3001',
|
|
API_GATEWAY: 'http://localhost:8000',
|
|
GIT_INTEGRATION: 'http://localhost:8012'
|
|
};
|
|
|
|
const TEST_ENDPOINTS = [
|
|
// GitHub Integration Endpoints
|
|
{ path: '/api/github/health', method: 'GET', service: 'git-integration' },
|
|
{ path: '/api/github/auth/github/status', method: 'GET', service: 'git-integration' },
|
|
|
|
// Diff Viewer Endpoints
|
|
{ path: '/api/diffs/repositories', method: 'GET', service: 'git-integration' },
|
|
|
|
// AI Streaming Endpoints
|
|
{ path: '/api/ai/streaming-sessions', method: 'GET', service: 'git-integration' },
|
|
|
|
// VCS Endpoints
|
|
{ path: '/api/vcs/github/auth/start', method: 'GET', service: 'git-integration' }
|
|
];
|
|
|
|
async function testServiceHealth(serviceName, baseUrl) {
|
|
console.log(`\n🔍 Testing ${serviceName} health...`);
|
|
try {
|
|
const response = await axios.get(`${baseUrl}/health`, { timeout: 5000 });
|
|
console.log(`✅ ${serviceName} is healthy: ${response.status}`);
|
|
return true;
|
|
} catch (error) {
|
|
console.log(`❌ ${serviceName} is unhealthy: ${error.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function testEndpoint(endpoint) {
|
|
console.log(`\n🔍 Testing ${endpoint.method} ${endpoint.path}...`);
|
|
|
|
// Test direct service call
|
|
try {
|
|
const directUrl = `${SERVICES.GIT_INTEGRATION}${endpoint.path}`;
|
|
const directResponse = await axios({
|
|
method: endpoint.method,
|
|
url: directUrl,
|
|
timeout: 10000,
|
|
validateStatus: () => true
|
|
});
|
|
console.log(`✅ Direct service call: ${directResponse.status}`);
|
|
} catch (error) {
|
|
console.log(`❌ Direct service call failed: ${error.message}`);
|
|
}
|
|
|
|
// Test through API Gateway
|
|
try {
|
|
const gatewayUrl = `${SERVICES.API_GATEWAY}${endpoint.path}`;
|
|
const gatewayResponse = await axios({
|
|
method: endpoint.method,
|
|
url: gatewayUrl,
|
|
timeout: 10000,
|
|
validateStatus: () => true
|
|
});
|
|
console.log(`✅ Gateway call: ${gatewayResponse.status}`);
|
|
} catch (error) {
|
|
console.log(`❌ Gateway call failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
async function testFrontendIntegration() {
|
|
console.log(`\n🔍 Testing Frontend Integration...`);
|
|
|
|
// Test if frontend is running
|
|
try {
|
|
const response = await axios.get(SERVICES.FRONTEND, { timeout: 5000 });
|
|
console.log(`✅ Frontend is accessible: ${response.status}`);
|
|
} catch (error) {
|
|
console.log(`❌ Frontend is not accessible: ${error.message}`);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
async function runArchitectureTest() {
|
|
console.log('🚀 Starting Microservices Architecture Test');
|
|
console.log('='.repeat(60));
|
|
|
|
// Test service health
|
|
const gitIntegrationHealthy = await testServiceHealth('Git Integration Service', SERVICES.GIT_INTEGRATION);
|
|
const apiGatewayHealthy = await testServiceHealth('API Gateway', SERVICES.API_GATEWAY);
|
|
const frontendHealthy = await testFrontendIntegration();
|
|
|
|
console.log('\n📊 Service Health Summary:');
|
|
console.log(`Git Integration (8012): ${gitIntegrationHealthy ? '✅' : '❌'}`);
|
|
console.log(`API Gateway (8000): ${apiGatewayHealthy ? '✅' : '❌'}`);
|
|
console.log(`Frontend (3001): ${frontendHealthy ? '✅' : '❌'}`);
|
|
|
|
if (!gitIntegrationHealthy || !apiGatewayHealthy) {
|
|
console.log('\n❌ Critical services are down. Please start the services first.');
|
|
console.log('Run: docker-compose up -d');
|
|
return;
|
|
}
|
|
|
|
// Test endpoints
|
|
console.log('\n🔍 Testing Endpoints...');
|
|
for (const endpoint of TEST_ENDPOINTS) {
|
|
await testEndpoint(endpoint);
|
|
}
|
|
|
|
// Test routing flow
|
|
console.log('\n🔍 Testing Routing Flow...');
|
|
console.log('Frontend (3001) → API Gateway (8000) → Git Integration (8012)');
|
|
|
|
// Test a simple endpoint through the complete flow
|
|
try {
|
|
const testUrl = `${SERVICES.API_GATEWAY}/api/github/health`;
|
|
const response = await axios.get(testUrl, { timeout: 10000 });
|
|
console.log(`✅ Complete flow test: ${response.status}`);
|
|
console.log(`Response: ${JSON.stringify(response.data, null, 2)}`);
|
|
} catch (error) {
|
|
console.log(`❌ Complete flow test failed: ${error.message}`);
|
|
}
|
|
|
|
console.log('\n🎯 Architecture Test Complete');
|
|
console.log('='.repeat(60));
|
|
|
|
if (gitIntegrationHealthy && apiGatewayHealthy && frontendHealthy) {
|
|
console.log('✅ All services are healthy and properly configured!');
|
|
console.log('\n📋 Next Steps:');
|
|
console.log('1. Start all services: docker-compose up -d');
|
|
console.log('2. Test frontend at: http://localhost:3001');
|
|
console.log('3. Test API Gateway at: http://localhost:8000');
|
|
console.log('4. Test Git Integration at: http://localhost:8012');
|
|
} else {
|
|
console.log('❌ Some services need attention. Check the logs above.');
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
if (require.main === module) {
|
|
runArchitectureTest().catch(console.error);
|
|
}
|
|
|
|
module.exports = { runArchitectureTest, testServiceHealth, testEndpoint };
|