summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
Diffstat (limited to 'subplot')
-rw-r--r--subplot/client.py11
-rw-r--r--subplot/client.yaml5
-rw-r--r--subplot/data.py16
-rw-r--r--subplot/data.yaml6
-rw-r--r--subplot/server.py18
-rw-r--r--subplot/server.yaml4
6 files changed, 51 insertions, 9 deletions
diff --git a/subplot/client.py b/subplot/client.py
index be0a6d6..d0beba5 100644
--- a/subplot/client.py
+++ b/subplot/client.py
@@ -16,7 +16,7 @@ def uninstall_obnam(ctx):
runcmd_run(ctx, ["chmod", "-R", "u+rwX", "."])
-def configure_client(ctx, filename=None):
+def configure_client_without_init(ctx, filename=None):
get_file = globals()["get_file"]
assert ctx.get("server_url") is not None
@@ -35,6 +35,15 @@ def configure_client(ctx, filename=None):
yaml.safe_dump(config, stream=f)
+def configure_client_with_init(ctx, filename=None):
+ runcmd_run = globals()["runcmd_run"]
+ runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
+
+ configure_client_without_init(ctx, filename=filename)
+ runcmd_run(ctx, ["obnam", "init", "--insecure-passphrase=hunter2"])
+ runcmd_exit_code_is_zero(ctx)
+
+
def run_obnam_restore(ctx, genid=None, todir=None):
runcmd_run = globals()["runcmd_run"]
diff --git a/subplot/client.yaml b/subplot/client.yaml
index 6de04c9..d660089 100644
--- a/subplot/client.yaml
+++ b/subplot/client.yaml
@@ -3,7 +3,10 @@
cleanup: uninstall_obnam
- given: "a client config based on {filename}"
- function: configure_client
+ function: configure_client_with_init
+
+- given: "a client config, without passphrase, based on {filename}"
+ function: configure_client_without_init
- when: "I invoke obnam restore <{genid}> {todir}"
function: run_obnam_restore
diff --git a/subplot/data.py b/subplot/data.py
index d134e5f..13b6d2b 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -170,3 +170,19 @@ def file_is_readable_by_owner(ctx, filename=None):
def file_does_not_contain(ctx, filename=None, pattern=None):
data = open(filename).read()
assert pattern not in data
+
+
+def files_are_different(ctx, filename1=None, filename2=None):
+ assert_ne = globals()["assert_ne"]
+
+ data1 = open(filename1, "rb").read()
+ data2 = open(filename2, "rb").read()
+ assert_ne(data1, data2)
+
+
+def files_are_identical(ctx, filename1=None, filename2=None):
+ assert_eq = globals()["assert_eq"]
+
+ data1 = open(filename1, "rb").read()
+ data2 = open(filename2, "rb").read()
+ assert_eq(data1, data2)
diff --git a/subplot/data.yaml b/subplot/data.yaml
index dcc6807..41a563f 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -48,3 +48,9 @@
- then: "file {filename} does not contain \"{pattern:text}\""
function: file_does_not_contain
+
+- then: "files {filename1} and {filename2} are different"
+ function: files_are_different
+
+- then: "files {filename1} and {filename2} are identical"
+ function: files_are_identical
diff --git a/subplot/server.py b/subplot/server.py
index df594f7..cfe91ab 100644
--- a/subplot/server.py
+++ b/subplot/server.py
@@ -134,13 +134,21 @@ def json_body_matches(ctx, wanted=None):
assert_eq(body.get(key, "not.there"), wanted[key])
-def server_has_n_file_chunks(ctx, n=None):
+def server_has_n_chunks(ctx, n=None):
assert_eq = globals()["assert_eq"]
n = int(n)
- url = f"{ctx['server_url']}/chunks?data=true"
- _request(ctx, requests.get, url)
- num_chunks = len(ctx["http.json"])
- assert_eq(n, num_chunks)
+ files = find_files(ctx["config"]["chunks"])
+ files = [json.load(open(x)) for x in files if x.endswith(".meta")]
+ logging.debug(f"server_has_n_file_chunks: n={n}")
+ logging.debug(f"server_has_n_file_chunks: len(files)={len(files)}")
+ logging.debug(f"server_has_n_file_chunks: files={files}")
+ assert_eq(n, len(files))
+
+
+def find_files(root):
+ for dirname, _, names in os.walk(root):
+ for name in names:
+ yield os.path.join(dirname, name)
# Make an HTTP request.
diff --git a/subplot/server.yaml b/subplot/server.yaml
index 60f8a44..5b8a242 100644
--- a/subplot/server.yaml
+++ b/subplot/server.yaml
@@ -44,5 +44,5 @@
- then: "the body matches file {filename}"
function: body_matches_file
-- then: "server has {n:int} file chunks"
- function: server_has_n_file_chunks
+- then: "server has {n:int} chunks"
+ function: server_has_n_chunks