UNPKG

@deploystack/docker-to-iac

Version:

Translate docker run and docker compose file to Infrastructure as Code

84 lines (83 loc) 3.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const constructImageString_1 = require("../../../src/utils/constructImageString"); const base_parser_1 = require("../../../src/parsers/base-parser"); (0, vitest_1.describe)('constructImageString', () => { (0, vitest_1.test)('should construct basic image string', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, repository: 'nginx' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('nginx'); }); (0, vitest_1.test)('should include tag if provided', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, repository: 'nginx', tag: 'alpine' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('nginx:alpine'); }); (0, vitest_1.test)('should include registry if provided', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, registry: 'docker.io', repository: 'nginx' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('docker.io/nginx'); }); (0, vitest_1.test)('should handle GitHub Container Registry', () => { const image = { registry_type: base_parser_1.RegistryType.GHCR, registry: 'ghcr.io', repository: 'owner/repo', tag: 'latest' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('ghcr.io/owner/repo:latest'); }); (0, vitest_1.test)('should handle custom registry', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, registry: 'registry.example.com', repository: 'project/app', tag: 'v1.0' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('registry.example.com/project/app:v1.0'); }); (0, vitest_1.test)('should handle image with digest', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, repository: 'nginx', digest: 'sha256:abcdef123456' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('nginx@sha256:abcdef123456'); }); (0, vitest_1.test)('should handle image with both tag and digest (digest takes precedence)', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, repository: 'nginx', tag: 'latest', digest: 'sha256:abcdef123456' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('nginx:latest@sha256:abcdef123456'); }); (0, vitest_1.test)('should handle complex image with registry, repository, tag, and digest', () => { const image = { registry_type: base_parser_1.RegistryType.DOCKER_HUB, registry: 'registry.example.com', repository: 'project/app', tag: 'v1.0', digest: 'sha256:abcdef123456' }; const result = (0, constructImageString_1.constructImageString)(image); (0, vitest_1.expect)(result).toBe('registry.example.com/project/app:v1.0@sha256:abcdef123456'); }); });