Skip to content

Commit 3df94b9

Browse files
committed
Add basic public config validation
1 parent 3bb10d8 commit 3df94b9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"remote": {
3+
"repositoryLists": [
4+
{
5+
"name": "repoList1",
6+
"repositories": ["foo/bar", "foo/baz"]
7+
}
8+
],
9+
"repositories": ["owner/repo1", "owner/repo2", "owner/repo3"],
10+
"somethingElse": "bar"
11+
}
12+
}

extensions/ql-vscode/test/pure-tests/databases/db-config-store.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { expect } from 'chai';
66
describe('db config store', async () => {
77
const tempWorkspaceStoragePath = path.join(__dirname, 'test-workspace');
88
const testDataStoragePath = path.join(__dirname, 'data');
9+
const corruptedTestDataStoragePath = path.join(__dirname, 'corruptedData');
910

1011
beforeEach(async () => {
1112
await fs.ensureDir(tempWorkspaceStoragePath);
@@ -53,4 +54,28 @@ describe('db config store', async () => {
5354
const reRetrievedConfig = configStore.getConfig();
5455
expect(reRetrievedConfig.remote.repositoryLists).to.have.length(1);
5556
});
57+
58+
it('should return error when file is not valid', async () => {
59+
const configStore = new DbConfigStore(corruptedTestDataStoragePath);
60+
await configStore.initialize();
61+
62+
const validationOutput = configStore.validateConfig();
63+
expect(validationOutput).to.have.length(2);
64+
if (validationOutput) {
65+
expect(validationOutput[0]).to.deep.equal({
66+
'instancePath': '/remote',
67+
'keyword': 'required',
68+
'message': 'must have required property \'owners\'',
69+
'params': { 'missingProperty': 'owners' },
70+
'schemaPath': '#/properties/remote/required'
71+
});
72+
expect(validationOutput[1]).to.deep.equal({
73+
'instancePath': '/remote',
74+
'keyword': 'additionalProperties',
75+
'message': 'must NOT have additional properties',
76+
'params': { 'additionalProperty': 'somethingElse' },
77+
'schemaPath': '#/properties/remote/additionalProperties'
78+
});
79+
}
80+
});
5681
});

0 commit comments

Comments
 (0)