summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-05-03 09:12:41 +0300
committerLars Wirzenius <liw@liw.fi>2020-05-03 09:12:41 +0300
commit67a3e4bcd9b6d79f5fec75f946bd48d20f469a03 (patch)
treed86cfefeb7bdb15a592c4a52114373c16d7c7608
parent82b4c62f1532faddc4c1be00d5e40068c47b9a20 (diff)
downloadewww-67a3e4bcd9b6d79f5fec75f946bd48d20f469a03.tar.gz
Change: force scheme, host in request URLs to point at test server
-rw-r--r--ewww.md3
-rw-r--r--ewww.py18
2 files changed, 18 insertions, 3 deletions
diff --git a/ewww.md b/ewww.md
index fa0aa4f..7d2ed8d 100644
--- a/ewww.md
+++ b/ewww.md
@@ -94,7 +94,8 @@ then I get status code 200
~~~
~~~{#minimal.yaml .file .yaml}
-{}
+hosts:
+ - example.com
~~~
diff --git a/ewww.py b/ewww.py
index 19511fe..a7ff930 100644
--- a/ewww.py
+++ b/ewww.py
@@ -6,6 +6,7 @@ import os
import re
import subprocess
import time
+import urllib.parse
import yaml
@@ -30,6 +31,15 @@ def _write(filename, content):
open(filename, 'w').write(content)
+# Construct a URL that points to server running on localhost by
+# replacing the actual scheme and host with ones that work for test.
+def _url(ctx, url):
+ c = urllib.parse.urlparse(url)
+ host = c[1]
+ c = ('http', 'localhost:{}'.format(ctx['port'])) + c[2:]
+ return urllib.parse.urlunparse(c), host
+
+
#############################################################################
# The actual step functions.
@@ -40,15 +50,19 @@ def fixme(*args, **kwargs):
# Start server using named configuration file.
def start_server(ctx, filename=None):
- _write(filename, get_file(filename).decode('UTF-8'))
+ config = get_file(filename).decode('UTF-8')
+ ctx['config'] = yaml.safe_load(config)
+ _write(filename, config)
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()
+ ctx['port'] = 3030
_run_exit(ctx, 0)
def request(ctx, method=None, url=None):
- _run(ctx, ['curl', '-sv', '-X', method, url])
+ url, host = _url(ctx, url)
+ _run(ctx, ['curl', '-sv', '-X', method, '-HHost: {}'.format(host), url])
_run_exit(ctx, 0)
def status_code_is(ctx, code=None):