summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-05-03 09:32:52 +0300
committerLars Wirzenius <liw@liw.fi>2020-05-03 09:32:52 +0300
commit37cc75c4b73c23ca4318333fb095cb0b8f9add19 (patch)
treea4669bf1796dae6da677b51e4b8b346e9116b5a5
parent67a3e4bcd9b6d79f5fec75f946bd48d20f469a03 (diff)
downloadewww-37cc75c4b73c23ca4318333fb095cb0b8f9add19.tar.gz
Change: add a more realistic smoke test
-rw-r--r--ewww.md11
-rw-r--r--ewww.py24
-rw-r--r--ewww.yaml13
3 files changed, 43 insertions, 5 deletions
diff --git a/ewww.md b/ewww.md
index 7d2ed8d..9621570 100644
--- a/ewww.md
+++ b/ewww.md
@@ -99,7 +99,16 @@ hosts:
~~~
-## Not really a smoke test
+## Smoke test
+
+~~~scenario
+given a running server using config file smoke.yaml
+when I create webroot/foo with "hello, world"
+and I request GET https://example.com/foo
+then I get status code 200
+and header content-type is "text/plain"
+and body is "hello, world\n"
+~~~
~~~scenario-disabled
given a self-signed certificate as snakeoil.pem, using key snakeoil.key
diff --git a/ewww.py b/ewww.py
index a7ff930..22c6507 100644
--- a/ewww.py
+++ b/ewww.py
@@ -48,6 +48,12 @@ def _url(ctx, url):
def fixme(*args, **kwargs):
assert 0
+# Create a file.
+def create_file(ctx, filename=None, content=None):
+ dirname = os.path.dirname(filename)
+ os.makedirs(dirname)
+ _write(filename, content)
+
# Start server using named configuration file.
def start_server(ctx, filename=None):
config = get_file(filename).decode('UTF-8')
@@ -60,11 +66,29 @@ def start_server(ctx, filename=None):
ctx['port'] = 3030
_run_exit(ctx, 0)
+# Make a HTTP request.
def request(ctx, method=None, url=None):
url, host = _url(ctx, url)
_run(ctx, ['curl', '-sv', '-X', method, '-HHost: {}'.format(host), url])
_run_exit(ctx, 0)
+# Check status code of latest HTTP request.
def status_code_is(ctx, code=None):
pattern = '\n< HTTP/1.1 {} '.format(code)
assert_eq(pattern in ctx['stderr'], True)
+
+# Check a HTTP response header for latest request has a given value.
+def http_header_is(ctx, header=None, value=None):
+ s = ctx['stderr']
+ pattern = '\n< {}: {}'.format(header, value)
+ print('stderr:', repr(s))
+ print('pattern:', repr(pattern))
+ assert_eq(pattern in s, True)
+
+# Check a HTTP body response for latest request has a given value.
+def http_body_is(ctx, body=None):
+ s = ctx['stdout']
+ body = body.encode('UTF8').decode('unicode-escape')
+ print('stdout:', repr(s))
+ print('pattern:', repr(body))
+ assert_eq(body, s)
diff --git a/ewww.yaml b/ewww.yaml
index 4782259..56be410 100644
--- a/ewww.yaml
+++ b/ewww.yaml
@@ -16,12 +16,17 @@
- then: I get status code {code}
function: status_code_is
-- then: '(?P<header>\S+) is "(?P<value>.+)"'
+- then: 'header (?P<header>\S+) is "(?P<value>.+)"'
regex: true
- function: fixme
+ function: http_header_is
-- when: I create {filename}
- function: fixme
+- then: 'body is "(?P<body>.*)"'
+ regex: true
+ function: http_body_is
+
+- when: I create (?P<filename>\S+) with "(?P<content>.*)"
+ regex: true
+ function: create_file
- when: I request {method} {url}
function: request