diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-18 23:33:26 -0400 |
|---|---|---|
| committer | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-18 23:33:26 -0400 |
| commit | d35c5b0d45c2389911e8fa57f5a409dc7eb4eba9 (patch) | |
| tree | 9504842130011e5303867f926b8e6016a715323e /__test__/git-directory-helper.test.ts | |
| parent | 6f1b729011b34bc28608462b6293df85180aba9c (diff) | |
use token for workflow repo
Diffstat (limited to '__test__/git-directory-helper.test.ts')
| -rw-r--r-- | __test__/git-directory-helper.test.ts | 75 |
1 files changed, 57 insertions, 18 deletions
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 |
