UNPKG

@deploystack/docker-to-iac

Version:

Translate docker run and docker compose file to Infrastructure as Code

43 lines (42 loc) 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const factory_1 = require("../../../src/sources/factory"); const compose_1 = require("../../../src/sources/compose"); const run_1 = require("../../../src/sources/run"); (0, vitest_1.describe)('createSourceParser', () => { (0, vitest_1.test)('should create a ComposeParser when type is compose', () => { const parser = (0, factory_1.createSourceParser)('compose'); (0, vitest_1.expect)(parser).toBeInstanceOf(compose_1.ComposeParser); (0, vitest_1.expect)(parser).toBeInstanceOf(Object); (0, vitest_1.expect)(parser).toHaveProperty('parse'); (0, vitest_1.expect)(parser).toHaveProperty('validate'); }); (0, vitest_1.test)('should create a RunCommandParser when type is run', () => { const parser = (0, factory_1.createSourceParser)('run'); (0, vitest_1.expect)(parser).toBeInstanceOf(run_1.RunCommandParser); (0, vitest_1.expect)(parser).toBeInstanceOf(Object); (0, vitest_1.expect)(parser).toHaveProperty('parse'); (0, vitest_1.expect)(parser).toHaveProperty('validate'); }); (0, vitest_1.test)('should throw an error for unsupported source type', () => { // Using type assertion to bypass TypeScript's type checking // In a real scenario, this might happen if the factory is called with a user-provided value (0, vitest_1.expect)(() => (0, factory_1.createSourceParser)('unsupported')).toThrow('Unsupported source type: unsupported'); }); (0, vitest_1.test)('should return objects that implement SourceParser interface', () => { const composeParser = (0, factory_1.createSourceParser)('compose'); const runParser = (0, factory_1.createSourceParser)('run'); // Verify both parsers implement the required interface methods (0, vitest_1.expect)(typeof composeParser.parse).toBe('function'); (0, vitest_1.expect)(typeof composeParser.validate).toBe('function'); (0, vitest_1.expect)(typeof runParser.parse).toBe('function'); (0, vitest_1.expect)(typeof runParser.validate).toBe('function'); // Verify the returned objects can be typed as SourceParser const assertParser = (parser) => { (0, vitest_1.expect)(parser).toBeDefined(); }; assertParser(composeParser); assertParser(runParser); }); });