summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-05-03 09:00:00 +0300
committerLars Wirzenius <liw@liw.fi>2020-05-03 09:00:00 +0300
commit82b4c62f1532faddc4c1be00d5e40068c47b9a20 (patch)
treed444c54223cfd77edeea7d1c448f0b01d1438386
parent0ee05ebeb67f8474bcb826b372e02e1d6686a076 (diff)
downloadewww-82b4c62f1532faddc4c1be00d5e40068c47b9a20.tar.gz
Change: minimal test
-rw-r--r--ewww.md5
-rw-r--r--ewww.py56
-rw-r--r--ewww.yaml6
-rw-r--r--src/main.rs11
4 files changed, 74 insertions, 4 deletions
diff --git a/ewww.md b/ewww.md
index a604232..fa0aa4f 100644
--- a/ewww.md
+++ b/ewww.md
@@ -93,6 +93,11 @@ when I request GET http://example.com/
then I get status code 200
~~~
+~~~{#minimal.yaml .file .yaml}
+{}
+~~~
+
+
## Not really a smoke test
~~~scenario-disabled
diff --git a/ewww.py b/ewww.py
index 2dbfd70..19511fe 100644
--- a/ewww.py
+++ b/ewww.py
@@ -1,2 +1,56 @@
+#############################################################################
+# Some helpers to make step functions simpler.
+
+import json
+import os
+import re
+import subprocess
+import time
+
+import yaml
+
+
+# Run a subprocess, capture its output and exit code in context.
+def _run(ctx, argv):
+ p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate("")
+ ctx['argv'] = argv
+ ctx['stdout'] = stdout.decode('utf-8')
+ ctx['stderr'] = stderr.decode('utf-8')
+ ctx['exit'] = p.returncode
+
+
+# Check that latest call of _run ended with an specific exit code.
+def _run_exit(ctx, expected):
+ assert_eq(ctx['exit'], expected)
+
+
+# Write a file with given content.
+def _write(filename, content):
+ open(filename, 'w').write(content)
+
+
+#############################################################################
+# The actual step functions.
+
+
+# Fail: use this for unimplemented steps.
def fixme(*args, **kwargs):
- pass
+ assert 0
+
+# Start server using named configuration file.
+def start_server(ctx, filename=None):
+ _write(filename, get_file(filename).decode('UTF-8'))
+ pid = os.path.abspath('ewww.pid')
+ bin = os.path.join(srcdir, 'target', 'debug', 'ewww')
+ _run(ctx, ['/usr/sbin/daemonize', '-p', pid, bin, filename])
+ ctx['pid'] = open(pid).read()
+ _run_exit(ctx, 0)
+
+def request(ctx, method=None, url=None):
+ _run(ctx, ['curl', '-sv', '-X', method, url])
+ _run_exit(ctx, 0)
+
+def status_code_is(ctx, code=None):
+ pattern = '\n< HTTP/1.1 {} '.format(code)
+ assert_eq(pattern in ctx['stderr'], True)
diff --git a/ewww.yaml b/ewww.yaml
index aefcea6..4782259 100644
--- a/ewww.yaml
+++ b/ewww.yaml
@@ -2,7 +2,7 @@
function: fixme
- given: a running server using config file {filename}
- function: fixme
+ function: start_server
- given: "{count} files in {dirname}"
function: fixme
@@ -14,7 +14,7 @@
function: fixme
- then: I get status code {code}
- function: fixme
+ function: status_code_is
- then: '(?P<header>\S+) is "(?P<value>.+)"'
regex: true
@@ -24,7 +24,7 @@
function: fixme
- when: I request {method} {url}
- function: fixme
+ function: request
- when: I request files under {url} in random order {count} times
function: fixme
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..7fa1bda
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,11 @@
+use warp::Filter;
+
+#[tokio::main]
+async fn main() {
+ let hello = warp::any()
+ .map(|| "hello, world\n".to_string());
+
+ warp::serve(hello)
+ .run(([127, 0, 0, 1], 3030))
+ .await;
+}