mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode 5b9869eb02fa4c96205a74d05cad9164dfd06d60 (#5607)
This commit is contained in:
@@ -26,21 +26,23 @@ export class FileStorage {
|
||||
return this._database;
|
||||
}
|
||||
|
||||
init(): Promise<void> {
|
||||
return readFile(this.dbPath).then(contents => {
|
||||
async init(): Promise<void> {
|
||||
try {
|
||||
const contents = await readFile(this.dbPath);
|
||||
|
||||
try {
|
||||
this.lastFlushedSerializedDatabase = contents.toString();
|
||||
this._database = JSON.parse(this.lastFlushedSerializedDatabase);
|
||||
} catch (error) {
|
||||
this._database = {};
|
||||
}
|
||||
}, error => {
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
this.onError(error);
|
||||
}
|
||||
|
||||
this._database = {};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private loadSync(): object {
|
||||
|
||||
@@ -14,38 +14,37 @@ suite('StateService', () => {
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'stateservice');
|
||||
const storageFile = path.join(parentDir, 'storage.json');
|
||||
|
||||
teardown(done => {
|
||||
rimraf(parentDir, RimRafMode.MOVE).then(done, done);
|
||||
teardown(async () => {
|
||||
await rimraf(parentDir, RimRafMode.MOVE);
|
||||
});
|
||||
|
||||
test('Basics', () => {
|
||||
return mkdirp(parentDir).then(() => {
|
||||
writeFileSync(storageFile, '');
|
||||
test('Basics', async () => {
|
||||
await mkdirp(parentDir);
|
||||
writeFileSync(storageFile, '');
|
||||
|
||||
let service = new FileStorage(storageFile, () => null);
|
||||
let service = new FileStorage(storageFile, () => null);
|
||||
|
||||
service.setItem('some.key', 'some.value');
|
||||
assert.equal(service.getItem('some.key'), 'some.value');
|
||||
service.setItem('some.key', 'some.value');
|
||||
assert.equal(service.getItem('some.key'), 'some.value');
|
||||
|
||||
service.removeItem('some.key');
|
||||
assert.equal(service.getItem('some.key', 'some.default'), 'some.default');
|
||||
service.removeItem('some.key');
|
||||
assert.equal(service.getItem('some.key', 'some.default'), 'some.default');
|
||||
|
||||
assert.ok(!service.getItem('some.unknonw.key'));
|
||||
assert.ok(!service.getItem('some.unknonw.key'));
|
||||
|
||||
service.setItem('some.other.key', 'some.other.value');
|
||||
service.setItem('some.other.key', 'some.other.value');
|
||||
|
||||
service = new FileStorage(storageFile, () => null);
|
||||
service = new FileStorage(storageFile, () => null);
|
||||
|
||||
assert.equal(service.getItem('some.other.key'), 'some.other.value');
|
||||
assert.equal(service.getItem('some.other.key'), 'some.other.value');
|
||||
|
||||
service.setItem('some.other.key', 'some.other.value');
|
||||
assert.equal(service.getItem('some.other.key'), 'some.other.value');
|
||||
service.setItem('some.other.key', 'some.other.value');
|
||||
assert.equal(service.getItem('some.other.key'), 'some.other.value');
|
||||
|
||||
service.setItem('some.undefined.key', undefined);
|
||||
assert.equal(service.getItem('some.undefined.key', 'some.default'), 'some.default');
|
||||
service.setItem('some.undefined.key', undefined);
|
||||
assert.equal(service.getItem('some.undefined.key', 'some.default'), 'some.default');
|
||||
|
||||
service.setItem('some.null.key', null);
|
||||
assert.equal(service.getItem('some.null.key', 'some.default'), 'some.default');
|
||||
});
|
||||
service.setItem('some.null.key', null);
|
||||
assert.equal(service.getItem('some.null.key', 'some.default'), 'some.default');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user