Skip to content

Instantly share code, notes, and snippets.

@ShaneHarvey
Last active December 16, 2021 18:42
Show Gist options
  • Save ShaneHarvey/0b51171676ba5d1a29ad4c814fd6c32c to your computer and use it in GitHub Desktop.
Save ShaneHarvey/0b51171676ba5d1a29ad4c814fd6c32c to your computer and use it in GitHub Desktop.
Resync spec tests for PyMongo
#!/bin/bash
# exit when any command fails
set -e
# Update to match your system.
PYMONGO=~/git/mongo-python-driver
SPECS=~/git/specifications
# Ensure the JSON files are up to date.
cd $SPECS/source
make
# Usage:
# cpjson unified-test-format/tests/invalid unified-test-format/invalid
# * param1: Path to spec tests dir in specifications repo
# * param2: Path to where the corresponding tests live in Python.
cpjson () {
rm -f $PYMONGO/test/$2/*.json
cp $SPECS/source/$1/*.json $PYMONGO/test/$2
}
cpjson2 () {
find $PYMONGO/test/$2 -name '*.json' -type f -delete
cd $SPECS/source/$1
find . -name '*.json' | cpio -pdm $PYMONGO/test/$2
}
for spec in "$@"
do
case "$spec" in
auth)
cpjson2 auth/tests/ auth/
;;
bson*corpus)
cpjson2 bson-corpus/tests/ bson_corpus/
;;
change*streams)
cpjson2 change-streams/tests/ change_streams/
;;
fle|csfle|client-side-encryption)
cpjson2 client-side-encryption/corpus/ client-side-encryption/corpus/
cpjson2 client-side-encryption/limits/ client-side-encryption/limits/
cpjson2 client-side-encryption/external/ client-side-encryption/external/
cpjson2 client-side-encryption/tests/ client-side-encryption/spec/
;;
cmap|CMAP)
cpjson connection-monitoring-and-pooling/tests cmap
rm $PYMONGO/test/cmap/wait-queue-fairness.json # PYTHON-1873
;;
command*monitoring)
cpjson2 command-monitoring/tests command_monitoring/
;;
crud|CRUD)
cpjson2 crud/tests/ crud/
;;
data_lake|atlas-data-lake-testing)
cpjson2 atlas-data-lake-testing/tests/ data_lake/
;;
gridfs)
cpjson2 gridfs/tests/ gridfs/
;;
initial-dns-seedlist-discovery|srv_seedlist)
cpjson2 initial-dns-seedlist-discovery/tests/ srv_seedlist/
;;
load*balancer)
cpjson load-balancers/tests load_balancer/
;;
old_srv_seedlist)
cpjson initial-dns-seedlist-discovery/tests srv_seedlist
;;
read-write-concern|read_write_concern)
cpjson2 read-write-concern/tests/ read_write_concern
;;
retryable*reads)
cpjson retryable-reads/tests/ retryable_reads
;;
retryable*writes)
cpjson2 retryable-writes/tests/ retryable_writes
;;
sdam|SDAM)
cpjson server-discovery-and-monitoring/tests/errors discovery_and_monitoring/errors
cpjson server-discovery-and-monitoring/tests/rs discovery_and_monitoring/rs
cpjson server-discovery-and-monitoring/tests/sharded discovery_and_monitoring/sharded
cpjson server-discovery-and-monitoring/tests/single discovery_and_monitoring/single
cpjson server-discovery-and-monitoring/tests/integration discovery_and_monitoring_integration
cpjson server-discovery-and-monitoring/tests/load-balanced discovery_and_monitoring/load-balanced
;;
sdam*monitoring)
cpjson server-discovery-and-monitoring/tests/monitoring sdam_monitoring
;;
server*selection)
cpjson2 server-selection/tests/ server_selection/
;;
sessions)
cpjson2 sessions/tests/ sessions/
;;
transactions|transactions-convenient-api)
cpjson2 transactions/tests/ transactions/
cpjson transactions-convenient-api/tests/ transactions-convenient-api
rm $PYMONGO/test/transactions/legacy/errors-client.json # PYTHON-1894
;;
unified)
cpjson2 unified-test-format/tests/ unified-test-format/
;;
uri|uri*options)
cpjson uri-options/tests uri_options
;;
versioned-api)
cpjson versioned-api/tests versioned-api
;;
*)
echo "Do not know how to resync spec tests for '${spec}'"
exit 1
;;
esac
done
@ShaneHarvey
Copy link
Author

Usage:

$ ./resync-specs.sh SDAM
$ ./resync-specs.sh CMAP unified 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment