-
Notifications
You must be signed in to change notification settings - Fork 57
/
run_contract_tests.py
54 lines (42 loc) · 1.55 KB
/
run_contract_tests.py
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
import sys
import os
import subprocess
import requests
import hashlib
def parse_and_run_feature_file():
FEATURE_FILE = sys.argv[1]
HOSTNAME = sys.argv[2] if len(sys.argv) >= 3 else "localhost"
collect_result = False
test_suite_failed = False
with open(FEATURE_FILE, 'r') as fd:
feature_file = fd.read().split("\n")
for line in feature_file:
if "@contract=" in line:
contract_tag, *_ = line.strip().split(" ", maxsplit=1)
_, contract_name = contract_tag.split("=")
res = requests.get(
f"http://{HOSTNAME}:8090/init",
params={"__contract__script__": contract_name}
)
assert res
collect_result = True
if "Scenario:" in line:
_, scenario = line.split(":")
scenario = scenario.strip()
os.system("./steps &")
print(f"RUNNING SCENARIO {scenario}")
res = subprocess.run(
["cucumber", "features", "-n", scenario, "-f", "junit", "-o", f'results/{hashlib.sha256(scenario.encode()).hexdigest()}']
)
if res.returncode:
test_suite_failed = True
if collect_result:
res = requests.get(f"http://{HOSTNAME}:8090/expect")
assert res
mock_server_response_data = res.json()
assert not mock_server_response_data["expectations"]["failed"]
collect_result = False
if test_suite_failed:
exit(1)
if __name__ == "__main__":
parse_and_run_feature_file()