Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/__test__
diff options
context:
space:
mode:
Diffstat (limited to '__test__')
-rw-r--r--__test__/git-auth-helper.test.ts3
-rw-r--r--__test__/git-directory-helper.test.ts62
2 files changed, 65 insertions, 0 deletions
diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts
index 2acec38..b58010b 100644
--- a/__test__/git-auth-helper.test.ts
+++ b/__test__/git-auth-helper.test.ts
@@ -770,6 +770,9 @@ async function setup(testName: string): Promise<void> {
return ''
}),
submoduleSync: jest.fn(),
+ submoduleStatus: jest.fn(async () => {
+ return true
+ }),
submoduleUpdate: jest.fn(),
tagExists: jest.fn(),
tryClean: jest.fn(),
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