From 37cc75c4b73c23ca4318333fb095cb0b8f9add19 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 3 May 2020 09:32:52 +0300 Subject: Change: add a more realistic smoke test --- ewww.md | 11 ++++++++++- ewww.py | 24 ++++++++++++++++++++++++ ewww.yaml | 13 +++++++++---- 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
\S+) is "(?P.+)"' +- then: 'header (?P
\S+) is "(?P.+)"' regex: true - function: fixme + function: http_header_is -- when: I create {filename} - function: fixme +- then: 'body is "(?P.*)"' + regex: true + function: http_body_is + +- when: I create (?P\S+) with "(?P.*)" + regex: true + function: create_file - when: I request {method} {url} function: request -- cgit v1.2.1