summaryrefslogtreecommitdiff
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
parent22202d176259d962abdbfdefef1e6213408df06c (diff)
downloadobnam2-ad48a051596f6b9748340b7ea5b30659e2692684.tar.gz
test: add scenario test for obnam config subcommand
-rw-r--r--obnam.md28
-rw-r--r--subplot/client.yaml3
-rw-r--r--subplot/data.py29
-rw-r--r--subplot/data.yaml7
4 files changed, 65 insertions, 2 deletions
diff --git a/obnam.md b/obnam.md
index e81989b..833fbf4 100644
--- a/obnam.md
+++ b/obnam.md
@@ -820,6 +820,32 @@ and chunk-meta is {"sha256":"abc","generation":null,"ended":null}
and the body matches file data.dat
~~~
+# Acceptance criteria for the Obnam client
+
+The scenarios in chapter verify that the Obnam client works as it
+should, when it is used independently of an Obnam chunk server.
+
+## Client shows its configuration
+
+This scenario verifies that the client can show its current
+configuration, with the `obnam config` command. The configuration is
+stored as YAML, but the command outputs JSON, to make sure it doesn't
+just copy the configuration file to the output.
+
+~~~scenario
+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
+~~~
+
+~~~{#config.yaml .file .yaml .numberLines}
+root: live
+server_url: https://backup.example.com
+~~~
+
+
# Acceptance criteria for Obnam as a whole
The scenarios in this chapter apply to Obnam as a whole: the client
@@ -1093,6 +1119,7 @@ bindings:
- subplot/server.yaml
- subplot/client.yaml
- subplot/data.yaml
+ - subplot/vendored/files.yaml
- subplot/vendored/runcmd.yaml
template: python
functions:
@@ -1100,6 +1127,7 @@ functions:
- subplot/client.py
- subplot/data.py
- subplot/vendored/daemon.py
+ - subplot/vendored/files.py
- subplot/vendored/runcmd.py
classes:
- json
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