提交 50318f4d 编写于 作者: D Daniel Imms

Fix tests broken from IBackupMainService.loadSync change

上级 8e5f2f13
......@@ -24,7 +24,7 @@ export interface IBackupMainService {
*
* @return The set of active workspace backup paths being tracked for restoration.
*/
getWorkspaceBackupPathsSync(): string[];
getWorkspaceBackupPaths(): string[];
/**
* Pushes workspace backup paths to be tracked for restoration.
......@@ -75,7 +75,7 @@ export class BackupService implements IBackupMainService {
this.loadSync();
}
public getWorkspaceBackupPathsSync(): string[] {
public getWorkspaceBackupPaths(): string[] {
return this.workspacesJsonContent.folderWorkspaces;
}
......@@ -125,7 +125,7 @@ export class BackupService implements IBackupMainService {
return path.join(this.backupHome, workspaceHash);
}
private loadSync(): void {
protected loadSync(): void {
try {
this.workspacesJsonContent = JSON.parse(fs.readFileSync(this.workspacesJsonPath, 'utf8').toString()); // invalid JSON or permission issue can happen here
} catch (error) {
......
......@@ -369,7 +369,7 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService
// Restore any existing backup workspaces
if (openConfig.restoreBackups) {
const workspacesWithBackups = this.backupService.getWorkspaceBackupPathsSync();
const workspacesWithBackups = this.backupService.getWorkspaceBackupPaths();
workspacesWithBackups.forEach(workspacePath => {
if (!fs.existsSync(workspacePath)) {
......
......@@ -26,6 +26,9 @@ class TestBackupService extends BackupService {
this.backupHome = backupHome;
this.workspacesJsonPath = backupWorkspacesPath;
// Force a reload with the new paths
this.loadSync();
}
}
......@@ -58,41 +61,41 @@ suite('BackupService', () => {
});
test('getWorkspaceBackupPathsSync should return [] when workspaces.json doesn\'t exist', () => {
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
});
test('getWorkspaceBackupPathsSync should return [] when workspaces.json is not properly formed JSON', () => {
fs.writeFileSync(backupWorkspacesPath, '');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, '{]');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, 'foo');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
});
test('getWorkspaceBackupPathsSync should return [] when folderWorkspaces in workspaces.json is absent', () => {
fs.writeFileSync(backupWorkspacesPath, '{}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
});
test('getWorkspaceBackupPathsSync should return [] when folderWorkspaces in workspaces.json is not a string array', () => {
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{}}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{"foo": ["bar"]}}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{"foo": []}}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{"foo": "bar"}}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":"foo"}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":1}');
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), []);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), []);
});
test('pushWorkspaceBackupPathsSync should persist paths to workspaces.json', () => {
backupService.pushWorkspaceBackupPathsSync([fooFile, barFile]);
assert.deepEqual(backupService.getWorkspaceBackupPathsSync(), [fooFile.fsPath, barFile.fsPath]);
assert.deepEqual(backupService.getWorkspaceBackupPaths(), [fooFile.fsPath, barFile.fsPath]);
});
test('getWorkspaceUntitledFileBackupsSync should return untitled file backup resources', done => {
......@@ -111,18 +114,16 @@ suite('BackupService', () => {
});
test('removeWorkspaceBackupPath should remove workspaces from workspaces.json', done => {
const workspacesJson: IBackupWorkspacesFormat = { folderWorkspaces: [fooFile.fsPath, barFile.fsPath] };
pfs.writeFileAndFlush(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => {
backupService.removeWorkspaceBackupPathSync(fooFile);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
assert.deepEqual(json.folderWorkspaces, [barFile.fsPath]);
backupService.removeWorkspaceBackupPathSync(barFile);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
assert.deepEqual(json2.folderWorkspaces, []);
done();
});
backupService.pushWorkspaceBackupPathsSync([fooFile, barFile]);
backupService.removeWorkspaceBackupPathSync(fooFile);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
assert.deepEqual(json.folderWorkspaces, [barFile.fsPath]);
backupService.removeWorkspaceBackupPathSync(barFile);
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
assert.deepEqual(json2.folderWorkspaces, []);
done();
});
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册