summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck10
-rw-r--r--yarns/100-hello.yarn16
-rw-r--r--yarns/900.yarn36
-rw-r--r--yarns/lib.py29
4 files changed, 91 insertions, 0 deletions
diff --git a/check b/check
new file mode 100755
index 0000000..f4c6167
--- /dev/null
+++ b/check
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -eu
+
+yarn yarns/*.yarn \
+ --shell python2 \
+ --shell-arg '' \
+ --shell-library yarns/lib.py \
+ --cd-datadir \
+ "$@"
diff --git a/yarns/100-hello.yarn b/yarns/100-hello.yarn
new file mode 100644
index 0000000..6eeecfd
--- /dev/null
+++ b/yarns/100-hello.yarn
@@ -0,0 +1,16 @@
+# Controller smoke test
+
+This scenario is just for making sure we can, in our tests, start and
+stop the controller, and make requests to it.
+
+ SCENARIO controller smoke test
+ GIVEN a running controller instance
+
+ WHEN client makes request GET /version
+ THEN HTTP status code is 200
+ AND result matches { "version": "1.0" }
+
+ WHEN client makes request GET /blatherskite
+ THEN HTTP status code is 404
+
+ FINALLY stop controller instance
diff --git a/yarns/900.yarn b/yarns/900.yarn
new file mode 100644
index 0000000..41711bb
--- /dev/null
+++ b/yarns/900.yarn
@@ -0,0 +1,36 @@
+# Scenario step implementations
+
+ IMPLEMENTS GIVEN a running controller instance
+ controller = os.path.join(srcdir, 'controller')
+ cliapp.runcmd(['/usr/sbin/daemonize', '-c.', controller, 'pid', 'port'])
+ vars['pid'] = cat('pid').strip()
+ vars['port'] = cat('port').strip()
+
+ IMPLEMENTS FINALLY stop controller instance
+ import signal
+ print 'killing process', repr(vars['pid'])
+ os.kill(int(vars['pid']), signal.SIGTERM)
+
+ IMPLEMENTS WHEN client makes request GET (\S+)
+ path = os.environ['MATCH_1']
+ url = 'http://localhost:{}{}'.format(vars['port'], path)
+ print 'url:', repr(url)
+ import requests
+ r = requests.get(url)
+ vars['http-status'] = r.status_code
+ vars['http-body'] = r.text
+
+ IMPLEMENTS THEN HTTP status code is (\d+)
+ wanted = int(os.environ['MATCH_1'])
+ print 'wanted:', repr(wanted)
+ print 'actual:', repr(vars['http-status'])
+ assert vars['http-status'] == wanted
+
+ IMPLEMENTS THEN result matches (.*)
+ import json
+ body = json.loads(vars['http-body'])
+ pattern = json.loads(os.environ['MATCH_1'])
+ assert type(body) == type(pattern)
+ for key in pattern.keys():
+ assert key in body
+ assert body[key] == pattern[key]
diff --git a/yarns/lib.py b/yarns/lib.py
new file mode 100644
index 0000000..b7df3a7
--- /dev/null
+++ b/yarns/lib.py
@@ -0,0 +1,29 @@
+import errno
+import os
+import time
+
+import cliapp
+
+import yarnutils
+
+datadir = os.environ['DATADIR']
+srcdir = os.environ['SRCDIR']
+
+vars = yarnutils.Variables(datadir)
+
+
+MAX_CAT_TIME = 5 # seconds
+def cat(filename):
+ start = time.time()
+ while time.time() - start < MAX_CAT_TIME:
+ try:
+ with open(filename) as f:
+ data = f.read()
+ if len(data) == 0:
+ continue
+ return data
+ except (IOError, OSError) as e:
+ if e.errno == errno.ENOENT:
+ continue
+ raise
+ raise Exception("cat took more then %s seconds" % MAX_CAT_TIME)