1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# Scenario step implementations
# Manage controller instance
IMPLEMENTS GIVEN a running controller instance
controller = os.path.join(srcdir, 'controller')
cliapp.runcmd(
['/usr/sbin/daemonize', '-c.',
controller, '--debug', '--pid-file=pid',
'--port-file=port', '--projects=ick.ick', '--log=log'])
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)
## Git repositories
IMPLEMENTS GIVEN a git repo (\S+) with file (\S+) containing "(.+)"
repo = yarnutils.get_next_match()
filename = yarnutils.get_next_match()
content = yarnutils.get_next_match()
pathname = os.path.join(repo, filename)
os.mkdir(repo)
git(repo, 'init', '.')
git(repo, 'config', 'user.email', 'user@example.com')
git(repo, 'config', 'user.name', 'J. Random User')
write(pathname, unescape(content))
git(repo, 'add', '.')
git(repo, 'commit', '-minitial')
## Controller configuration
IMPLEMENTS GIVEN a project (\S+), using (\S+), publishing to (\S+)
project = yarnutils.get_next_match()
repo = yarnutils.get_next_match()
if os.path.exists('ick.ick'):
config = yaml.safe_load(open('ick.ick'))
else:
config = {
'projects': {}
}
config['projects'][project] = {
'git': repo,
'shell_steps': [
'ikiwiki --build',
'rsync',
],
}
write('ick.ick', yaml.safe_dump(config))
## API use
IMPLEMENTS WHEN (user|worker manager|git server) calls (\S+) (\S+)
who = yarnutils.get_next_match()
method = yarnutils.get_next_match()
path = yarnutils.get_next_match()
url = controller_url(vars['port'], path)
vars['status'], vars['body'] = request(method, url)
IMPLEMENTS WHEN worker manager calls (\S+) (\S+), with JSON body '(.+)'
method = yarnutils.get_next_match()
path = yarnutils.get_next_match()
body_text = yarnutils.get_next_match()
url = controller_url(vars['port'], path)
body = parse_json(body_text)
vars['status'], vars['body'] = request(method, url, body=body_text)
IMPLEMENTS THEN response has status (\d+), and an empty body
status = yarnutils.get_next_match()
yarnutils.assertEqual(int(status), int(vars['status']))
yarnutils.assertEqual(vars['body'], '')
IMPLEMENTS THEN response has status (\d+), and text body "(.+)"
status = yarnutils.get_next_match()
bodypat = yarnutils.get_next_match()
yarnutils.assertEqual(int(status), int(vars['status']))
yarnutils.assertEqual(vars['body'], unescape(bodypat) )
IMPLEMENTS THEN response has status (\d+), and JSON body "(.+)"
status = yarnutils.get_next_match()
bodytext = yarnutils.get_next_match()
print 'varsbody:', repr(vars['body'])
print 'bodytext:', repr(bodytext)
bodyjson = parse_json(bodytext)
print 'bodyjson:', repr(bodyjson)
yarnutils.assertEqual(int(status), int(vars['status']))
yarnutils.assertEqual(parse_json(vars['body']), parse_json(bodytext) )
IMPLEMENTS THEN response has status (\d+)
status = yarnutils.get_next_match()
yarnutils.assertEqual(int(status), int(vars['status']))
|