summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-12 09:29:15 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-12 09:54:09 +0200
commitd848a9587748308421b54ad2e3126f8afc7a3b38 (patch)
treeff5d07b07f46210090cb729d4dad48e0e8e853c7
parent755c18a11f87040245964cf411ea8f518b61e0f5 (diff)
downloadobnam2-d848a9587748308421b54ad2e3126f8afc7a3b38.tar.gz
test: give better error messages for file manifests differing
This makes it easier to see what the problem is.
-rw-r--r--obnam.md3
-rw-r--r--subplot/data.py31
-rw-r--r--subplot/data.yaml3
3 files changed, 36 insertions, 1 deletions
diff --git a/obnam.md b/obnam.md
index 6521372..96fca9a 100644
--- a/obnam.md
+++ b/obnam.md
@@ -1258,12 +1258,13 @@ and a running chunk server
and a client config based on metadata.yaml
and a file live/data.dat containing some random data
and symbolink link live/link that points at data.dat
+and symbolink link live/broken that points at does-not-exist
and a manifest of the directory live in live.yaml
when I run obnam --config metadata.yaml backup
then backup generation is GEN
when I invoke obnam --config metadata.yaml restore <GEN> rest
given a manifest of the directory live restored in rest in rest.yaml
-then files live.yaml and rest.yaml match
+then manifests live.yaml and rest.yaml match
~~~
## Set chunk size
diff --git a/subplot/data.py b/subplot/data.py
index 8817909..9396215 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -113,3 +113,34 @@ def match_stdout_to_json_file(ctx, filename=None):
if stdout[key] != obj[key]:
logging.error(f"stdout value for key is not what was exptected")
assert_eq(stdout[key], obj[key])
+
+
+def manifests_match(ctx, expected=None, actual=None):
+ assert_eq = globals()["assert_eq"]
+ assert_dict_eq = globals()["assert_dict_eq"]
+
+ logging.debug(f"comparing manifests {expected} and {actual}")
+
+ expected_objs = list(yaml.safe_load_all(open(expected)))
+ actual_objs = list(yaml.safe_load_all(open(actual)))
+
+ logging.debug(f"there are {len(expected_objs)} and {len(actual_objs)} objects")
+
+ i = 0
+ while expected_objs and actual_objs:
+ e = expected_objs.pop(0)
+ a = actual_objs.pop(0)
+
+ logging.debug(f"comparing manifest objects at index {i}:")
+ logging.debug(f" expected: {e}")
+ logging.debug(f" actual : {a}")
+ assert_dict_eq(e, a)
+
+ i += 1
+
+ logging.debug(f"remaining expected objecvts: {expected_objs}")
+ logging.debug(f"remaining actual objecvts : {actual_objs}")
+ assert_eq(expected_objs, [])
+ assert_eq(actual_objs, [])
+
+ logging.debug(f"manifests {expected} and {actual} match")
diff --git a/subplot/data.yaml b/subplot/data.yaml
index 0e13abd..64348d6 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -36,3 +36,6 @@
- then: "file {filename} is not restored to {restored}"
function: file_is_not_restored
+
+- then: "manifests {expected} and {actual} match"
+ function: manifests_match