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:
authoreric sciple <ericsciple@users.noreply.github.com>2020-03-18 23:33:26 -0400
committereric sciple <ericsciple@users.noreply.github.com>2020-03-18 23:33:26 -0400
commitd35c5b0d45c2389911e8fa57f5a409dc7eb4eba9 (patch)
tree9504842130011e5303867f926b8e6016a715323e /__test__
parent6f1b729011b34bc28608462b6293df85180aba9c (diff)
use token for workflow repo
Diffstat (limited to '__test__')
-rw-r--r--__test__/git-auth-helper.test.ts4
-rw-r--r--__test__/git-directory-helper.test.ts75
2 files changed, 60 insertions, 19 deletions
diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts
index 1d5c3d5..026be7c 100644
--- a/__test__/git-auth-helper.test.ts
+++ b/__test__/git-auth-helper.test.ts
@@ -725,6 +725,7 @@ async function setup(testName: string): Promise<void> {
setEnvironmentVariable: jest.fn((name: string, value: string) => {
git.env[name] = value
}),
+ setRemoteUrl: jest.fn(),
submoduleForeach: jest.fn(async () => {
return ''
}),
@@ -748,7 +749,7 @@ async function setup(testName: string): Promise<void> {
}
),
tryDisableAutomaticGarbageCollection: jest.fn(),
- tryGetFetchUrl: jest.fn(),
+ tryGetRemoteUrl: jest.fn(),
tryReset: jest.fn()
}
@@ -757,6 +758,7 @@ async function setup(testName: string): Promise<void> {
clean: true,
commit: '',
fetchDepth: 1,
+ isWorkflowRepository: true,
lfs: false,
submodules: false,
nestedSubmodules: false,
diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts
index c39a2a5..22f3767 100644
--- a/__test__/git-directory-helper.test.ts
+++ b/__test__/git-directory-helper.test.ts
@@ -7,7 +7,8 @@ import {IGitCommandManager} from '../lib/git-command-manager'
const testWorkspace = path.join(__dirname, '_temp', 'git-directory-helper')
let repositoryPath: string
-let repositoryUrl: string
+let httpsUrl: string
+let sshUrl: string
let clean: boolean
let git: IGitCommandManager
@@ -40,7 +41,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -62,7 +64,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -87,7 +90,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -108,7 +112,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -136,7 +141,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -155,14 +161,15 @@ describe('git-directory-helper tests', () => {
await setup(removesContentsWhenDifferentRepositoryUrl)
clean = false
await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
- const differentRepositoryUrl =
+ const differentRemoteUrl =
'https://github.com/my-different-org/my-different-repo'
// Act
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- differentRepositoryUrl,
+ differentRemoteUrl,
+ [differentRemoteUrl],
clean
)
@@ -186,7 +193,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -211,7 +219,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -235,7 +244,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
undefined,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -259,7 +269,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -289,7 +300,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -319,7 +331,8 @@ describe('git-directory-helper tests', () => {
await gitDirectoryHelper.prepareExistingDirectory(
git,
repositoryPath,
- repositoryUrl,
+ httpsUrl,
+ [httpsUrl, sshUrl],
clean
)
@@ -329,6 +342,30 @@ describe('git-directory-helper tests', () => {
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-1')
expect(git.branchDelete).toHaveBeenCalledWith(true, 'remote-branch-2')
})
+
+ const updatesRemoteUrl = 'updates remote URL'
+ it(updatesRemoteUrl, async () => {
+ // Arrange
+ await setup(updatesRemoteUrl)
+ await fs.promises.writeFile(path.join(repositoryPath, 'my-file'), '')
+
+ // Act
+ await gitDirectoryHelper.prepareExistingDirectory(
+ git,
+ repositoryPath,
+ sshUrl,
+ [sshUrl, httpsUrl],
+ clean
+ )
+
+ // Assert
+ const files = await fs.promises.readdir(repositoryPath)
+ expect(files.sort()).toEqual(['.git', 'my-file'])
+ expect(git.isDetached).toHaveBeenCalled()
+ expect(git.branchList).toHaveBeenCalled()
+ expect(core.warning).not.toHaveBeenCalled()
+ expect(git.setRemoteUrl).toHaveBeenCalledWith(sshUrl)
+ })
})
async function setup(testName: string): Promise<void> {
@@ -338,8 +375,9 @@ async function setup(testName: string): Promise<void> {
repositoryPath = path.join(testWorkspace, testName)
await fs.promises.mkdir(path.join(repositoryPath, '.git'), {recursive: true})
- // Repository URL
- repositoryUrl = 'https://github.com/my-org/my-repo'
+ // Remote URLs
+ httpsUrl = 'https://github.com/my-org/my-repo'
+ sshUrl = 'git@github.com:my-org/my-repo'
// Clean
clean = true
@@ -365,6 +403,7 @@ async function setup(testName: string): Promise<void> {
remoteAdd: jest.fn(),
removeEnvironmentVariable: jest.fn(),
setEnvironmentVariable: jest.fn(),
+ setRemoteUrl: jest.fn(),
submoduleForeach: jest.fn(),
submoduleSync: jest.fn(),
submoduleUpdate: jest.fn(),
@@ -374,10 +413,10 @@ async function setup(testName: string): Promise<void> {
}),
tryConfigUnset: jest.fn(),
tryDisableAutomaticGarbageCollection: jest.fn(),
- tryGetFetchUrl: jest.fn(async () => {
+ tryGetRemoteUrl: jest.fn(async () => {
// Sanity check - this function shouldn't be called when the .git directory doesn't exist
await fs.promises.stat(path.join(repositoryPath, '.git'))
- return repositoryUrl
+ return httpsUrl
}),
tryReset: jest.fn(async () => {
return true