diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-05-03 09:32:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-05-03 09:32:52 +0300 |
commit | 37cc75c4b73c23ca4318333fb095cb0b8f9add19 (patch) | |
tree | a4669bf1796dae6da677b51e4b8b346e9116b5a5 | |
parent | 67a3e4bcd9b6d79f5fec75f946bd48d20f469a03 (diff) | |
download | ewww-37cc75c4b73c23ca4318333fb095cb0b8f9add19.tar.gz |
Change: add a more realistic smoke test
-rw-r--r-- | ewww.md | 11 | ||||
-rw-r--r-- | ewww.py | 24 | ||||
-rw-r--r-- | ewww.yaml | 13 |
3 files changed, 43 insertions, 5 deletions
@@ -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 @@ -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) @@ -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 |