Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadsen committed Sep 29, 2020
1 parent 06e7e95 commit 2c2b386
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 25 deletions.
10 changes: 10 additions & 0 deletions validator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 30 additions & 2 deletions validator/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@

npm link
validator
## 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
7 changes: 5 additions & 2 deletions validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
19 changes: 12 additions & 7 deletions validator/scripts/all-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 6 additions & 14 deletions validator/src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
30 changes: 30 additions & 0 deletions validator/test/download.test.js
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 2c2b386

Please sign in to comment.