提交 ef4b5102 编写于 作者: D Daniel Imms

Fix tests

上级 eb9a79d4
...@@ -119,12 +119,16 @@ export class BackupMainService implements IBackupMainService { ...@@ -119,12 +119,16 @@ export class BackupMainService implements IBackupMainService {
this.validateBackupWorkspaces(backups); this.validateBackupWorkspaces(backups);
} }
private validateBackupWorkspaces(backups: IBackupWorkspacesFormat): void { protected sanitizeFolderWorkspaces(backups: IBackupWorkspacesFormat): void {
const staleBackupWorkspaces: { workspaceIdentifier: string; backupPath: string; isEmptyWorkspace: boolean }[] = [];
// Merge duplicates for folder workspaces, don't worry about cleaning them up as they will // Merge duplicates for folder workspaces, don't worry about cleaning them up as they will
// be removed when there are no backups. // be removed when there are no backups.
backups.folderWorkspaces = arrays.distinct(backups.folderWorkspaces.map(w => this.sanitizePath(w))); backups.folderWorkspaces = arrays.distinct(backups.folderWorkspaces.map(w => this.sanitizePath(w)));
}
private validateBackupWorkspaces(backups: IBackupWorkspacesFormat): void {
const staleBackupWorkspaces: { workspaceIdentifier: string; backupPath: string; isEmptyWorkspace: boolean }[] = [];
this.sanitizeFolderWorkspaces(backups);
backups.folderWorkspaces.forEach(workspacePath => { backups.folderWorkspaces.forEach(workspacePath => {
const backupPath = path.join(this.backupHome, this.getWorkspaceHash(workspacePath)); const backupPath = path.join(this.backupHome, this.getWorkspaceHash(workspacePath));
......
...@@ -36,6 +36,10 @@ class TestBackupMainService extends BackupMainService { ...@@ -36,6 +36,10 @@ class TestBackupMainService extends BackupMainService {
super.loadSync(); super.loadSync();
} }
public sanitizeFolderWorkspaces(backups: IBackupWorkspacesFormat): void {
super.sanitizeFolderWorkspaces(backups);
}
public toBackupPath(workspacePath: string): string { public toBackupPath(workspacePath: string): string {
return path.join(this.backupHome, super.getWorkspaceHash(workspacePath)); return path.join(this.backupHome, super.getWorkspaceHash(workspacePath));
} }
...@@ -72,8 +76,6 @@ suite('BackupMainService', () => { ...@@ -72,8 +76,6 @@ suite('BackupMainService', () => {
test('service validates backup workspaces on startup and cleans up', done => { test('service validates backup workspaces on startup and cleans up', done => {
// 1) backup workspace path does not exist // 1) backup workspace path does not exist
console.log('fooFile :' + fooFile.fsPath);
console.log('barFile :' + barFile.fsPath);
service.registerWindowForBackups(1, false, null, fooFile.fsPath); service.registerWindowForBackups(1, false, null, fooFile.fsPath);
service.registerWindowForBackups(2, false, null, barFile.fsPath); service.registerWindowForBackups(2, false, null, barFile.fsPath);
service.loadSync(); service.loadSync();
...@@ -190,23 +192,26 @@ suite('BackupMainService', () => { ...@@ -190,23 +192,26 @@ suite('BackupMainService', () => {
service.loadSync(); service.loadSync();
assert.deepEqual(service.emptyWorkspaceBackupPaths, []); assert.deepEqual(service.emptyWorkspaceBackupPaths, []);
}); });
});
suite('sanitizeFolderWorkspaces', () => {
test('should merge same cased paths on Windows and Mac', () => { test('should merge same cased paths on Windows and Mac', () => {
// Skip test on Linux // Skip test on Linux
if (platform.isLinux) { if (platform.isLinux) {
return; return;
} }
if (platform.isMacintosh) { const backups: IBackupWorkspacesFormat = {
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":["/foo", "/FOO"]}'); folderWorkspaces: platform.isWindows ? ['c:\\foo', 'C:\\FOO', 'c:\\FOO'] : ['/foo', '/FOO'],
service.loadSync(); emptyWorkspaces: []
assert.deepEqual(service.workspaceBackupPaths, ['/foo']); };
}
service.sanitizeFolderWorkspaces(backups);
if (platform.isWindows) { if (platform.isWindows) {
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":["c:\\foo", "C:\\FOO", "c:\\FOO]}'); assert.deepEqual(backups.folderWorkspaces, ['c:\\foo']);
service.loadSync(); } else {
assert.deepEqual(service.workspaceBackupPaths, ['c:\\foo']); assert.deepEqual(backups.folderWorkspaces, ['/foo']);
} }
}); });
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册