25 lines
1.9 KiB
Python
25 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
from __future__ import annotations
|
|
import argparse,json,sys,tempfile,unittest
|
|
from pathlib import Path
|
|
P=argparse.ArgumentParser();P.add_argument("--root",type=Path,required=True);R=P.parse_args().root;sys.path.insert(0,str(R/"tools"))
|
|
import phase10dr_inventory_runner as runner # noqa:E402
|
|
def record(root):return {"active":True,"run_id":"TEST","target":"192.0.2.1","port":9021,"artifact_size":runner.ARTIFACT_SIZE,"artifact_sha256":runner.ARTIFACT_SHA256,"output_path":str((root/"out.json").resolve()),"receipt_path":str((root/"receipt.json").resolve()),"not_before":1.0,"not_after":3.0,"one_connection":True,"one_transfer":True,"one_execution":True,"result_receive":True,"directory_inventory":True,"possible_atime_effect_acknowledged":True,"device_file_content_read":False,"persistent_device_write":False,"installation":False,"autoload":False,"retry":False,"reconnect":False}
|
|
class Tests(unittest.TestCase):
|
|
def test_tracked_inactive(self):
|
|
value=json.loads((R/"manifests/retroarch/phase-1.0dr-inactive-inventory-runner.json").read_text())
|
|
with self.assertRaises(runner.RunnerError):runner.validate_records(value,value,2.0)
|
|
def test_exact_pair(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
value=record(Path(d));self.assertEqual(runner.validate_records(value,dict(value),2.0)["run_id"],"TEST")
|
|
def test_atime_ack_required(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
value=record(Path(d));value["possible_atime_effect_acknowledged"]=False
|
|
with self.assertRaises(runner.RunnerError):runner.validate_records(value,value,2.0)
|
|
def test_forbidden_content_read(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
value=record(Path(d));value["device_file_content_read"]=True
|
|
with self.assertRaises(runner.RunnerError):runner.validate_records(value,value,2.0)
|
|
if __name__=="__main__":unittest.main(argv=[__file__])
|