This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
forked from eclipse-che/che-theia
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from PizzaFactory/prp-update-to-the-upstream
[Scheduled] Update to the upstream
- Loading branch information
Showing
2 changed files
with
173 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import 'reflect-metadata'; | ||
|
||
import * as fs from 'fs-extra'; | ||
import * as ini from 'ini'; | ||
import * as path from 'path'; | ||
|
||
import { | ||
|
@@ -20,6 +21,7 @@ import { | |
UserConfiguration, | ||
} from '../src/node/git-configuration-controller'; | ||
|
||
import { CheGitClient } from '../lib/common/git-protocol'; | ||
import { CheTheiaUserPreferencesSynchronizer } from '@eclipse-che/theia-user-preferences-synchronizer/lib/node/che-theia-preferences-synchronizer'; | ||
import { Container } from 'inversify'; | ||
|
||
|
@@ -28,28 +30,37 @@ describe('Test GitConfigurationController', () => { | |
let gitConfigurationController: GitConfigurationController; | ||
const cheTheiaUserPreferencesSynchronizerGetpreferencesMock = jest.fn(); | ||
const cheTheiaUserPreferencesSynchronizerSetpreferencesMock = jest.fn(); | ||
const cheTheiaUserPreferencesSynchronizerOnTheiaUserPreferencesCreatedMock = jest.fn(); | ||
const cheTheiaUserPreferencesSynchronizer = { | ||
getPreferences: cheTheiaUserPreferencesSynchronizerGetpreferencesMock, | ||
setPreferences: cheTheiaUserPreferencesSynchronizerSetpreferencesMock, | ||
onTheiaUserPreferencesCreated: cheTheiaUserPreferencesSynchronizerOnTheiaUserPreferencesCreatedMock, | ||
} as any; | ||
cheTheiaUserPreferencesSynchronizerGetpreferencesMock.mockResolvedValue({}); | ||
const cheGitClient: CheGitClient = { | ||
firePreferencesChanged: jest.fn(), | ||
}; | ||
|
||
beforeEach(async () => { | ||
jest.restoreAllMocks(); | ||
jest.resetAllMocks(); | ||
// jest.resetAllMocks(); | ||
jest.spyOn(fs, 'readdirSync').mockReturnValue([]); | ||
jest.spyOn(fs, 'pathExistsSync').mockReturnValue(false); | ||
container = new Container(); | ||
container.bind(CheTheiaUserPreferencesSynchronizer).toConstantValue(cheTheiaUserPreferencesSynchronizer); | ||
container.bind(GitConfigurationController).toSelf().inSingletonScope(); | ||
gitConfigurationController = container.get(GitConfigurationController); | ||
gitConfigurationController.setClient(cheGitClient); | ||
}); | ||
|
||
test('check Update', async () => { | ||
const gitLfsConfigPath = path.resolve(__dirname, '_data', 'git-lfs.config'); | ||
const gitLfsConfig = await fs.readFile(gitLfsConfigPath, 'utf-8'); | ||
const readFileSpy = jest.spyOn(fs, 'readFile') as jest.Mock; | ||
const readFileSpy = jest.spyOn(fs, 'readFileSync') as jest.Mock; | ||
readFileSpy.mockReturnValue(gitLfsConfig); | ||
const pathExistsSpy = jest.spyOn(fs, 'pathExists') as jest.Mock; | ||
const pathExistsSpy = jest.spyOn(fs, 'pathExistsSync') as jest.Mock; | ||
pathExistsSpy.mockReturnValue(true); | ||
const writeFileSpy = jest.spyOn(fs, 'writeFile') as jest.Mock; | ||
const writeFileSpy = jest.spyOn(fs, 'writeFileSync') as jest.Mock; | ||
// do not write anything | ||
writeFileSpy.mockResolvedValue({}); | ||
|
||
|
@@ -58,7 +69,7 @@ describe('Test GitConfigurationController', () => { | |
email: '[email protected]', | ||
}; | ||
|
||
await gitConfigurationController.updateGlobalGitConfig(userConfig); | ||
await gitConfigurationController.updateUserGitonfigFromUserConfig(userConfig); | ||
expect(gitConfigurationController).toBeDefined(); | ||
|
||
// it should contain lfs data | ||
|
@@ -74,16 +85,16 @@ describe('Test GitConfigurationController', () => { | |
|
||
const userConfigPath = path.resolve(__dirname, '_data', 'git-user.config'); | ||
const userConfig = await fs.readFile(userConfigPath, 'utf-8'); | ||
const readFileSpy = jest.spyOn(fs, 'readFile') as jest.Mock; | ||
const pathExistsSpy = jest.spyOn(fs, 'pathExists') as jest.Mock; | ||
const readFileSpy = jest.spyOn(fs, 'readFileSync') as jest.Mock; | ||
const pathExistsSpy = jest.spyOn(fs, 'pathExistsSync') as jest.Mock; | ||
|
||
// GIT_USER_CONFIG_PATH | ||
readFileSpy.mockResolvedValueOnce(gitLfsConfig); | ||
pathExistsSpy.mockResolvedValueOnce(true); | ||
readFileSpy.mockReturnValueOnce(gitLfsConfig); | ||
pathExistsSpy.mockReturnValueOnce(true); | ||
|
||
// GIT_GLOBAL_CONFIG_PATH | ||
readFileSpy.mockResolvedValueOnce(userConfig); | ||
pathExistsSpy.mockResolvedValueOnce(true); | ||
readFileSpy.mockReturnValueOnce(userConfig); | ||
pathExistsSpy.mockReturnValueOnce(true); | ||
|
||
const userConfiguration = await gitConfigurationController.getUserConfigurationFromGitConfig(); | ||
|
||
|
@@ -92,4 +103,33 @@ describe('Test GitConfigurationController', () => { | |
email: '[email protected]', | ||
}); | ||
}); | ||
|
||
test('check updateLocalGitconfig', async () => { | ||
const gitConfigurationControllerProto = Object.getPrototypeOf(gitConfigurationController); | ||
const userGitconfigContent = fs.readFileSync(path.resolve(__dirname, '_data', 'git-user.config')).toString(); | ||
const lfsGitconfigContent = fs.readFileSync(path.resolve(__dirname, '_data', 'git-lfs.config')).toString(); | ||
gitConfigurationControllerProto.userGitconfigDirty = ini.parse(userGitconfigContent); | ||
const dir = { | ||
isFile: () => false, | ||
isDirectory: () => true, | ||
isBlockDevice: () => true, | ||
isCharacterDevice: () => true, | ||
isSymbolicLink: () => true, | ||
isFIFO: () => true, | ||
isSocket: () => true, | ||
name: 'dirName', | ||
}; | ||
jest.spyOn(fs, 'readdirSync').mockReturnValueOnce([dir]); | ||
const gitUserConfigPath = path.resolve(__dirname, '_data', 'git-user.config'); | ||
jest.spyOn(path, 'resolve').mockReturnValueOnce(gitUserConfigPath); | ||
const writeFileSpy = jest.spyOn(fs, 'writeFileSync') as jest.Mock; | ||
// do not write anything | ||
writeFileSpy.mockReturnValue({}); | ||
|
||
gitConfigurationControllerProto.updateLocalGitconfig(ini.parse(userGitconfigContent.concat(lfsGitconfigContent))); | ||
|
||
expect(writeFileSpy).toBeCalledWith(gitUserConfigPath, expect.stringContaining('lfs')); | ||
expect(writeFileSpy).toBeCalledWith(gitUserConfigPath, expect.stringContaining('dummy')); | ||
expect(writeFileSpy).toBeCalledWith(gitUserConfigPath, expect.stringContaining('[email protected]')); | ||
}); | ||
}); |