summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-06 18:03:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-06 18:16:45 +0200
commit61aca01941d3bdf324a207f2b53dbf7128169142 (patch)
tree861aa3b61e16e2a486c61eabf1bf2e27a223679e /subplot
parentad98db921aa3d710ad7c448c6a1b818f4359d73a (diff)
downloadobnam2-61aca01941d3bdf324a207f2b53dbf7128169142.tar.gz
test: add scenario for checking chunk-size
Diffstat (limited to 'subplot')
-rw-r--r--subplot/data.py15
-rw-r--r--subplot/data.yaml4
-rw-r--r--subplot/server.py21
-rw-r--r--subplot/server.yaml3
4 files changed, 26 insertions, 17 deletions
diff --git a/subplot/data.py b/subplot/data.py
index 2a54037..f3faf2b 100644
--- a/subplot/data.py
+++ b/subplot/data.py
@@ -5,14 +5,17 @@ import random
import yaml
-def create_file_with_random_data(ctx, filename=None):
- N = 128
- data = "".join(chr(random.randint(0, 255)) for i in range(N)).encode("UTF-8")
+def create_file_with_given_data(ctx, filename=None, data=None):
+ logging.debug(f"creating file {filename} with {data!r}")
dirname = os.path.dirname(filename) or "."
- logging.debug(f"create_file_with_random_data: dirname={dirname}")
os.makedirs(dirname, exist_ok=True)
- with open(filename, "wb") as f:
- f.write(data)
+ open(filename, "wb").write(data.encode("UTF-8"))
+
+
+def create_file_with_random_data(ctx, filename=None):
+ N = 128
+ data = "".join(chr(random.randint(0, 255)) for i in range(N))
+ create_file_with_given_data(ctx, filename=filename, data=data)
def create_nonutf8_filename(ctx, dirname=None):
diff --git a/subplot/data.yaml b/subplot/data.yaml
index 6d384b8..9538daa 100644
--- a/subplot/data.yaml
+++ b/subplot/data.yaml
@@ -1,6 +1,4 @@
-- given: >
- a file (?P<filename>\\S+) containing "(?P<data>.*)"
- regex: true
+- given: a file {filename} containing "{data:text}"
function: create_file_with_given_data
- given: "a file {filename} containing some random data"
diff --git a/subplot/server.py b/subplot/server.py
index 289e181..df594f7 100644
--- a/subplot/server.py
+++ b/subplot/server.py
@@ -5,8 +5,6 @@ import random
import re
import requests
import shutil
-import socket
-import time
import urllib3
import yaml
@@ -35,7 +33,9 @@ def start_chunk_server(ctx):
"address": f"localhost:{port}",
}
- server_binary = os.path.abspath(os.path.join(srcdir, "target", "debug", "obnam-server"))
+ server_binary = os.path.abspath(
+ os.path.join(srcdir, "target", "debug", "obnam-server")
+ )
filename = "config.yaml"
yaml.safe_dump(config, stream=open(filename, "w"))
@@ -44,11 +44,7 @@ def start_chunk_server(ctx):
ctx["server_url"] = f"https://{config['address']}"
daemon_start_on_port(
- ctx,
- name="obnam-server",
- path=server_binary,
- args=filename,
- port=port,
+ ctx, name="obnam-server", path=server_binary, args=filename, port=port
)
@@ -138,6 +134,15 @@ 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):
+ 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)
+
+
# Make an HTTP request.
def _request(ctx, method, url, headers=None, data=None):
r = method(url, headers=headers, data=data, verify=False)
diff --git a/subplot/server.yaml b/subplot/server.yaml
index 68f8f0c..60f8a44 100644
--- a/subplot/server.yaml
+++ b/subplot/server.yaml
@@ -43,3 +43,6 @@
- then: "the body matches file {filename}"
function: body_matches_file
+
+- then: "server has {n:int} file chunks"
+ function: server_has_n_file_chunks