summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-04 11:07:09 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-04 11:07:31 +0200
commitad48a051596f6b9748340b7ea5b30659e2692684 (patch)
tree0820209b255f83bae4132d30df067161e04ec899 /subplot
parent22202d176259d962abdbfdefef1e6213408df06c (diff)
downloadobnam2-ad48a051596f6b9748340b7ea5b30659e2692684.tar.gz
test: add scenario test for obnam config subcommand
Diffstat (limited to 'subplot')
-rw-r--r--subplot/client.yaml3
-rw-r--r--subplot/data.py29
-rw-r--r--subplot/data.yaml7
3 files changed, 37 insertions, 2 deletions
diff --git a/subplot/client.yaml b/subplot/client.yaml
index b1f9b19..eef4714 100644
--- a/subplot/client.yaml
+++ b/subplot/client.yaml
@@ -4,6 +4,9 @@
- given: "a client config based on {filename}"
function: configure_client
+- when: "I invoke obnam --config {filename} config"
+ function: run_obnam_config
+
- when: "I invoke obnam --config {filename} restore <{genid}> {todir}"
function: run_obnam_restore
diff --git a/subplot/data.py b/subplot/data.py
index a24cd0c..2a54037 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -1,6 +1,8 @@
+import json
import logging
import os
import random
+import yaml
def create_file_with_random_data(ctx, filename=None):
@@ -57,3 +59,30 @@ def files_match(ctx, first=None, second=None):
logging.debug(f"files_match: f:\n{f}")
logging.debug(f"files_match: s:\n{s}")
assert_eq(f, s)
+
+
+def convert_yaml_to_json(ctx, yaml_name=None, json_name=None):
+ with open(yaml_name) as f:
+ obj = yaml.safe_load(f)
+ with open(json_name, "w") as f:
+ json.dump(obj, f)
+
+
+def match_stdout_to_json_file(ctx, filename=None):
+ runcmd_get_stdout = globals()["runcmd_get_stdout"]
+ assert_eq = globals()["assert_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}")
+
+ for key in obj:
+ if key not in stdout:
+ logging.error(f"{key} not in stdout")
+ assert key in stdout
+
+ if stdout[key] != obj[key]:
+ logging.error(f"stdout value for key is not what was exptected")
+ assert_eq(stdout[key], obj[key])
diff --git a/subplot/data.yaml b/subplot/data.yaml
index 7659319..6d384b8 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -21,5 +21,8 @@
- given: a manifest of the directory {dirname} restored in {restored} in {manifest}
function: create_manifest_of_restored
-- then: files {first} and {second} match
- function: files_match
+- 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