Skip to content

Commit 8c94292

Browse files
author
skepppy
committed
Add test cases for md5sum, sha1sum, and sha256sum in target-shell
1 parent e5f4138 commit 8c94292

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/tools/test_shell.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ def test_redirect_simple_ls(tmp_path: Path, target_win: Target, monkeypatch: pyt
257257
assert "sysvol" in content
258258

259259

260+
def test_target_cli_hashsums(tmp_path: Path, target_unix: Target, capsys: pytest.CaptureFixture) -> None:
261+
target_unix.fs.map_file_fh("/test-file", BytesIO(b"Hello world!"))
262+
out_file = tmp_path / "checksum.txt"
263+
264+
cli = TargetCli(target_unix)
265+
266+
cli.onecmd(f"cat /test-file | md5sum > {out_file}")
267+
assert "86fb269d190d2c85f6e0468ceca42a20 -" in out_file.read_text()
268+
269+
cli.onecmd(f"sha1sum /test-file > {out_file}")
270+
assert "d3486ae9136e7856bc42212385ea797094475802 /test-file" in out_file.read_text()
271+
272+
cli.onecmd(f"cat /test-file | sha256sum - > {out_file}")
273+
assert "c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a -" in out_file.read_text()
274+
275+
260276
@pytest.mark.skipif(platform.system() == "Windows", reason="Unix-specific test")
261277
def test_redirect_pipe(tmp_path: Path, target_win: Target, monkeypatch: pytest.MonkeyPatch) -> None:
262278
monkeypatch.setattr(fs, "LS_COLORS", {"di": "\033[34m", "fi": "\033[0m"})

0 commit comments

Comments
 (0)