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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
import os
import pytest
import tempfile
import subprocess
import re
from contextlib import contextmanager
import http
import http.server
import socketserver
import threading
from buildstream import SourceError
from buildstream import utils
# import our common fixture
from .fixture import Setup
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'ostree',
)
class OSTreeSetup(Setup):
def __init__(self, datafiles, tmpdir, bstfile=None):
if not bstfile:
bstfile = 'target.bst'
super().__init__(datafiles, bstfile, tmpdir)
def run_ostree_bash_script():
# Run the generate-ostree.sh script
return subprocess.call(
['%s/generate-ostree.sh' % (DATA_DIR,)],
stderr=subprocess.PIPE)
def run_ostree_cli(repo, cmd):
if type(cmd) is not list:
cmd = [cmd]
arg = ['ostree', '--repo=%s' % (repo,)]
arg.extend(cmd)
process = subprocess.Popen(
arg,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
out, err = process.communicate()
return process.returncode, out, err
###############################################################
# Tests #
###############################################################
def test_ostree_shell_exe():
# Run the generate-ostree.sh script
# Does it run ok?
ret = run_ostree_bash_script()
assert(ret == 0)
def test_ostree_shell_dir_exist(tmpdir):
# tmp/repo and tmp/files directories should exist
run_ostree_bash_script()
assert(os.path.isdir("tmp/repo"))
assert(os.path.isdir("tmp/files"))
def test_ostree_shell_branches():
# only 'my/branch' should exist
run_ostree_bash_script()
exit, out, err = run_ostree_cli("tmp/repo", "refs")
assert(out.decode('unicode-escape').strip() == "my/branch")
exit, out, err = run_ostree_cli("repofoo", "refs")
assert(err.decode('unicode-escape') != '')
def test_ostree_shell_commits():
# only 2 commits
global REF_HEAD, REF_NOTHEAD
run_ostree_bash_script()
exit, out, err = run_ostree_cli("tmp/repo", ["log", "my/branch"])
reg = re.compile(r'commit ([a-z0-9]{64})')
commits = [m.groups()[0] for m in reg.finditer(str(out))]
assert(len(commits) == 2)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'head'))
def test_ostree_conf(tmpdir, datafiles):
setup = OSTreeSetup(datafiles, tmpdir)
assert(setup.source.get_kind() == 'ostree')
print(setup.source.url)
# Test other config settings
assert(setup.source.url == 'http://127.0.0.1:8000/tmp/repo')
assert(setup.source.tracking == 'my/branch')
assert(setup.source.gpg_key is None)
# XXX The following test cases are broken and should be revived, checkouts
# and fetches actually work, but the scaffolding for this test case needs work.
#
# @pytest.mark.datafiles(os.path.join(DATA_DIR, 'head'))
# def test_ostree_fetch(tmpdir, datafiles):
# setup = OSTreeSetup(datafiles, tmpdir)
# assert(setup.source.get_kind() == 'ostree')
#
# print("fetch cwd : {}".format(os.getcwd()))
# # Make sure we preflight and fetch first, cant stage without fetching
# setup.source.preflight()
# setup.source.fetch()
#
# # Check to see if the directory contains basic OSTree directories
# expected = ['objects', 'config', 'tmp', 'extensions', 'state', 'refs']
# indir = os.listdir(setup.source.mirror)
# assert(set(expected) <= set(indir))
# @pytest.mark.datafiles(os.path.join(DATA_DIR, 'head'))
# def test_ostree_stage(tmpdir, datafiles):
# setup = OSTreeSetup(datafiles, tmpdir)
# assert(setup.source.get_kind() == 'ostree')
# Make sure we preflight and fetch first, cant stage without fetching
# setup.source.preflight()
# setup.source.fetch()
# Stage the file and just check that it's there
# stagedir = os.path.join(setup.context.builddir, 'repo')
# setup.source.stage(stagedir)
|