@deploystack/docker-to-iac
Version:
Translate docker run and docker compose file to Infrastructure as Code
66 lines (65 loc) • 2.49 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const normalizePort_1 = require("../../../src/utils/normalizePort");
(0, vitest_1.describe)('normalizePort', () => {
(0, vitest_1.test)('should normalize simple port mapping', () => {
const result = (0, normalizePort_1.normalizePort)('8080:80');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80
});
});
(0, vitest_1.test)('should normalize single port', () => {
const result = (0, normalizePort_1.normalizePort)('8080');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 8080
});
});
(0, vitest_1.test)('should normalize port with protocol', () => {
const result = (0, normalizePort_1.normalizePort)('8080:80/tcp');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80,
protocol: 'tcp'
});
});
(0, vitest_1.test)('should normalize port with IP address', () => {
const result = (0, normalizePort_1.normalizePort)('127.0.0.1:8080:80');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80
});
});
(0, vitest_1.test)('should normalize port with environment variable and default value', () => {
const result = (0, normalizePort_1.normalizePort)('${PORT:-8080}:80');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80
});
});
(0, vitest_1.test)('should handle negative numbers by using absolute value', () => {
const result = (0, normalizePort_1.normalizePort)('-8080:-80');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80
});
});
(0, vitest_1.test)('should handle port with protocol in different format', () => {
const result = (0, normalizePort_1.normalizePort)('8080:80/udp');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80,
protocol: 'udp'
});
});
(0, vitest_1.test)('should handle complex port mapping', () => {
const result = (0, normalizePort_1.normalizePort)('127.0.0.1:${PORT:-8080}:80/tcp');
(0, vitest_1.expect)(result).toEqual({
host: 8080,
container: 80,
protocol: 'tcp'
});
});
});