Skip to content

Commit 6c8e0cf

Browse files
Merge pull request #189 from JonathonReinhart/ci-updates
Minor CI test update
2 parents 93dcd45 + dd13cbf commit 6c8e0cf

File tree

7 files changed

+70
-41
lines changed

7 files changed

+70
-41
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: [3.5, 3.6, 3.7, 3.8]
14+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
1515
fail-fast: False
1616

1717
steps:

ci/test_setup.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ set -e
33

44
topdir=$(cd $(dirname $0)/.. && pwd)
55

6-
# Pull this image ahead of time, so it's there for the unit tests
7-
docker pull debian:8.2
6+
# Load test constants
7+
eval $(cd $topdir && python3 -m tests.const)
8+
9+
# Pull this image ahead of time, so it's there for the tests
10+
docker pull "$DOCKER_IMAGE"
811

912
# Build docker images for local testing
1013
$topdir/test-docker-images/build_all.sh

run_full_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import tempfile
66
import shutil
77

8+
from tests.const import DOCKER_IMAGE
9+
810

911
class InTempDir:
1012
def __init__(self, suffix='', prefix='tmp', delete=True):
@@ -25,7 +27,7 @@ def __exit__(self, *exc_info):
2527
def test1():
2628
with InTempDir(prefix='scuba-systest'):
2729
with open('.scuba.yml', 'w+t') as f:
28-
f.write('image: debian:8.2\n')
30+
f.write('image: {}\n'.format(DOCKER_IMAGE))
2931

3032
in_data = 'success'
3133

tests/const.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Constants used throughout the test suite
2+
3+
# Main Docker image
4+
# This image is used for nearly all tests where a "real" docker image is
5+
# necessary (becuase we're going to actually invoke some docker command).
6+
#
7+
# Requirements:
8+
# - Must contain /bin/bash (TestMain::test_*shell_override*)
9+
#
10+
DOCKER_IMAGE = 'debian:10'
11+
12+
# Alternate Docker image
13+
# This image is used for alternate tests (e.g. pulling) and should be small.
14+
ALT_DOCKER_IMAGE = 'busybox:latest'
15+
16+
17+
# Act as an executable for consumption by non-Python things
18+
if __name__ == '__main__':
19+
for name, val in dict(vars()).items():
20+
if name.startswith('_'):
21+
continue
22+
print('{}="{}"'.format(name, val))

tests/test_config.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TestConfig:
5858
def test_find_config_cur_dir(self, in_tmp_path):
5959
'''find_config can find the config in the current directory'''
6060
with open('.scuba.yml', 'w') as f:
61-
f.write('image: busybox\n')
61+
f.write('image: bosybux\n')
6262

6363
path, rel, _ = scuba.config.find_config()
6464
assert_paths_equal(path, in_tmp_path)
@@ -68,7 +68,7 @@ def test_find_config_cur_dir(self, in_tmp_path):
6868
def test_find_config_parent_dir(self, in_tmp_path):
6969
'''find_config cuba can find the config in the parent directory'''
7070
with open('.scuba.yml', 'w') as f:
71-
f.write('image: busybox\n')
71+
f.write('image: bosybux\n')
7272

7373
os.mkdir('subdir')
7474
os.chdir('subdir')
@@ -83,7 +83,7 @@ def test_find_config_parent_dir(self, in_tmp_path):
8383
def test_find_config_way_up(self, in_tmp_path):
8484
'''find_config can find the config way up the directory hierarchy'''
8585
with open('.scuba.yml', 'w') as f:
86-
f.write('image: busybox\n')
86+
f.write('image: bosybux\n')
8787

8888
subdirs = ['foo', 'bar', 'snap', 'crackle', 'pop']
8989

@@ -122,37 +122,37 @@ def test_load_config_no_image(self):
122122
def test_load_unexpected_node(self):
123123
'''load_config raises ConfigError on unexpected config node'''
124124
with open('.scuba.yml', 'w') as f:
125-
f.write('image: busybox\n')
125+
f.write('image: bosybux\n')
126126
f.write('unexpected_node_123456: value\n')
127127

128128
self._invalid_config()
129129

130130
def test_load_config_minimal(self):
131131
'''load_config loads a minimal config'''
132132
with open('.scuba.yml', 'w') as f:
133-
f.write('image: busybox\n')
133+
f.write('image: bosybux\n')
134134

135135
config = scuba.config.load_config('.scuba.yml')
136-
assert config.image == 'busybox'
136+
assert config.image == 'bosybux'
137137

138138
def test_load_config_with_aliases(self):
139139
'''load_config loads a config with aliases'''
140140
with open('.scuba.yml', 'w') as f:
141-
f.write('image: busybox\n')
141+
f.write('image: bosybux\n')
142142
f.write('aliases:\n')
143143
f.write(' foo: bar\n')
144144
f.write(' snap: crackle pop\n')
145145

146146
config = scuba.config.load_config('.scuba.yml')
147-
assert config.image == 'busybox'
147+
assert config.image == 'bosybux'
148148
assert len(config.aliases) == 2
149149
assert config.aliases['foo'].script == ['bar']
150150
assert config.aliases['snap'].script == ['crackle pop']
151151

152152
def test_load_config__no_spaces_in_aliases(self):
153153
'''load_config refuses spaces in aliases'''
154154
with open('.scuba.yml', 'w') as f:
155-
f.write('image: busybox\n')
155+
f.write('image: bosybux\n')
156156
f.write('aliases:\n')
157157
f.write(' this has spaces: whatever\n')
158158

@@ -161,46 +161,46 @@ def test_load_config__no_spaces_in_aliases(self):
161161
def test_load_config_image_from_yaml(self):
162162
'''load_config loads a config using !from_yaml'''
163163
with open('.gitlab.yml', 'w') as f:
164-
f.write('image: debian:8.2\n')
164+
f.write('image: dummian:8.2\n')
165165

166166
with open('.scuba.yml', 'w') as f:
167167
f.write('image: !from_yaml .gitlab.yml image\n')
168168

169169
config = scuba.config.load_config('.scuba.yml')
170-
assert config.image == 'debian:8.2'
170+
assert config.image == 'dummian:8.2'
171171

172172
def test_load_config_image_from_yaml_nested_keys(self):
173173
'''load_config loads a config using !from_yaml with nested keys'''
174174
with open('.gitlab.yml', 'w') as f:
175175
f.write('somewhere:\n')
176176
f.write(' down:\n')
177-
f.write(' here: debian:8.2\n')
177+
f.write(' here: dummian:8.2\n')
178178

179179
with open('.scuba.yml', 'w') as f:
180180
f.write('image: !from_yaml .gitlab.yml somewhere.down.here\n')
181181

182182
config = scuba.config.load_config('.scuba.yml')
183-
assert config.image == 'debian:8.2'
183+
assert config.image == 'dummian:8.2'
184184

185185
def test_load_config_image_from_yaml_nested_keys_with_escaped_characters(self):
186186
'''load_config loads a config using !from_yaml with nested keys containing escaped '.' characters'''
187187
with open('.gitlab.yml', 'w') as f:
188188
f.write('.its:\n')
189189
f.write(' somewhere.down:\n')
190-
f.write(' here: debian:8.2\n')
190+
f.write(' here: dummian:8.2\n')
191191

192192
with open('.scuba.yml', 'w') as f:
193193
f.write('image: !from_yaml .gitlab.yml "\\.its.somewhere\\.down.here"\n')
194194

195195
config = scuba.config.load_config('.scuba.yml')
196-
assert config.image == 'debian:8.2'
196+
assert config.image == 'dummian:8.2'
197197

198198
def test_load_config_from_yaml_cached_file(self):
199199
'''load_config loads a config using !from_yaml from cached version'''
200200
with open('.gitlab.yml', 'w') as f:
201-
f.write('one: debian:8.2\n')
202-
f.write('two: debian:9.3\n')
203-
f.write('three: debian:10.1\n')
201+
f.write('one: dummian:8.2\n')
202+
f.write('two: dummian:9.3\n')
203+
f.write('three: dummian:10.1\n')
204204

205205
with open('.scuba.yml', 'w') as f:
206206
f.write('image: !from_yaml .gitlab.yml one\n')
@@ -254,7 +254,7 @@ def test_load_config_image_from_yaml_unicode_args(self):
254254
def test_load_config_image_from_yaml_missing_arg(self):
255255
'''load_config raises ConfigError when !from_yaml has missing args'''
256256
with open('.gitlab.yml', 'w') as f:
257-
f.write('image: debian:8.2\n')
257+
f.write('image: dummian:8.2\n')
258258

259259
with open('.scuba.yml', 'w') as f:
260260
f.write('image: !from_yaml .gitlab.yml\n')

tests/test_dockerutil.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import pytest
44

55
import subprocess
6+
from .const import *
67

78
import scuba.dockerutil as uut
89

910
def test_get_image_command_success():
1011
'''get_image_command works'''
11-
assert uut.get_image_command('debian:8.2')
12+
assert uut.get_image_command(DOCKER_IMAGE)
1213

1314
def test_get_image_command_bad_image():
1415
'''get_image_command raises an exception for a bad image name'''
@@ -47,23 +48,23 @@ def test_get_images_success__no_images():
4748
def test_get_images_success__multiple_images():
4849
'''get_images works when many images are present'''
4950
output = '''\
50-
busybox
51-
busybox:latest
52-
debian
53-
debian:buster
54-
debian:latest
55-
scuba/scratch
56-
scuba/scratch:latest
51+
foo
52+
foo:latest
53+
bar
54+
bar:snap
55+
bar:latest
56+
dummy/crackle
57+
dummy/crackle:pop
5758
'''
5859
images = _test_get_images(output)
5960
assert images == [
60-
'busybox',
61-
'busybox:latest',
62-
'debian',
63-
'debian:buster',
64-
'debian:latest',
65-
'scuba/scratch',
66-
'scuba/scratch:latest',
61+
'foo',
62+
'foo:latest',
63+
'bar',
64+
'bar:snap',
65+
'bar:latest',
66+
'dummy/crackle',
67+
'dummy/crackle:pop',
6768
]
6869

6970
def test_get_images__failure():
@@ -74,7 +75,7 @@ def test_get_images__failure():
7475

7576
def test__get_image_command__pulls_image_if_missing():
7677
'''get_image_command pulls an image if missing'''
77-
image = 'busybox:latest'
78+
image = ALT_DOCKER_IMAGE
7879

7980
# First remove the image
8081
subprocess.call(['docker', 'rmi', image])
@@ -92,7 +93,7 @@ def test_get_image_entrypoint():
9293

9394
def test_get_image_entrypoint__none():
9495
'''get_image_entrypoint works for image with no entrypoint'''
95-
result = uut.get_image_entrypoint('debian')
96+
result = uut.get_image_entrypoint(DOCKER_IMAGE)
9697
assert result is None
9798

9899

tests/test_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import scuba
1919
import re
2020

21-
DOCKER_IMAGE = 'debian:8.2'
21+
from .const import DOCKER_IMAGE
22+
2223
SCUBAINIT_EXIT_FAIL = 99
2324

2425
@pytest.mark.usefixtures("in_tmp_path")

0 commit comments

Comments
 (0)