diff options
| author | SKi <megamanics@users.noreply.github.com> | 2023-04-14 03:26:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-14 06:26:47 -0400 |
| commit | 0023cf10d2f41d4eddfd3d6ad7ad99a1152ef708 (patch) | |
| tree | 54997dba50eeec3cbc1e3119122ed65b062042b2 /__test__/git-directory-helper.test.ts | |
| parent | 72a27d858e989e4f80fdb9a9747ee908f946c62e (diff) | |
Fix: Checkout fail in self-hosted runners when faulty submodule are checked-in (#1196)
* Fix Self hosted runner issue wrt bad submodules - solution cleanup working space.
* Fix format with npm run format output
* Add mock implementation for new function submoduleStatus
* Add 2 test cases for submodule status.
* Codeql-Action Analyse revert v1 to v2
---------
Co-authored-by: Bassem Dghaidi <568794+Link-@users.noreply.github.com>
Co-authored-by: sminnie <minnie@sankhe.com>
Diffstat (limited to '__test__/git-directory-helper.test.ts')
| -rw-r--r-- | __test__/git-directory-helper.test.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts index 70849b5..02118ae 100644 --- a/__test__/git-directory-helper.test.ts +++ b/__test__/git-directory-helper.test.ts @@ -281,6 +281,65 @@ describe('git-directory-helper tests', () => { expect(git.branchDelete).toHaveBeenCalledWith(false, 'local-branch-2') }) + const cleanWhenSubmoduleStatusIsFalse = + 'cleans when submodule status is false' + + it(cleanWhenSubmoduleStatusIsFalse, async () => { + // Arrange + await setup(cleanWhenSubmoduleStatusIsFalse) + await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '') + + //mock bad submodule + + const submoduleStatus = git.submoduleStatus as jest.Mock<any, any> + submoduleStatus.mockImplementation(async (remote: boolean) => { + return false + }) + + // Act + await gitDirectoryHelper.prepareExistingDirectory( + git, + repositoryPath, + repositoryUrl, + clean, + ref + ) + + // Assert + const files = await fs.promises.readdir(repositoryPath) + expect(files).toHaveLength(0) + expect(git.tryClean).toHaveBeenCalled() + }) + + const doesNotCleanWhenSubmoduleStatusIsTrue = + 'does not clean when submodule status is true' + + it(doesNotCleanWhenSubmoduleStatusIsTrue, async () => { + // Arrange + await setup(doesNotCleanWhenSubmoduleStatusIsTrue) + await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '') + + const submoduleStatus = git.submoduleStatus as jest.Mock<any, any> + submoduleStatus.mockImplementation(async (remote: boolean) => { + return true + }) + + // Act + await gitDirectoryHelper.prepareExistingDirectory( + git, + repositoryPath, + repositoryUrl, + clean, + ref + ) + + // Assert + + const files = await fs.promises.readdir(repositoryPath) + expect(files.sort()).toEqual(['.git', 'my-file']) + expect(git.tryClean).toHaveBeenCalled() + }) + const removesLockFiles = 'removes lock files' it(removesLockFiles, async () => { // Arrange @@ -423,6 +482,9 @@ async function setup(testName: string): Promise<void> { submoduleForeach: jest.fn(), submoduleSync: jest.fn(), submoduleUpdate: jest.fn(), + submoduleStatus: jest.fn(async () => { + return true + }), tagExists: jest.fn(), tryClean: jest.fn(async () => { return true |
