-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtests.py
59 lines (43 loc) · 1.45 KB
/
runtests.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
55
56
57
58
59
import dcql
import json
import os
import logging
from logger_formatter import CustomFormatter
logger = logging.getLogger(__name__)
ch = logging.StreamHandler()
ch.setFormatter(CustomFormatter())
logger.addHandler(ch)
logger.setLevel(logging.INFO)
def get_test_cases(path):
return [
os.path.join(path, f)
for f in os.listdir(path)
if os.path.isfile(
os.path.join(path, f)
) and f.startswith("testcase")
]
def load_json(path):
with open(path) as f:
return json.load(f)
def get_case_num(case):
filename = os.path.basename(case)
case_num = int(filename.lstrip("testcase-").rstrip(".json"))
return case_num
def main():
test_cases = get_test_cases(os.getcwd())
test_cases.sort(key=lambda x: get_case_num(x))
# print('\n'.join(test_cases))
credential_store = load_json("credentials.json")
for test_path in test_cases:
test = load_json(test_path)
logger.info(f"Testing {test_path}: {test['name']}")
matched_credentials = dcql.dcql_query(
test["dcql_query"],
credential_store["credentials"]
)
logger.info(f"Matched: {json.dumps(matched_credentials, indent=None)}")
expected_result = test["expected_result"]["matched_credentials"]
if not expected_result == matched_credentials:
logger.error(f"Expctd: {json.dumps(expected_result)}")
if __name__ == "__main__":
main()