summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test-getsrc.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/test-getsrc.py b/test-getsrc.py
new file mode 100644
index 0000000..c0e7176
--- /dev/null
+++ b/test-getsrc.py
@@ -0,0 +1,99 @@
+import base64, json, os, subprocess, sys
+
+import cliapp
+
+import yaml
+
+
+def RUN(*args, cwd=None):
+# print('Executing:', args, 'cwd:', cwd)
+ with open('/dev/null', 'w') as f:
+ kwargs = {'stdout': f, 'stderr': f}
+# kwargs = {}
+ return subprocess.check_call(args, cwd=cwd, **kwargs)
+
+
+def find_pipeline(obj, name):
+ for p in obj['pipelines']:
+ if p['pipeline'] == name:
+ return p
+ assert 0
+
+
+obj = yaml.safe_load(sys.stdin)
+get_sources = find_pipeline(obj, 'get_sources')
+actions = get_sources['actions']
+actions = [a for a in actions if 'python' in a]
+assert len(actions) == 1
+code = actions[0]['python']
+
+print('Setting up workspace, simulating git_mirror action')
+RUN('rm', '-rf', 'workspace')
+RUN('mkdir', 'workspace')
+RUN('mkdir', 'workspace/.mirrors')
+RUN('git', 'clone', '--mirror', 'git://git.liw.fi/heippa', 'workspace/.mirrors/heippa')
+
+
+heippa = {
+ 'name': 'heippa',
+}
+
+params = {
+ 'sources': [
+ {
+ 'name': 'heippa',
+ 'location': 'master',
+ 'ref': 'master',
+ 'HEAD': 'ref: refs/heads/master',
+ },
+ {
+ 'name': 'heippa',
+ 'location': 'foo',
+ 'ref': 'liw/foo',
+ 'HEAD': 'ref: refs/heads/liw/foo',
+ },
+ {
+ 'name': 'heippa',
+ 'location': 'tag',
+ 'ref': 'heippa-0.4',
+ 'HEAD': 'f1b343f846c8f38d8e3bc35bc28064b46291676d'
+ },
+ {
+ 'name': 'heippa',
+ 'location': 'sha',
+ 'ref': '58fffbf8b8aba0660f1759674c1ac818789b7d45',
+ 'HEAD': '58fffbf8b8aba0660f1759674c1ac818789b7d45',
+ },
+ ],
+}
+params_encoded = base64.b64encode(json.dumps(params).encode('UTF-8')).decode('UTF-8')
+
+preamble = '''
+import base64, json
+params_encoded = '{}'
+params = json.loads(base64.b64decode(params_encoded))
+'''.format(params_encoded)
+
+print('Execute pipeline to check everything out initially')
+RUN('python3', '-c', preamble + code, cwd='workspace')
+
+print('Check that all is checked out OK')
+for src in params['sources']:
+ filename = 'workspace/{}/.git/HEAD'.format(src['location'])
+ data = open(filename).read().strip()
+ assert data == src['HEAD']
+ print('{} checked out OK'.format(src['name']))
+
+print('Make every checkout have the wrong branch checked out')
+for src in params['sources']:
+ RUN('git', 'checkout', 'wrong', cwd='workspace/{}'.format(src['location']))
+
+print('Execute pipeline to update exiting checkouts')
+RUN('python3', '-c', preamble + code, cwd='workspace')
+
+print('Check that all is checked out OK again')
+for src in params['sources']:
+ filename = 'workspace/{}/.git/HEAD'.format(src['location'])
+ data = open(filename).read().strip()
+ assert data == src['HEAD']
+ print('{} checked out OK'.format(src['name']))