[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.

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