summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-07-18 09:49:04 +0300
committerLars Wirzenius <liw@liw.fi>2021-07-18 10:02:33 +0300
commit46bea38612245a28af8e5daaf76544f25ec74d90 (patch)
tree2f86d98fc8b313f2e595ff65cb3d4e5c87a8b3e4
parentecd9cf74e670afb112189171486e91161bd5580d (diff)
downloadobnam2-46bea38612245a28af8e5daaf76544f25ec74d90.tar.gz
test: add scenario to verify chunkify works
Sponsored-by: author
-rw-r--r--obnam.md30
-rw-r--r--subplot/data.py40
-rw-r--r--subplot/data.yaml7
3 files changed, 66 insertions, 11 deletions
diff --git a/obnam.md b/obnam.md
index 181b2c2..31b87dd 100644
--- a/obnam.md
+++ b/obnam.md
@@ -1129,7 +1129,7 @@ given an installed obnam
and file config.yaml
and JSON file config.json converted from YAML file config.yaml
when I run obnam --config config.yaml config
-then stdout, as JSON, matches file config.json
+then stdout, as JSON, has all the values in file config.json
~~~
~~~{#config.yaml .file .yaml .numberLines}
@@ -1216,6 +1216,34 @@ then files cleartext.dat and encrypted.dat are different
then files cleartext.dat and decrypted.dat are identical
~~~
+## Split a file into chunks
+
+The `obnam chunkify` command reads one or more files and splits them
+into chunks, and writes to the standard output a JSON file describing
+each chunk. This scenario verifies that the command works at least in
+a simple case.
+
+~~~scenario
+given an installed obnam
+given a running chunk server
+given a client config based on smoke.yaml
+given a file data.dat containing "hello, world"
+given file chunks.json
+when I run obnam chunkify data.dat
+then stdout, as JSON, exactly matches file chunks.json
+~~~
+
+~~~{#chunks.json .file .json}
+[
+ {
+ "filename": "data.dat",
+ "offset": 0,
+ "len": 12,
+ "checksum": "09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b"
+ }
+]
+~~~
+
# Acceptance criteria for Obnam as a whole
The scenarios in this chapter apply to Obnam as a whole: the client
diff --git a/subplot/data.py b/subplot/data.py
index 13b6d2b..2e2802e 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -107,9 +107,10 @@ def convert_yaml_to_json(ctx, yaml_name=None, json_name=None):
json.dump(obj, f)
-def match_stdout_to_json_file(ctx, filename=None):
+def match_stdout_to_json_file_superset(ctx, filename=None):
runcmd_get_stdout = globals()["runcmd_get_stdout"]
assert_eq = globals()["assert_eq"]
+ assert_dict_eq = globals()["assert_dict_eq"]
stdout = runcmd_get_stdout(ctx)
stdout = json.loads(stdout.strip())
@@ -117,14 +118,37 @@ def match_stdout_to_json_file(ctx, filename=None):
logging.debug(f"match_stdout_to_json_file: stdout={stdout!r}")
logging.debug(f"match_stdout_to_json_file: file={obj!r}")
- for key in obj:
- if key not in stdout:
- logging.error(f"{key} not in stdout")
- assert key in stdout
+ if isinstance(obj, dict):
+ stdout = {key: value for key, value in stdout.items() if key in obj}
+ assert_dict_eq(obj, stdout)
+ elif isinstance(obj, list):
+ obj = {"key": obj}
+ stdout = {"key": stdout}
+ assert_dict_eq(obj, stdout)
+ assert_dict_eq(obj, stdout)
+ else:
+ assert_eq(obj, stdout)
+
+
+def match_stdout_to_json_file_exactly(ctx, filename=None):
+ runcmd_get_stdout = globals()["runcmd_get_stdout"]
+ assert_eq = globals()["assert_eq"]
+ assert_dict_eq = globals()["assert_dict_eq"]
+
+ stdout = runcmd_get_stdout(ctx)
+ stdout = json.loads(stdout.strip())
+ obj = json.load(open(filename))
+ logging.debug(f"match_stdout_to_json_file: stdout={stdout!r}")
+ logging.debug(f"match_stdout_to_json_file: file={obj!r}")
- if stdout[key] != obj[key]:
- logging.error(f"stdout value for key is not what was exptected")
- assert_eq(stdout[key], obj[key])
+ if isinstance(obj, list):
+ obj = {"key": obj}
+ stdout = {"key": stdout}
+ assert_dict_eq(obj, stdout)
+ elif isinstance(obj, dict):
+ assert_dict_eq(obj, stdout)
+ else:
+ assert_eq(obj, stdout)
def manifests_match(ctx, expected=None, actual=None):
diff --git a/subplot/data.yaml b/subplot/data.yaml
index 41a563f..46be6bc 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -31,8 +31,11 @@
- given: "JSON file {json_name} converted from YAML file {yaml_name}"
function: convert_yaml_to_json
-- then: "stdout, as JSON, matches file {filename}"
- function: match_stdout_to_json_file
+- then: "stdout, as JSON, exactly matches file {filename}"
+ function: match_stdout_to_json_file_exactly
+
+- then: "stdout, as JSON, has all the values in file {filename}"
+ function: match_stdout_to_json_file_superset
- then: "file {filename} is restored to {restored}"
function: file_is_restored