Ottomata has submitted this change and it was merged.
Change subject: Set up basic validity tests for JSON schemas
......................................................................
Set up basic validity tests for JSON schemas
Basic tests that get all schemas in the jsonschemas subfolder,
load them and verify validity with the json-schema schema.
Bug: T124438
Change-Id: Ie1e3c3cee1581525e0ef9ec76b6f009fc6e6dcb1
---
A .gitignore
A test/jsonschema/index.js
A test/package.json
3 files changed, 65 insertions(+), 0 deletions(-)
Approvals:
Ottomata: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4310533
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+test/node_modules/*
\ No newline at end of file
diff --git a/test/jsonschema/index.js b/test/jsonschema/index.js
new file mode 100644
index 0000000..2629e42
--- /dev/null
+++ b/test/jsonschema/index.js
@@ -0,0 +1,39 @@
+"use strict";
+
+var fs = require('fs');
+var yaml = require('js-yaml');
+var assert = require('assert');
+var Ajv = require('ajv');
+var preq = require('preq');
+
+describe('Json schema', function() {
+ var ajv = new Ajv();
+ var baseDir = __dirname + '/../../jsonschema/';
+ function browseDir(pathFromBase) {
+ fs.readdirSync(baseDir + pathFromBase).forEach(function(fileName) {
+ var filePath = pathFromBase + '/' + fileName;
+ if (fs.statSync(baseDir + filePath).isDirectory()) {
+ browseDir(filePath);
+ } else {
+ it('Validity: ' + filePath, function() {
+ var schema = yaml.safeLoad(fs.readFileSync(baseDir +
filePath, 'utf8'));
+ assert.notEqual(schema, undefined);
+ assert.notEqual(schema['$schema'], undefined);
+ return preq.get({
+ uri: schema['$schema']
+ })
+ .then(function(res) {
+ var validate = ajv.compile(res.body);
+ var valid = validate(schema);
+ if (!valid) {
+ throw new assert.AssertionError({
+ message: ajv.errorsText(valid.errors)
+ });
+ }
+ });
+ });
+ }
+ });
+ }
+ browseDir('');
+});
\ No newline at end of file
diff --git a/test/package.json b/test/package.json
new file mode 100644
index 0000000..9e51ba9
--- /dev/null
+++ b/test/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "event-schemas",
+ "version": "0.0.0",
+ "description": "Schemas for MediaWiki event streams.",
+ "main": "index.js",
+ "scripts": {
+ "test": "mocha jsonschema"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://gerrit.wikimedia.org/r/mediawiki/event-schemas"
+ },
+ "keywords": [
+ "mediawiki",
+ "event-schemas"
+ ],
+ "author": "",
+ "license": "Apache-2.0",
+ "devDependencies": {
+ "mocha": "^2.4.5",
+ "preq": "^0.4.9",
+ "ajv": "^4.0.1",
+ "js-yaml": "^3.0.6"
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/284350
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie1e3c3cee1581525e0ef9ec76b6f009fc6e6dcb1
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/event-schemas
Gerrit-Branch: master
Gerrit-Owner: Ppchelko <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Ottomata <[email protected]>
Gerrit-Reviewer: Ppchelko <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits