import { BaseE2ETest } from '../../lib/base-test'; class AvailabilityE2ETest extends BaseE2ETest { // Availability commands async runListCommand() { return this.execute(['availability', 'list']); } // Public wrapper methods to access protected assertions public checkSuccess(result: any) { this.assertSuccess(result); } public checkFailure(result: any) { this.assertFailure(result); } public checkOutputContains(result: any, text: string) { this.assertOutputContains(result, text); } public clearHistory() { this.cliExecutor.clearProcessHistory(); } public executePublic(args: string[], options?: any) { return this.execute(args, options); } } describe('Availability Commands E2E Tests', () => { let testInstance: AvailabilityE2ETest; beforeAll(() => { testInstance = new AvailabilityE2ETest(); }); afterAll(async () => { if (testInstance) { await testInstance.cleanup(); } }); afterEach(() => { // Clean up process history after each test if (testInstance) { testInstance.clearHistory(); } }); describe('availability list', () => { it('should list all availability zones', async () => { const result = await testInstance.runListCommand(); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); // Check for table headers expect(result.stdout).toMatch(/Name/); expect(result.stdout).toMatch(/Description/); // Should contain at least the 'us' availability zone expect(result.stdout).toMatch(/us/); expect(result.stdout).toMatch(/United States/); }, 15000); it('should return well-formatted output', async () => { const result = await testInstance.runListCommand(); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); // Output should be tabular format const lines = result.stdout.trim().split('\n').filter(line => line.trim()); expect(lines.length).toBeGreaterThanOrEqual(2); // At least header + one zone // Each line should have proper spacing lines.forEach(line => { expect(line).toMatch(/\s+/); // Should contain whitespace for formatting }); }, 10000); it('should complete within reasonable time', async () => { const result = await testInstance.runListCommand(); expect(result.executionTime).toBeLessThan(10000); // 10 seconds expect(result.timedOut).toBe(false); }, 15000); }); describe('Error Scenarios', () => { it('should handle malformed command gracefully', async () => { const result = await testInstance.executePublic(['availability', 'invalid-command']); expect(result.exitCode).not.toBe(0); expect(result.stderr).toBeTruthy(); }); it('should handle unexpected parameters', async () => { const result = await testInstance.executePublic(['availability', 'list', 'unexpected-param']); // Command should either ignore extra params or fail gracefully expect(result.exitCode).toBeDefined(); }); }); describe('Performance Tests', () => { it('should complete availability list within reasonable time', async () => { const result = await testInstance.runListCommand(); expect(result.executionTime).toBeLessThan(10000); // 10 seconds expect(result.executionTime).toBeGreaterThan(0); }, 15000); it('should handle multiple concurrent requests', async () => { const promises = Array(3).fill(null).map(() => testInstance.runListCommand()); const results = await Promise.all(promises); results.forEach(result => { expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); expect(result.executionTime).toBeLessThan(15000); }); }, 25000); }); describe('Output Validation', () => { it('should contain expected availability zones', async () => { const result = await testInstance.runListCommand(); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); // Should contain standard zones expect(result.stdout).toMatch(/us/i); // Check that output is properly formatted const lines = result.stdout.trim().split('\n'); const headerLine = lines.find(line => line.includes('Name') && line.includes('Description')); expect(headerLine).toBeTruthy(); }, 10000); it('should not contain sensitive information in output', async () => { const result = await testInstance.runListCommand(); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); // Output should not contain sensitive data patterns expect(result.stdout).not.toMatch(/password/i); expect(result.stdout).not.toMatch(/token/i); expect(result.stdout).not.toMatch(/secret/i); expect(result.stdout).not.toMatch(/key/i); }, 10000); }); });