diff --git a/validator/Makefile b/validator/Makefile index e83d54e60..4cc501d14 100644 --- a/validator/Makefile +++ b/validator/Makefile @@ -2,4 +2,14 @@ .DEFAULT_GOAL := default default: + npm install validator download-all + +clean: + rm package-lock.json + rm -rf node_modules + rm -rf releases + +.PHONY: all test clean +test: + npm test diff --git a/validator/README.md b/validator/README.md index d4a1fb706..5f1f7487d 100644 --- a/validator/README.md +++ b/validator/README.md @@ -1,3 +1,31 @@ -npm link -validator \ No newline at end of file +## Introduction +This project is made to validate any json response with all releases. + +The command line interface is called "validator". Use it to download releases, + +and then run json on the releases. Check out the Makefile to get started. + +You can also use the scripts/all-releases.sh to run the validator on every release. + +## Getting started +cd validator +npm install + +## Examples +### Download and test a release +validator download 5.6.0 + +sh scripts/all-releases.sh ../services-directions-models/src/test/resources/directions_* + +### Download all releases and test a json +validator download-all + +sh scripts/all-releases.sh json/tokyo-2020-09-22.json + +### Explore the releases +- validator list-services +- validator list-releases +- validator list-releases mapbox-sdk-geojson +- validator list-releases mapbox-sdk-directions-models +- rm -rf releases \ No newline at end of file diff --git a/validator/package.json b/validator/package.json index 7eb5ad258..9def86fa6 100644 --- a/validator/package.json +++ b/validator/package.json @@ -7,14 +7,17 @@ "validator": "./src/index.js" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { - "jarfile": "^2.0.0", + "chai": "^4.2.0", + "expect.js": "^0.3.1", + "fetch-mock": "^9.10.7", "java": "^0.12.1", + "mocha": "^8.1.3", "node-fetch": "^2.6.1", "yargs": "^16.0.3" } diff --git a/validator/scripts/all-releases.sh b/validator/scripts/all-releases.sh index 6c6e38c92..1e80ae7b6 100644 --- a/validator/scripts/all-releases.sh +++ b/validator/scripts/all-releases.sh @@ -10,16 +10,21 @@ # # This script requires a file with a DirectionsResponse in the form of json. -if [[ $# -ne 1 ]]; then +echo $# +if [[ $# -lt 1 ]]; then echo "Provide a path to the json file" exit 1 fi JSON_FILE=$1 -# Validate the json with each release that has been downloaded. -# To download releases, use the validator command line interface -FILES=releases/* -for f in $FILES; do - release="${f:9}" - validator json $release $JSON_FILE +for var in "$@"; do + JSON_FILE=$var + echo Testing $JSON_FILE + # Validate the json with each release that has been downloaded. + # To download releases, use the validator command line interface + FILES=releases/* + for f in $FILES; do + release="${f:9}" + validator json $release $JSON_FILE + done done diff --git a/validator/src/download.js b/validator/src/download.js index d0504c802..2ca38a4ff 100644 --- a/validator/src/download.js +++ b/validator/src/download.js @@ -58,20 +58,12 @@ async function downloadService(release, service) { return response }; -async function downloadRelease(release, callback) { - const sdkServices = downloadService(release, "mapbox-sdk-services") - const sdkGeojson = downloadService(release, "mapbox-sdk-geojson") - const directionsModels = downloadService(release, "mapbox-sdk-directions-models") - const directionsRefreshModels = downloadService(release, "mapbox-sdk-directions-refresh-models") - let values = await Promise.all([sdkServices, sdkGeojson, directionsModels, directionsRefreshModels]); - callback(values) -} - module.exports = { - downloadRelease: function(release,) { - downloadRelease(release, (values) => { - const downloaded = values.every((download) => download.result == "success") - console.log(`${release} ${downloaded}`) - }) + downloadRelease: async function(release) { + const sdkServices = downloadService(release, "mapbox-sdk-services") + const sdkGeojson = downloadService(release, "mapbox-sdk-geojson") + const directionsModels = downloadService(release, "mapbox-sdk-directions-models") + const directionsRefreshModels = downloadService(release, "mapbox-sdk-directions-refresh-models") + return await Promise.all([sdkServices, sdkGeojson, directionsModels, directionsRefreshModels]); } } diff --git a/validator/test/download.test.js b/validator/test/download.test.js new file mode 100644 index 000000000..327c4e068 --- /dev/null +++ b/validator/test/download.test.js @@ -0,0 +1,30 @@ +const download = require('../src/download') + +const chai = require('chai'); +const assert = chai.assert +const should = chai.should(); + +describe('#downloadRelease()', function() { + context('should successfully download a release', function() { + + it('should download results for 4 services', async function () { + const services = await download.downloadRelease('5.5.0') + + services.should.be.an('array').to.have.lengthOf(4) + }); + + it('should return success for each result', async function() { + const services = await download.downloadRelease('5.5.0') + + const success = services.every(value => value.result == "success") + + assert.isTrue(success, `expecting result values to be 'retry' ${JSON.stringify(services)}`) + }); + }) +}); + + +// "https://dl.bintray.com/mapbox/mapbox/com/mapbox/mapboxsdk/mapbox-sdk-services/5.4.0/mapbox-sdk-services-5.4.0.jar", +// "https://dl.bintray.com/mapbox/mapbox/com/mapbox/mapboxsdk/mapbox-sdk-geojson/5.4.0/mapbox-sdk-geojson-5.4.0.jar", +// "https://dl.bintray.com/mapbox/mapbox/com/mapbox/mapboxsdk/mapbox-sdk-directions-models/5.4.0/mapbox-sdk-directions-models-5.4.0.jar", +// "https://dl.bintray.com/mapbox/mapbox/com/mapbox/mapboxsdk/mapbox-sdk-directions-refresh-models/5.4.0/mapbox-sdk-directions-refresh-models-5.4.0.jar" \ No newline at end of file