[READ-ONLY] Mirror of https://github.com/FoxxMD/komodo-import. Import existing compose stacks into Komodo foxxmd.github.io/komodo-import
compose docker import komodo toml
0

Configure Feed

Select the types of activity you want to include in your feed.

test: Add initial tests

FoxxMD (Aug 11, 2025, 4:05 PM UTC) a41b1f61 5103fba6

+166
+166
tests/filesOnServer.test.ts
··· 1 + import { describe, it } from 'mocha'; 2 + import chai, { expect } from 'chai'; 3 + import withLocalTmpDir from 'with-local-tmp-dir'; 4 + import { mkdir, writeFile, chmod, constants } from 'node:fs/promises'; 5 + import path from "path"; 6 + import { loggerTest } from "@foxxmd/logging"; 7 + import { buildFileStack, BuildFileStackOptions } from '../src/builders/stack/filesOnServer.js'; 8 + import { FilesOnServerConfig } from '../src/common/infrastructure/config/filesOnServer.js'; 9 + 10 + const DEFAULT_FOS_PATH = '/my/cool' 11 + const DEFAULT_SERVER = 'test-server'; 12 + 13 + const defaultFOSConfig: BuildFileStackOptions = { 14 + server: DEFAULT_SERVER, 15 + hostParentPath: DEFAULT_FOS_PATH, 16 + logger: loggerTest, 17 + komodoEnvName: '.komodoEnv', 18 + } 19 + 20 + describe('#FilesOnServer', function () { 21 + 22 + it(`sets server`, async function () { 23 + await withLocalTmpDir(async () => { 24 + const dir = path.join(process.cwd(), 'test_1'); 25 + 26 + await mkdir(dir); 27 + const data = await buildFileStack(dir, defaultFOSConfig); 28 + 29 + expect(data.config.server).eq(DEFAULT_SERVER); 30 + }, { unsafeCleanup: true }); 31 + }); 32 + 33 + it(`sets run_directory from hostParentPath`, async function () { 34 + await withLocalTmpDir(async () => { 35 + const dir = path.join(process.cwd(), 'test_1'); 36 + 37 + await mkdir(dir); 38 + const data = await buildFileStack(dir, defaultFOSConfig); 39 + 40 + expect(data.config.run_directory).eq(path.join(defaultFOSConfig.hostParentPath, 'test_1')); 41 + }, { unsafeCleanup: true }); 42 + }); 43 + 44 + describe('Compose Files', function () { 45 + 46 + it(`does not include file_paths when no compose file found`, async function () { 47 + await withLocalTmpDir(async () => { 48 + const dir = path.join(process.cwd(), 'test_1'); 49 + 50 + await mkdir(dir); 51 + const data = await buildFileStack(dir, defaultFOSConfig); 52 + 53 + expect(data.config.file_paths).to.be.undefined; 54 + }, { unsafeCleanup: true }); 55 + }); 56 + 57 + it(`includes compose file when one is found`, async function () { 58 + await withLocalTmpDir(async () => { 59 + 60 + const dir = path.join(process.cwd(), 'test_1'); 61 + await mkdir(dir); 62 + const fileName = 'docker-compose.yaml'; 63 + await writeFile(path.join(dir, fileName), ''); 64 + 65 + const data = await buildFileStack(dir, defaultFOSConfig); 66 + 67 + expect(data.config.file_paths).to.not.be.undefined; 68 + expect(data.config.file_paths.length).eq(1); 69 + expect(data.config.file_paths[0]).eq(fileName) 70 + 71 + }, { unsafeCleanup: true }); 72 + }); 73 + 74 + it(`does not use file_paths if only one compose file selected and it is named 'compose.yaml'`, async function () { 75 + await withLocalTmpDir(async () => { 76 + 77 + const dir = path.join(process.cwd(), 'test_1'); 78 + await mkdir(dir); 79 + const fileName = 'compose.yaml'; 80 + await writeFile(path.join(dir, fileName), ''); 81 + await mkdir(path.join(dir, 'nested')); 82 + await writeFile(path.join(dir, 'nested', fileName), ''); 83 + 84 + const data = await buildFileStack(dir, defaultFOSConfig); 85 + 86 + expect(data.config.file_paths).to.be.undefined; 87 + }, { unsafeCleanup: true }); 88 + }); 89 + 90 + it(`includes only one compose file when using default glob`, async function () { 91 + await withLocalTmpDir(async () => { 92 + 93 + const dir = path.join(process.cwd(), 'test_1'); 94 + await mkdir(dir); 95 + await writeFile(path.join(dir, 'docker-compose.yaml'), ''); 96 + await writeFile(path.join(dir, 'compose.prod.yaml'), ''); 97 + 98 + const data = await buildFileStack(dir, { ...defaultFOSConfig }); 99 + 100 + expect(data.config.file_paths).to.not.be.undefined; 101 + expect(data.config.file_paths.length).eq(1); 102 + }, { unsafeCleanup: true }); 103 + }); 104 + 105 + it(`includes all compose files when using non-default glob`, async function () { 106 + await withLocalTmpDir(async () => { 107 + 108 + const dir = path.join(process.cwd(), 'test_1'); 109 + await mkdir(dir); 110 + await writeFile(path.join(dir, 'docker-compose.yaml'), ''); 111 + await writeFile(path.join(dir, 'compose.prod.yaml'), ''); 112 + 113 + const data = await buildFileStack(dir, { ...defaultFOSConfig, composeFileGlob: '**/{compose,docker-compose}*.yaml' }); 114 + 115 + expect(data.config.file_paths).to.not.be.undefined; 116 + expect(data.config.file_paths.length).eq(2); 117 + }, { unsafeCleanup: true }); 118 + }); 119 + 120 + }); 121 + 122 + describe('ENV Files', function () { 123 + 124 + it(`does not include additional_env_files when no env files found`, async function () { 125 + await withLocalTmpDir(async () => { 126 + const dir = path.join(process.cwd(), 'test_1'); 127 + 128 + await mkdir(dir); 129 + const data = await buildFileStack(dir, defaultFOSConfig); 130 + 131 + expect(data.config.additional_env_files).to.be.undefined; 132 + }, { unsafeCleanup: true }); 133 + }); 134 + 135 + it(`includes additional_env_files when env files found`, async function () { 136 + await withLocalTmpDir(async () => { 137 + const dir = path.join(process.cwd(), 'test_1'); 138 + 139 + await mkdir(dir); 140 + await writeFile(path.join(dir, '.env'), ''); 141 + await mkdir(path.join(dir, 'nested')); 142 + await writeFile(path.join(dir, 'nested', '.env'), ''); 143 + const data = await buildFileStack(dir, defaultFOSConfig); 144 + 145 + expect(data.config.additional_env_files).to.not.be.undefined; 146 + expect(data.config.additional_env_files.length).eq(2); 147 + expect(data.config.additional_env_files[0]).eq('.env'); 148 + expect(data.config.additional_env_files[1]).eq('nested/.env'); 149 + }, { unsafeCleanup: true }); 150 + }); 151 + 152 + it(`uses komodo env name when env files found`, async function () { 153 + await withLocalTmpDir(async () => { 154 + const dir = path.join(process.cwd(), 'test_1'); 155 + 156 + await mkdir(dir); 157 + await writeFile(path.join(dir, '.env'), ''); 158 + const data = await buildFileStack(dir, defaultFOSConfig); 159 + 160 + expect(data.config.env_file_path).eq(defaultFOSConfig.komodoEnvName) 161 + }, { unsafeCleanup: true }); 162 + }); 163 + 164 + }); 165 + 166 + });