Skip to content

Commit

Permalink
Test Index meta-DB openapi.json
Browse files Browse the repository at this point in the history
Add comparison tests for index_openapi.json.
Update pre-commit to perform tests as well.
  • Loading branch information
CasperWA committed Dec 2, 2019
1 parent 70fafd0 commit 8c7ff42
Show file tree
Hide file tree
Showing 6 changed files with 2,109 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .ci/index_openapi_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Note: This returns exit code 0, if the two specs agree, otherwise exit code 1
docker run -t -v $(pwd):/specs:ro quen2404/openapi-diff /specs/index_openapi.json /specs/local_index_openapi.json
8 changes: 7 additions & 1 deletion .ci/json_diff.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash
diff=$(jsondiff openapi.json local_openapi.json);
index_diff=$(jsondiff index_openapi.json local_index_openapi.json);

if [ ! "$diff" = "{}" ]; then
echo -e "Generated OpenAPI spec did not match committed version. Diff:\n$diff";
echo -e "Generated OpenAPI spec for test server did not match committed version. Diff:\n$diff";
exit 1;
fi

if [ ! "$index_diff" = "{}" ]; then
echo -e "Generated OpenAPI spec for Index meta-database did not match committed version. Diff:\n$index_diff";
exit 1;
fi
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
default_language_version:
python: python3.7

repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
default_language_version:
python: python3.7
name: Blacken

- repo: local
hooks:
- id: json-diff
name: OpenAPI diff
description: Check for differences in openapi.json and index_openapi.json with local versions.
entry: ./.ci/json_diff.sh
language: system
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ install:
script:
- py.test --cov=optimade
- openapi-spec-validator openapi.json
# update schema
- openapi-spec-validator index_openapi.json
# update schemes
- python -c "from optimade.server.main import app, update_schema; update_schema(app)"
# check whether generated schema matches the committed version
- python -c "from optimade.server.main_index import app, update_schema; update_schema(app)"
# check whether generated schemes match the committed version
- .ci/openapi_diff.sh
- .ci/index_openapi_diff.sh
- codecov --token=$CODECOV_TOKEN

# Automatically deploy tags to PyPI
Expand Down

0 comments on commit 8c7ff42

Please sign in to comment.