@deploystack/docker-to-iac
Version:
Translate docker run and docker compose file to Infrastructure as Code
79 lines (78 loc) • 3.33 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const normalizeVolume_1 = require("../../../src/utils/normalizeVolume");
(0, vitest_1.describe)('normalizeVolume', () => {
(0, vitest_1.test)('should normalize simple path as both host and container', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('/data');
(0, vitest_1.expect)(result).toEqual({
host: '/data',
container: '/data'
});
});
(0, vitest_1.test)('should normalize host:container format', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('/host/path:/container/path');
(0, vitest_1.expect)(result).toEqual({
host: '/host/path',
container: '/container/path'
});
});
(0, vitest_1.test)('should normalize host:container:mode format', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('/host/path:/container/path:ro');
(0, vitest_1.expect)(result).toEqual({
host: '/host/path',
container: '/container/path',
mode: 'ro'
});
});
(0, vitest_1.test)('should normalize paths with $HOME environment variable', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('$HOME/data:/app/data');
(0, vitest_1.expect)(result).toEqual({
host: './data',
container: '/app/data'
});
});
(0, vitest_1.test)('should normalize paths with ${HOME} environment variable', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('${HOME}/data:/app/data');
(0, vitest_1.expect)(result).toEqual({
host: './data',
container: '/app/data'
});
});
(0, vitest_1.test)('should normalize paths with ~/ as home directory', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('~/data:/app/data');
(0, vitest_1.expect)(result).toEqual({
host: './data',
container: '/app/data'
});
});
(0, vitest_1.test)('should handle named volumes', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('volume_name:/container/path');
(0, vitest_1.expect)(result).toEqual({
host: 'volume_name',
container: '/container/path'
});
});
(0, vitest_1.test)('should handle named volumes with mode', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('volume_name:/container/path:rw');
(0, vitest_1.expect)(result).toEqual({
host: 'volume_name',
container: '/container/path',
mode: 'rw'
});
});
(0, vitest_1.test)('should handle relative paths', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('./data:/app/data');
(0, vitest_1.expect)(result).toEqual({
host: './data',
container: '/app/data'
});
});
(0, vitest_1.test)('should handle multiple environment variables in path', () => {
const result = (0, normalizeVolume_1.normalizeVolume)('$HOME/data/${PROJECT_NAME}:/app/data');
(0, vitest_1.expect)(result).toEqual({
host: './data/${PROJECT_NAME}',
container: '/app/data'
});
});
});