Skip to content

Commit

Permalink
💄 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 16, 2019
1 parent 4ace80e commit d26e39b
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/vs/platform/backup/test/electron-main/backupMainService.test.ts
Expand Up @@ -9,7 +9,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'vs/base/common/path';
import * as pfs from 'vs/base/node/pfs';
import { URI as Uri, URI } from 'vs/base/common/uri';
import { URI } from 'vs/base/common/uri';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
import { BackupMainService } from 'vs/platform/backup/electron-main/backupMainService';
Expand All @@ -24,7 +24,7 @@ import { Schemas } from 'vs/base/common/network';

suite('BackupMainService', () => {

function assertEqualUris(actual: Uri[], expected: Uri[]) {
function assertEqualUris(actual: URI[], expected: URI[]) {
assert.deepEqual(actual.map(a => a.toString()), expected.map(a => a.toString()));
}

Expand All @@ -43,12 +43,12 @@ suite('BackupMainService', () => {
this.workspacesJsonPath = backupWorkspacesPath;
}

public toBackupPath(arg: Uri | string): string {
const id = arg instanceof Uri ? super.getFolderHash(arg) : arg;
public toBackupPath(arg: URI | string): string {
const id = arg instanceof URI ? super.getFolderHash(arg) : arg;
return path.join(this.backupHome, id);
}

public getFolderHash(folderUri: Uri): string {
public getFolderHash(folderUri: URI): string {
return super.getFolderHash(folderUri);
}

Expand Down Expand Up @@ -81,7 +81,7 @@ suite('BackupMainService', () => {
};
}

async function ensureFolderExists(uri: Uri): Promise<void> {
async function ensureFolderExists(uri: URI): Promise<void> {
if (!fs.existsSync(uri.fsPath)) {
fs.mkdirSync(uri.fsPath);
}
Expand Down Expand Up @@ -110,10 +110,10 @@ suite('BackupMainService', () => {
return platform.isLinux ? p : p.toLowerCase();
}

const fooFile = Uri.file(platform.isWindows ? 'C:\\foo' : '/foo');
const barFile = Uri.file(platform.isWindows ? 'C:\\bar' : '/bar');
const fooFile = URI.file(platform.isWindows ? 'C:\\foo' : '/foo');
const barFile = URI.file(platform.isWindows ? 'C:\\bar' : '/bar');

const existingTestFolder1 = Uri.file(path.join(parentDir, 'folder1'));
const existingTestFolder1 = URI.file(path.join(parentDir, 'folder1'));

let service: TestBackupMainService;
let configService: TestConfigurationService;
Expand Down Expand Up @@ -231,7 +231,7 @@ suite('BackupMainService', () => {
const backupPathToMigrate = service.toBackupPath(fooFile);
fs.mkdirSync(backupPathToMigrate);
fs.writeFileSync(path.join(backupPathToMigrate, 'backup.txt'), 'Some Data');
service.registerFolderBackupSync(Uri.file(backupPathToMigrate));
service.registerFolderBackupSync(URI.file(backupPathToMigrate));

const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath), backupPathToMigrate);

Expand All @@ -247,12 +247,12 @@ suite('BackupMainService', () => {
const backupPathToMigrate = service.toBackupPath(fooFile);
fs.mkdirSync(backupPathToMigrate);
fs.writeFileSync(path.join(backupPathToMigrate, 'backup.txt'), 'Some Data');
service.registerFolderBackupSync(Uri.file(backupPathToMigrate));
service.registerFolderBackupSync(URI.file(backupPathToMigrate));

const backupPathToPreserve = service.toBackupPath(barFile);
fs.mkdirSync(backupPathToPreserve);
fs.writeFileSync(path.join(backupPathToPreserve, 'backup.txt'), 'Some Data');
service.registerFolderBackupSync(Uri.file(backupPathToPreserve));
service.registerFolderBackupSync(URI.file(backupPathToPreserve));

const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath), backupPathToMigrate);

Expand All @@ -270,8 +270,8 @@ suite('BackupMainService', () => {
test('migration folder path to URI makes sure to preserve existing backups', async () => {
let path1 = path.join(parentDir, 'folder1');
let path2 = path.join(parentDir, 'FOLDER2');
let uri1 = Uri.file(path1);
let uri2 = Uri.file(path2);
let uri1 = URI.file(path1);
let uri2 = URI.file(path2);

if (!fs.existsSync(path1)) {
fs.mkdirSync(path1);
Expand Down Expand Up @@ -372,8 +372,8 @@ suite('BackupMainService', () => {
});

test('getFolderBackupPaths() should return [] when files.hotExit = "onExitAndWindowClose"', async () => {
service.registerFolderBackupSync(Uri.file(fooFile.fsPath.toUpperCase()));
assertEqualUris(service.getFolderBackupPaths(), [Uri.file(fooFile.fsPath.toUpperCase())]);
service.registerFolderBackupSync(URI.file(fooFile.fsPath.toUpperCase()));
assertEqualUris(service.getFolderBackupPaths(), [URI.file(fooFile.fsPath.toUpperCase())]);
configService.setUserConfiguration('files.hotExit', HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE);
await service.initialize();
assertEqualUris(service.getFolderBackupPaths(), []);
Expand Down Expand Up @@ -591,11 +591,11 @@ suite('BackupMainService', () => {
});

test('should always store the workspace path in workspaces.json using the case given, regardless of whether the file system is case-sensitive (folder workspace)', () => {
service.registerFolderBackupSync(Uri.file(fooFile.fsPath.toUpperCase()));
assertEqualUris(service.getFolderBackupPaths(), [Uri.file(fooFile.fsPath.toUpperCase())]);
service.registerFolderBackupSync(URI.file(fooFile.fsPath.toUpperCase()));
assertEqualUris(service.getFolderBackupPaths(), [URI.file(fooFile.fsPath.toUpperCase())]);
return pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
assert.deepEqual(json.folderURIWorkspaces, [Uri.file(fooFile.fsPath.toUpperCase()).toString()]);
assert.deepEqual(json.folderURIWorkspaces, [URI.file(fooFile.fsPath.toUpperCase()).toString()]);
});
});

Expand Down Expand Up @@ -681,19 +681,19 @@ suite('BackupMainService', () => {
}

if (platform.isMacintosh) {
assert.equal(service.getFolderHash(Uri.file('/foo')), service.getFolderHash(Uri.file('/FOO')));
assert.equal(service.getFolderHash(URI.file('/foo')), service.getFolderHash(URI.file('/FOO')));
}

if (platform.isWindows) {
assert.equal(service.getFolderHash(Uri.file('c:\\foo')), service.getFolderHash(Uri.file('C:\\FOO')));
assert.equal(service.getFolderHash(URI.file('c:\\foo')), service.getFolderHash(URI.file('C:\\FOO')));
}
});
});

suite('mixed path casing', () => {
test('should handle case insensitive paths properly (registerWindowForBackupsSync) (folder workspace)', () => {
service.registerFolderBackupSync(fooFile);
service.registerFolderBackupSync(Uri.file(fooFile.fsPath.toUpperCase()));
service.registerFolderBackupSync(URI.file(fooFile.fsPath.toUpperCase()));

if (platform.isLinux) {
assert.equal(service.getFolderBackupPaths().length, 2);
Expand Down Expand Up @@ -722,7 +722,7 @@ suite('BackupMainService', () => {

// mixed case
service.registerFolderBackupSync(fooFile);
service.unregisterFolderBackupSync(Uri.file(fooFile.fsPath.toUpperCase()));
service.unregisterFolderBackupSync(URI.file(fooFile.fsPath.toUpperCase()));

if (platform.isLinux) {
assert.equal(service.getFolderBackupPaths().length, 1);
Expand Down

0 comments on commit d26e39b

Please sign in to comment.