Skip to content

Commit 008d2f5

Browse files
authored
DRIVERS-1767: test all json files with a schemaVersion against their corresponding schema (#1127)
1 parent b995503 commit 008d2f5

File tree

8 files changed

+48
-12
lines changed

8 files changed

+48
-12
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/env bash
2+
3+
# Collect error codes so we can see all the invalid json files in one run
4+
exitCode=0
5+
6+
# $1 - takes a single argument of the path to the JSON file containing a schemaVersion key at the top level.
7+
function get_schema_version() {
8+
node << EOF
9+
const { readFileSync } = require('fs')
10+
const { load } = require('js-yaml')
11+
console.log(load(readFileSync("./$1", { encoding: 'utf-8' })).schemaVersion)
12+
EOF
13+
}
14+
15+
function get_all_schemaVersion_defining_files () {
16+
# look for all yaml files with "schemaVersion: ["'][1-9]"
17+
grep --include=*.{yml,yaml} --files-with-matches --recursive --word-regexp --regexp="schemaVersion: [\"'][1-9]" source | \
18+
# Remove the known invalid test files from 'unified-test-format/tests/invalid'
19+
grep --word-regexp --invert-match 'unified-test-format/tests/invalid' | \
20+
# sort the result!
21+
sort
22+
}
23+
24+
for testFile in $(get_all_schemaVersion_defining_files)
25+
do
26+
schemaVersion=$(get_schema_version "$testFile")
27+
if ! ajvCheck=$(ajv -s "source/unified-test-format/schema-$schemaVersion.json" -d "$testFile"); then
28+
exitCode=1
29+
fi
30+
echo "$ajvCheck using schema v$schemaVersion"
31+
done
32+
33+
exit $exitCode

.github/workflows/unified-test-format-schema-check.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v2
1515
- name: Set up Python
16-
uses: actions/setup-python@v1
16+
uses: actions/setup-python@v2
1717
with:
18-
python-version: 3.7
18+
python-version: 3.x
1919
- name: Set up npm
20-
uses: actions/setup-node@v1
20+
uses: actions/setup-node@v2
2121
with:
22-
node-version: 12
22+
node-version: lts/*
2323
- name: Install dependencies
2424
run: |
2525
npm install -g ajv-cli
26+
npm install js-yaml
2627
- name: Check unified format test files against schema
27-
run: |
28-
cd source/unified-test-format/tests && make
28+
working-directory: source/unified-test-format/tests
29+
run: make
30+
- name: Check all unified tests schema version is valid
31+
run: bash .github/workflows/check_schema_version.sh

source/load-balancers/tests/cursors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "cursors are correctly pinned to connections for load-balanced clusters",
3-
"schemaVersion": "1.3",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"topologies": [

source/load-balancers/tests/cursors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: cursors are correctly pinned to connections for load-balanced clusters
22

3-
schemaVersion: '1.3'
3+
schemaVersion: '1.4'
44

55
runOnRequirements:
66
- topologies: [ load-balanced ]

source/load-balancers/tests/sdam-error-handling.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "state change errors are correctly handled",
3-
"schemaVersion": "1.3",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"topologies": [

source/load-balancers/tests/sdam-error-handling.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: state change errors are correctly handled
22

3-
schemaVersion: '1.3'
3+
schemaVersion: '1.4'
44

55
runOnRequirements:
66
- topologies: [ load-balanced ]

source/load-balancers/tests/transactions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "transactions are correctly pinned to connections for load-balanced clusters",
3-
"schemaVersion": "1.3",
3+
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
66
"topologies": [

source/load-balancers/tests/transactions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: transactions are correctly pinned to connections for load-balanced clusters
22

3-
schemaVersion: '1.3'
3+
schemaVersion: '1.4'
44

55
runOnRequirements:
66
- topologies: [ load-balanced ]

0 commit comments

Comments
 (0)