|
| 1 | +#!/bin/bash |
| 2 | +# exit when any command fails |
| 3 | +set -e |
| 4 | +PYMONGO=$(dirname "$(cd "$(dirname "$0")"; pwd)") |
| 5 | +SPECS=${MDB_SPECS:-~/Work/specifications} |
| 6 | + |
| 7 | +help (){ |
| 8 | + echo "Usage: resync_specs.sh [-bcsp] spec" |
| 9 | + echo "Required arguments:" |
| 10 | + echo " spec determines which folder the spec tests will be copied from." |
| 11 | + echo "Optional flags:" |
| 12 | + echo " -b is used to add a string to the blocklist for that next run. Can be used" |
| 13 | + echo " any number of times on a single command to block multiple patterns." |
| 14 | + echo " You can use any regex pattern (it is passed to 'grep -Ev')." |
| 15 | + echo " -c is used to set a branch or commit that will be checked out in the" |
| 16 | + echo " specifications repo before copying." |
| 17 | + echo " -s is used to set a unique path to the specs repo for that specific" |
| 18 | + echo " run." |
| 19 | + echo "Notes:" |
| 20 | + echo "You can export the environment variable MDB_SPECS to set the specs" |
| 21 | + echo " repo similar to -s, but this will persist between runs until you " |
| 22 | + echo "unset it." |
| 23 | +} |
| 24 | + |
| 25 | +# Parse flag args |
| 26 | +BRANCH='' |
| 27 | +BLOCKLIST='.*\.yml' |
| 28 | +while getopts 'b:c:s:' flag; do |
| 29 | + case "${flag}" in |
| 30 | + b) BLOCKLIST+="|$OPTARG" |
| 31 | + ;; |
| 32 | + c) BRANCH="${OPTARG}" |
| 33 | + ;; |
| 34 | + s) SPECS="${OPTARG}" |
| 35 | + ;; |
| 36 | + *) help; exit 0 |
| 37 | + ;; |
| 38 | + esac |
| 39 | +done |
| 40 | +shift $((OPTIND-1)) |
| 41 | + |
| 42 | +if [ -z $BRANCH ] |
| 43 | +then |
| 44 | + git -C $SPECS checkout $BRANCH |
| 45 | +fi |
| 46 | + |
| 47 | +# Ensure the JSON files are up to date. |
| 48 | +cd $SPECS/source |
| 49 | +make |
| 50 | +cd - |
| 51 | +# cpjson unified-test-format/tests/invalid unified-test-format/invalid |
| 52 | +# * param1: Path to spec tests dir in specifications repo |
| 53 | +# * param2: Path to where the corresponding tests live in Python. |
| 54 | +cpjson () { |
| 55 | + find "$PYMONGO"/test/$2 -type f -delete |
| 56 | + cd "$SPECS"/source/$1 |
| 57 | + find . -name '*.json' | grep -Ev "${BLOCKLIST}" | cpio -pdm \ |
| 58 | + $PYMONGO/test/$2 |
| 59 | + printf "\nIgnored files for ${PWD}" |
| 60 | + printf "\n%s\n" "$(diff <(find . -name '*.json' | sort) \ |
| 61 | + <(find . -name '*.json' | grep -Ev "${BLOCKLIST}" | sort))" | \ |
| 62 | + sed -e '/^[0-9]/d' | sed -e 's|< ./||g' |
| 63 | +} |
| 64 | + |
| 65 | +for spec in "$@" |
| 66 | +do |
| 67 | + case "$spec" in |
| 68 | + bson*corpus) |
| 69 | + cpjson bson-corpus/tests/ bson_corpus |
| 70 | + ;; |
| 71 | + max*staleness) |
| 72 | + cpjson max-staleness/tests/ max_staleness |
| 73 | + ;; |
| 74 | + connection*string) |
| 75 | + cpjson connection-string/tests/ connection_string/test |
| 76 | + ;; |
| 77 | + change*streams) |
| 78 | + cpjson change-streams/tests/ change_streams/ |
| 79 | + ;; |
| 80 | + cmap|CMAP) |
| 81 | + cpjson connection-monitoring-and-pooling/tests cmap |
| 82 | + ;; |
| 83 | + command*monitoring) |
| 84 | + cpjson command-monitoring/tests command_monitoring |
| 85 | + ;; |
| 86 | + crud|CRUD) |
| 87 | + cpjson crud/tests/ crud |
| 88 | + ;; |
| 89 | + load*balancer) |
| 90 | + cpjson load-balancers/tests load_balancer |
| 91 | + ;; |
| 92 | + initial-dns-seedlist-discovery|srv_seedlist) |
| 93 | + cpjson initial-dns-seedlist-discovery/tests/ srv_seedlist |
| 94 | + ;; |
| 95 | + old_srv_seedlist) |
| 96 | + cpjson initial-dns-seedlist-discovery/tests srv_seedlist |
| 97 | + ;; |
| 98 | + retryable*reads) |
| 99 | + cpjson retryable-reads/tests/ retryable_reads |
| 100 | + ;; |
| 101 | + retryable*writes) |
| 102 | + cpjson retryable-writes/tests/ retryable_writes |
| 103 | + ;; |
| 104 | + sdam|SDAM) |
| 105 | + cpjson server-discovery-and-monitoring/tests/errors \ |
| 106 | + discovery_and_monitoring/errors |
| 107 | + cpjson server-discovery-and-monitoring/tests/rs \ |
| 108 | + discovery_and_monitoring/rs |
| 109 | + cpjson server-discovery-and-monitoring/tests/sharded \ |
| 110 | + discovery_and_monitoring/sharded |
| 111 | + cpjson server-discovery-and-monitoring/tests/single \ |
| 112 | + discovery_and_monitoring/single |
| 113 | + cpjson server-discovery-and-monitoring/tests/integration \ |
| 114 | + discovery_and_monitoring_integration |
| 115 | + cpjson server-discovery-and-monitoring/tests/load-balanced \ |
| 116 | + discovery_and_monitoring/load-balanced |
| 117 | + ;; |
| 118 | + sdam*monitoring) |
| 119 | + cpjson server-discovery-and-monitoring/tests/monitoring sdam_monitoring |
| 120 | + ;; |
| 121 | + server*selection) |
| 122 | + cpjson server-selection/tests/ server_selection |
| 123 | + ;; |
| 124 | + sessions) |
| 125 | + cpjson sessions/tests/ sessions |
| 126 | + ;; |
| 127 | + transactions|transactions-convenient-api) |
| 128 | + cpjson transactions/tests/ transactions |
| 129 | + cpjson transactions-convenient-api/tests/ transactions-convenient-api |
| 130 | + ;; |
| 131 | + unified) |
| 132 | + cpjson unified-test-format/tests/ unified-test-format/ |
| 133 | + ;; |
| 134 | + uri|uri*options) |
| 135 | + cpjson uri-options/tests uri_options |
| 136 | + ;; |
| 137 | + versioned-api) |
| 138 | + cpjson versioned-api/tests versioned-api |
| 139 | + ;; |
| 140 | + *) |
| 141 | + echo "Do not know how to resync spec tests for '${spec}'" |
| 142 | + help |
| 143 | + ;; |
| 144 | + esac |
| 145 | +done |
0 commit comments