@deploystack/docker-to-iac
Version:
Translate docker run and docker compose file to Infrastructure as Code
71 lines (70 loc) • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const normalizeEnvironment_1 = require("../../../src/utils/normalizeEnvironment");
(0, vitest_1.describe)('normalizeEnvironment', () => {
(0, vitest_1.test)('should handle undefined input', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)(undefined);
(0, vitest_1.expect)(result).toEqual({});
});
(0, vitest_1.test)('should handle string input with key=value format', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)('NODE_ENV=production');
(0, vitest_1.expect)(result).toEqual({
NODE_ENV: 'production'
});
});
(0, vitest_1.test)('should handle string input with quoted values', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)('SECRET_KEY="super-secret"');
(0, vitest_1.expect)(result).toEqual({
SECRET_KEY: 'super-secret'
});
});
(0, vitest_1.test)('should handle array input', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)([
'NODE_ENV=production',
'PORT=3000',
'DEBUG=true'
]);
(0, vitest_1.expect)(result).toEqual({
NODE_ENV: 'production',
PORT: '3000',
DEBUG: 'true'
});
});
(0, vitest_1.test)('should handle object input', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)({
NODE_ENV: 'production',
PORT: '3000',
DEBUG: 'true'
});
(0, vitest_1.expect)(result).toEqual({
NODE_ENV: 'production',
PORT: '3000',
DEBUG: 'true'
});
});
(0, vitest_1.test)('should resolve environment variables', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)('DATABASE_URL=${DB_URL}', { DB_URL: 'postgres://localhost:5432/db' });
(0, vitest_1.expect)(result).toEqual({
DATABASE_URL: '${DB_URL}' // Note: actual resolution happens in resolveEnvironmentValue
});
});
(0, vitest_1.test)('should handle equals sign in values', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)('CONNECTION_STRING=user=admin;password=pass');
(0, vitest_1.expect)(result).toEqual({
CONNECTION_STRING: 'user=admin;password=pass'
});
});
(0, vitest_1.test)('should handle empty values', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)('EMPTY_VAR=');
(0, vitest_1.expect)(result).toEqual({
EMPTY_VAR: ''
});
});
(0, vitest_1.test)('should trim keys and values', () => {
const result = (0, normalizeEnvironment_1.normalizeEnvironment)(' SPACES = value with spaces ');
(0, vitest_1.expect)(result).toEqual({
SPACES: 'value with spaces'
});
});
});