| 1 |
|
| 2 |
|
| 3 |
import subprocess |
| 4 |
import os |
| 5 |
import sys |
| 6 |
import time |
| 7 |
import argparse |
| 8 |
import platform |
| 9 |
import urllib.request |
| 10 |
from glob import glob |
| 11 |
from docker import start_database |
| 12 |
|
| 13 |
parser = argparse.ArgumentParser() |
| 14 |
parser.add_argument("-t", "--target") |
| 15 |
parser.add_argument("-e", "--target-exact") |
| 16 |
parser.add_argument("-l", "--list-targets", action="store_true") |
| 17 |
parser.add_argument("--test") |
| 18 |
|
| 19 |
argv, unknown = parser.parse_known_args() |
| 20 |
|
| 21 |
|
| 22 |
dir_workspace = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 23 |
|
| 24 |
|
| 25 |
dir_tests = os.path.join(dir_workspace, "tests") |
| 26 |
|
| 27 |
|
| 28 |
def maybe_fetch_sqlite_extension(): |
| 29 |
""" |
| 30 |
For supported platforms, if we're testing SQLite and the file isn't |
| 31 |
already present, grab a simple extension for testing. |
| 32 |
|
| 33 |
Returns the extension name if it was downloaded successfully or `None` if not. |
| 34 |
""" |
| 35 |
BASE_URL = "https://github.com/nalgeon/sqlean/releases/download/0.15.2/" |
| 36 |
if platform.system() == "Darwin": |
| 37 |
if platform.machine() == "arm64": |
| 38 |
download_url = BASE_URL + "/ipaddr.arm64.dylib" |
| 39 |
filename = "ipaddr.dylib" |
| 40 |
else: |
| 41 |
download_url = BASE_URL + "/ipaddr.dylib" |
| 42 |
filename = "ipaddr.dylib" |
| 43 |
elif platform.system() == "Linux": |
| 44 |
download_url = BASE_URL + "/ipaddr.so" |
| 45 |
filename = "ipaddr.so" |
| 46 |
else: |
| 47 |
|
| 48 |
return None |
| 49 |
|
| 50 |
if not os.path.exists(filename): |
| 51 |
content = urllib.request.urlopen(download_url).read() |
| 52 |
with open(filename, "wb") as fd: |
| 53 |
fd.write(content) |
| 54 |
|
| 55 |
return filename.split(".")[0] |
| 56 |
|
| 57 |
|
| 58 |
def run(command, comment=None, env=None, service=None, tag=None, args=None, database_url_args=None): |
| 59 |
if argv.list_targets: |
| 60 |
if tag: |
| 61 |
print(f"{tag}") |
| 62 |
|
| 63 |
return |
| 64 |
|
| 65 |
if argv.target and not tag.startswith(argv.target): |
| 66 |
return |
| 67 |
|
| 68 |
if argv.target_exact and tag != argv.target_exact: |
| 69 |
return |
| 70 |
|
| 71 |
if comment is not None: |
| 72 |
print(f"\x1b[2m # {comment}\x1b[0m") |
| 73 |
|
| 74 |
environ = env or {} |
| 75 |
|
| 76 |
if service == "sqlite": |
| 77 |
if maybe_fetch_sqlite_extension() is not None: |
| 78 |
if environ.get("RUSTFLAGS"): |
| 79 |
environ["RUSTFLAGS"] += " --cfg sqlite_ipaddr" |
| 80 |
else: |
| 81 |
environ["RUSTFLAGS"] = "--cfg sqlite_ipaddr" |
| 82 |
if platform.system() == "Linux": |
| 83 |
if os.environ.get("LD_LIBRARY_PATH"): |
| 84 |
environ["LD_LIBRARY_PATH"]= os.environ.get("LD_LIBRARY_PATH") + ":"+ os.getcwd() |
| 85 |
else: |
| 86 |
environ["LD_LIBRARY_PATH"]=os.getcwd() |
| 87 |
|
| 88 |
|
| 89 |
if service is not None: |
| 90 |
database_url = start_database(service, database="sqlite/sqlite.db" if service == "sqlite" else "sqlx", cwd=dir_tests) |
| 91 |
|
| 92 |
if database_url_args: |
| 93 |
database_url += "?" + database_url_args |
| 94 |
|
| 95 |
environ["DATABASE_URL"] = database_url |
| 96 |
|
| 97 |
|
| 98 |
print(f"\x1b[94m @ {database_url}\x1b[0m") |
| 99 |
|
| 100 |
command_args = [] |
| 101 |
|
| 102 |
if argv.test: |
| 103 |
command_args.extend(["--test", argv.test]) |
| 104 |
|
| 105 |
if unknown: |
| 106 |
command_args.extend(["--", *unknown]) |
| 107 |
|
| 108 |
if args is not None: |
| 109 |
command_args.extend(args) |
| 110 |
|
| 111 |
print(f"\x1b[93m $ {command} {' '.join(command_args)}\x1b[0m") |
| 112 |
|
| 113 |
cwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 114 |
res = subprocess.run( |
| 115 |
[ |
| 116 |
*command.split(" "), |
| 117 |
*command_args |
| 118 |
], |
| 119 |
env=dict(list(os.environ.items()) + list(environ.items())), |
| 120 |
cwd=cwd, |
| 121 |
) |
| 122 |
|
| 123 |
if res.returncode != 0: |
| 124 |
sys.exit(res.returncode) |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
for path in glob(os.path.join(os.path.dirname(__file__), "target/**/*.gc*"), recursive=True): |
| 130 |
os.remove(path) |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
for runtime in ["async-std", "tokio"]: |
| 137 |
for tls in ["native-tls", "rustls", "none"]: |
| 138 |
run( |
| 139 |
f"cargo c --no-default-features --features all-databases,_unstable-all-types,macros,runtime-{runtime},tls-{tls}", |
| 140 |
comment="check with async-std", |
| 141 |
tag=f"check_{runtime}_{tls}" |
| 142 |
) |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
for runtime in ["async-std", "tokio"]: |
| 149 |
for tls in ["native-tls", "rustls", "none"]: |
| 150 |
run( |
| 151 |
f"cargo test --no-default-features --manifest-path sqlx-core/Cargo.toml --features json,offline,migrate,_rt-{runtime},_tls-{tls}", |
| 152 |
comment="unit test core", |
| 153 |
tag=f"unit_{runtime}_{tls}" |
| 154 |
) |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
for runtime in ["async-std", "tokio"]: |
| 161 |
for tls in ["native-tls", "rustls", "none"]: |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
run( |
| 168 |
f"cargo test --no-default-features --features any,sqlite,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 169 |
comment=f"test sqlite", |
| 170 |
service="sqlite", |
| 171 |
tag=f"sqlite" if runtime == "async-std" else f"sqlite_{runtime}", |
| 172 |
) |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
for version in ["17", "16", "15", "14", "13"]: |
| 179 |
run( |
| 180 |
f"cargo test --no-default-features --features any,postgres,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 181 |
comment=f"test postgres {version}", |
| 182 |
service=f"postgres_{version}", |
| 183 |
tag=f"postgres_{version}" if runtime == "async-std" else f"postgres_{version}_{runtime}", |
| 184 |
) |
| 185 |
|
| 186 |
if tls != "none": |
| 187 |
|
| 188 |
run( |
| 189 |
f"cargo test --no-default-features --features any,postgres,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 190 |
comment=f"test postgres {version} ssl", |
| 191 |
database_url_args="sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt", |
| 192 |
service=f"postgres_{version}", |
| 193 |
tag=f"postgres_{version}_ssl" if runtime == "async-std" else f"postgres_{version}_ssl_{runtime}", |
| 194 |
) |
| 195 |
|
| 196 |
|
| 197 |
run( |
| 198 |
f"cargo test --no-default-features --features any,postgres,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 199 |
comment=f"test postgres {version}_client_ssl no-password", |
| 200 |
database_url_args="sslmode=verify-ca&sslrootcert=.%2Ftests%2Fcerts%2Fca.crt&sslkey=.%2Ftests%2Fkeys%2Fclient.key&sslcert=.%2Ftests%2Fcerts%2Fclient.crt", |
| 201 |
service=f"postgres_{version}_client_ssl", |
| 202 |
tag=f"postgres_{version}_client_ssl_no_password" if runtime == "async-std" else f"postgres_{version}_client_ssl_no_password_{runtime}", |
| 203 |
) |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
for version in ["8", "5_7"]: |
| 210 |
|
| 211 |
|
| 212 |
if not(version == "5_7" and tls == "rustls"): |
| 213 |
run( |
| 214 |
f"cargo test --no-default-features --features any,mysql,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 215 |
comment=f"test mysql {version}", |
| 216 |
service=f"mysql_{version}", |
| 217 |
tag=f"mysql_{version}" if runtime == "async-std" else f"mysql_{version}_{runtime}", |
| 218 |
) |
| 219 |
|
| 220 |
|
| 221 |
if tls != "none" and not(version == "5_7" and tls == "rustls"): |
| 222 |
run( |
| 223 |
f"cargo test --no-default-features --features any,mysql,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 224 |
comment=f"test mysql {version}_client_ssl no-password", |
| 225 |
database_url_args="sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt", |
| 226 |
service=f"mysql_{version}_client_ssl", |
| 227 |
tag=f"mysql_{version}_client_ssl_no_password" if runtime == "async-std" else f"mysql_{version}_client_ssl_no_password_{runtime}", |
| 228 |
) |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
for version in ["verylatest", "10_11", "10_6", "10_5", "10_4"]: |
| 235 |
run( |
| 236 |
f"cargo test --no-default-features --features any,mysql,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 237 |
comment=f"test mariadb {version}", |
| 238 |
service=f"mariadb_{version}", |
| 239 |
tag=f"mariadb_{version}" if runtime == "async-std" else f"mariadb_{version}_{runtime}", |
| 240 |
) |
| 241 |
|
| 242 |
|
| 243 |
if tls != "none": |
| 244 |
run( |
| 245 |
f"cargo test --no-default-features --features any,mysql,macros,_unstable-all-types,runtime-{runtime},tls-{tls}", |
| 246 |
comment=f"test mariadb {version}_client_ssl no-password", |
| 247 |
database_url_args="sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt", |
| 248 |
service=f"mariadb_{version}_client_ssl", |
| 249 |
tag=f"mariadb_{version}_client_ssl_no_password" if runtime == "async-std" else f"mariadb_{version}_client_ssl_no_password_{runtime}", |
| 250 |
) |
| 251 |
|
| 252 |
|
| 253 |
|