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

Add tests for git stacks

FoxxMD (Aug 13, 2025, 2:54 PM UTC) 2e278469 b2afbb8b

+108 -6
+1 -1
src/builders/stack/gitStack.ts
··· 22 22 autoUpdate = false, 23 23 pollForUpdate = false, 24 24 server, 25 - inMonorepo, 25 + inMonorepo = false, 26 26 hostParentPath 27 27 } = options 28 28
+107 -5
tests/git.test.ts
··· 2 2 import chai, { expect } from 'chai'; 3 3 import { parseGitStatus } from '../src/common/utils/git.js'; 4 4 import { stripIndents } from 'common-tags'; 5 + import withLocalTmpDir from 'with-local-tmp-dir'; 6 + import { mkdir, writeFile, chmod, constants } from 'node:fs/promises'; 7 + import path from "path"; 8 + import { buildGitStack, BuildGitStackOptions } from '../src/builders/stack/gitStack.js'; 9 + import { loggerTest } from "@foxxmd/logging"; 10 + import chaiAsPromised from 'chai-as-promised'; 11 + import git from 'isomorphic-git'; 12 + import fs from 'fs'; 13 + import { execa, Options } from 'execa'; 14 + 15 + chai.use(chaiAsPromised); 16 + 17 + const DEFAULT_SERVER = 'test-server'; 18 + 19 + const defaultGitStandaloneConfig: BuildGitStackOptions = { 20 + server: DEFAULT_SERVER, 21 + logger: loggerTest 22 + } 5 23 6 24 describe('#Git', function () { 7 25 ··· 45 63 } 46 64 ] 47 65 48 - for(const o of outputs) { 49 - const parsed = parseGitStatus(o.out); 66 + for (const o of outputs) { 67 + const parsed = parseGitStatus(o.out); 50 68 51 - expect(parsed.branch).to.eq(o.expect.branch); 52 - expect(parsed.remote).to.eq(o.expect.remote); 53 - expect(parsed.remoteBranch).to.eq(o.expect.remoteBranch); 69 + expect(parsed.branch).to.eq(o.expect.branch); 70 + expect(parsed.remote).to.eq(o.expect.remote); 71 + expect(parsed.remoteBranch).to.eq(o.expect.remoteBranch); 54 72 } 55 73 56 74 ··· 92 110 expect(parsed.remoteBranch).to.eq('main'); 93 111 } 94 112 113 + }); 114 + }); 115 + 116 + describe('#GitStack', function () { 117 + 118 + it(`detects as not a git repo when no .git folder is present`, async function () { 119 + await withLocalTmpDir(async () => { 120 + const dir = path.join(process.cwd(), 'test_1'); 121 + 122 + await mkdir(dir); 123 + await expect(buildGitStack(dir, defaultGitStandaloneConfig)).to.eventually.be.rejected; 124 + }, { unsafeCleanup: true }); 125 + }); 126 + 127 + it(`detects as not a git repo when .git folder is ill-defined`, async function () { 128 + await withLocalTmpDir(async () => { 129 + const dir = path.join(process.cwd(), 'test_1'); 130 + await mkdir(dir, { recursive: true }); 131 + await mkdir(path.join(dir, '.git')) 132 + await expect(buildGitStack(dir, defaultGitStandaloneConfig)).to.eventually.be.rejected; 133 + }, { unsafeCleanup: true }); 134 + }); 135 + 136 + it(`detects as not a suitable git repo when no remote repository`, async function () { 137 + await withLocalTmpDir(async () => { 138 + const dir = path.join(process.cwd(), 'test_1'); 139 + await mkdir(dir, { recursive: true }); 140 + await git.init({ fs, dir }); 141 + await expect(buildGitStack(dir, defaultGitStandaloneConfig)).to.eventually.be.rejectedWith('Folder has a .git folder but could not find a suitable remote'); 142 + }, { unsafeCleanup: true }); 143 + }); 144 + 145 + it(`detects as not a suitable git repo when tracked branch does not have a remote`, async function () { 146 + await withLocalTmpDir(async () => { 147 + const dir = path.join(process.cwd(), 'test_1'); 148 + await mkdir(dir); 149 + const localDir = path.join(dir, 'local'); 150 + await mkdir(localDir); 151 + const remoteDir = path.join(dir, 'remote'); 152 + await mkdir(remoteDir); 153 + await git.init({ fs, dir: localDir }); 154 + await git.commit({ 155 + fs, 156 + dir: localDir, 157 + author: { 158 + name: 'Mr. Test', 159 + email: 'mrtest@example.com', 160 + }, 161 + message: 'Added the a.txt file' 162 + }) 163 + await git.init({ fs, dir: remoteDir }); 164 + await git.addRemote({ 165 + fs, 166 + remote: 'origin', 167 + url: '../remote', 168 + dir: remoteDir 169 + }); 170 + await expect(buildGitStack(localDir, defaultGitStandaloneConfig)).to.eventually.be.rejectedWith('Folder has a .git folder but could not find a suitable remote'); 171 + }, { unsafeCleanup: true }); 172 + }); 173 + 174 + it(`detects as a suitable git repo when tracked branch has a remote`, async function () { 175 + await withLocalTmpDir(async () => { 176 + const dir = path.join(process.cwd(), 'test_1'); 177 + await mkdir(dir); 178 + const localDir = path.join(dir, 'local'); 179 + //await mkdir(localDir); 180 + const remoteDir = path.join(dir, 'remote'); 181 + await mkdir(remoteDir); 182 + await git.init({ fs, dir: remoteDir }); 183 + await git.commit({ 184 + fs, 185 + dir: remoteDir, 186 + author: { 187 + name: 'Mr. Test', 188 + email: 'mrtest@example.com', 189 + }, 190 + message: 'Added the a.txt file' 191 + }); 192 + // cannot yet clone local repo with isomorphic git 193 + // https://github.com/isomorphic-git/isomorphic-git/issues/1263 194 + await execa({cwd: dir})`git clone remote local` 195 + await expect(buildGitStack(localDir, defaultGitStandaloneConfig)).to.eventually.be.fulfilled; 196 + }, { unsafeCleanup: true }); 95 197 }); 96 198 }); 97 199 });