-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest
executable file
·82 lines (64 loc) · 2.14 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env python3
from argparse import ArgumentParser
from hashlib import sha1
from os import mkdir
from pathlib import Path
from signal import SIGINT, signal
from shutil import which
from subprocess import PIPE, run, Popen
from sys import argv, stderr, exit
JAR_URL = "https://piston-data.mojang.com/v1/objects/450698d1863ab5180c25d7c804ef0fe6369dd1ba/server.jar"
JAR_SHA1 = JAR_URL.split("/")[-2]
parser = ArgumentParser(description="mc-query test utility", prog=argv[0])
parser.add_argument(
"--server-only", help="runs server only, without running cargo tests"
)
args = parser.parse_args()
if args.server_only:
print("running server only, not cargo tests.")
print("ensuring server directory exists...")
if not Path("server").is_dir():
mkdir("server")
print("checking for server.jar...")
if not Path("server/server.jar").is_file():
print("server/server.jar not found... fetching server")
run([which("curl"), JAR_URL, "-o", "server/server.jar"])
else:
print("server.jar found. validating...")
sha1sum = sha1()
with open("server/server.jar", "rb") as f:
block = f.read(2**16)
while len(block) != 0:
sha1sum.update(block)
block = f.read(2**16)
if sha1sum.hexdigest() != JAR_SHA1:
print("could not verify integrity of server.jar... exiting...", file=stderr)
exit(1)
print("ensuring configuration files...")
with open("server/eula.txt", "w") as f:
f.writelines(["eula=true"])
with open("server/server.properties", "w") as f, open(
"resources/server.properties", "r"
) as source:
f.write(source.read())
print("starting server...")
process = Popen(
[which("java"), "-Xmx1G", "-jar", "server.jar", "nogui"],
cwd="./server",
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
text=True,
)
def signal_handler(_s, _f):
global process
process.kill()
signal(SIGINT, signal_handler)
for line in process.stdout:
print(f"server log: {line}", end="")
if (not args.server_only) and "RCON running on 0.0.0.0:25575" in line:
print("server RCON is ready, starting tests")
break
if not args.server_only:
run([which("cargo"), "test", "--", "--show-output"])
process.kill()