|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from collections import OrderedDict |
| 4 | + |
| 5 | +# add the bin dir to the path |
| 6 | +sys.path.append(os.path.join(os.path.dirname(__file__), "..")) |
| 7 | + |
| 8 | + |
| 9 | +def test_decrypt_hexed() -> None: |
| 10 | + """this checks the stream function not the rest""" |
| 11 | + import bin.decrypt as decrypt |
| 12 | + |
| 13 | + streamer = decrypt.DecryptCommand() |
| 14 | + """ equivalent to `| decrypt field=testfield hex() emit('hexed')` """ |
| 15 | + streamer.field = "testfield" |
| 16 | + streamer.fieldnames = ["hex()", "emit('hexed')"] |
| 17 | + |
| 18 | + records = [ |
| 19 | + OrderedDict([("testfield", "hello"), ("_chunked_idx", "0")]), |
| 20 | + OrderedDict([("testfield", "world"), ("_chunked_idx", "1")]), |
| 21 | + OrderedDict([("_chunked_idx", "2")]), |
| 22 | + ] |
| 23 | + |
| 24 | + output = list(streamer.stream(records)) |
| 25 | + assert output[0]["testfield"] == "hello" |
| 26 | + assert output[0]["hexed"] == "68656c6c6f" |
| 27 | + print(output[0]) |
| 28 | + |
| 29 | + assert output[1]["testfield"] == "world" |
| 30 | + assert output[1]["hexed"] == "776f726c64" |
| 31 | + print(output[1]) |
| 32 | + |
| 33 | + assert output[2] == {"_chunked_idx": "2"} |
| 34 | + print(output[2]) |
| 35 | + assert len(output) == 3 |
| 36 | + # ensure there's no errors |
| 37 | + assert not any(decrypt.FAILURE_FIELD in rec for rec in output) |
0 commit comments