diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-18 08:34:40 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-18 08:34:40 +0000 |
commit | 62e56dd0b93f51705651b09286aad703cc2c6457 (patch) | |
tree | f5f0d08347064a7e753dd0725b427dbc4d3d0489 | |
parent | 2de0f1bd7d2d91f70b670d23a42049e2bf2f7e03 (diff) | |
parent | 9d8edeac3280dba38d94a50cc6ea685ca79e9566 (diff) | |
download | summain-rs-62e56dd0b93f51705651b09286aad703cc2c6457.tar.gz |
Merge branch 'filetypes' into 'main'
Filetypes
See merge request larswirzenius/summain!15
-rw-r--r-- | subplot/summain.py | 25 | ||||
-rw-r--r-- | subplot/summain.yaml | 9 | ||||
-rw-r--r-- | summain.md | 67 |
3 files changed, 101 insertions, 0 deletions
diff --git a/subplot/summain.py b/subplot/summain.py index 4efc8c4..ca7c0f6 100644 --- a/subplot/summain.py +++ b/subplot/summain.py @@ -1,5 +1,7 @@ +import difflib import logging import os +import socket def install_summain(ctx): @@ -21,6 +23,19 @@ def create_symlink(ctx, linkname=None, target=None): os.symlink(target, linkname) +def create_socket(ctx, filename=None): + fd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + fd.bind(filename) + + +def create_fifo(ctx, filename=None): + os.mkfifo(filename) + + +def set_mode(ctx, filename=None, mode=None): + os.chmod(filename, int(mode, 8)) + + def set_atime(ctx, filename=None, timestamp=None): st = os.lstat(filename) os.utime(filename, (int(timestamp), int(st.st_mtime)), follow_symlinks=False) @@ -38,7 +53,17 @@ def output_matches_file(ctx, filename=None): actual = runcmd_get_stdout(ctx) expected = get_file(filename).decode("UTF-8") + diff = "".join( + line.rstrip("\n") + "\n" + for line in difflib.unified_diff( + expected.splitlines(), + actual.splitlines(), + fromfile="expected", + tofile="actual", + ) + ) logging.debug("output_matches:") logging.debug(f" actual:\n{actual}") logging.debug(f" expect:\n{expected}") + logging.debug(f" diff:\n{diff}") assert_eq(actual, expected) diff --git a/subplot/summain.yaml b/subplot/summain.yaml index 2fd12a5..8e5333c 100644 --- a/subplot/summain.yaml +++ b/subplot/summain.yaml @@ -4,9 +4,18 @@ - given: directory {dirname} function: create_directory +- given: socket {filename} + function: create_socket + +- given: named pipe {filename} + function: create_fifo + - given: file {filename} function: create_file +- given: file {filename} has mode {mode} + function: set_mode + - given: symlink {linkname} pointing at {target} function: create_symlink @@ -65,6 +65,15 @@ order. # Acceptance criteria +These scenarios verify that Summain handles the various kinds of file +system objects it may encounter, with two exceptions: block and +character devices. To create those, one needs to be the `root` user, +and we don't want to have to run the test suite as root. Instead, we +blithely rely on the output being correct for those anyway. Testing +manually indicates that it works, and the only difference from, say, +regular files is that the mode starts with a `b` or `c`, which is +exactly correct. + ## Directory ~~~scenario @@ -202,3 +211,61 @@ functions: - subplot/summain.py - subplot/runcmd.py ... + +## Unix domain socket + +~~~scenario +given an installed summain +given socket aaa +and file aaa has mode 0700 +and mtime for aaa is 44 +when I run summain aaa +then output matches file socket.yaml +~~~ + +```{#socket.yaml .file .numberLines} +--- +path: aaa +mode: srwx------ +mtime: 44 +mtime_nsec: 0 +nlink: 1 +size: 0 +sha256: ~ +target: ~ +``` + +## Named pipe + +~~~scenario +given an installed summain +given named pipe aaa +and file aaa has mode 0700 +and mtime for aaa is 44 +when I run summain aaa +then output matches file fifo.yaml +~~~ + +```{#fifo.yaml .file .numberLines} +--- +path: aaa +mode: prwx------ +mtime: 44 +mtime_nsec: 0 +nlink: 1 +size: 0 +sha256: ~ +target: ~ +``` + +--- +title: "Summain—deterministic file manifests" +author: Lars Wirzenius +template: python +bindings: + - subplot/summain.yaml + - subplot/runcmd.yaml +functions: + - subplot/summain.py + - subplot/runcmd.py +... |