Skip to content

Commit 9756a4e

Browse files
committed
Fix build tests to not rely on internet connectivity
Signed-off-by: Joffrey F <[email protected]>
1 parent e055729 commit 9756a4e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

tests/integration/api_build_test.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import pytest
99
import six
1010

11-
from .base import BaseAPIIntegrationTest
12-
from ..helpers import requires_api_version, requires_experimental
11+
from .base import BaseAPIIntegrationTest, BUSYBOX
12+
from ..helpers import random_name, requires_api_version, requires_experimental
1313

1414

1515
class BuildTest(BaseAPIIntegrationTest):
@@ -214,21 +214,31 @@ def test_build_container_with_target(self):
214214

215215
@requires_api_version('1.25')
216216
def test_build_with_network_mode(self):
217+
# Set up pingable endpoint on custom network
218+
network = self.client.create_network(random_name())['Id']
219+
self.tmp_networks.append(network)
220+
container = self.client.create_container(BUSYBOX, 'top')
221+
self.tmp_containers.append(container)
222+
self.client.start(container)
223+
self.client.connect_container_to_network(
224+
container, network, aliases=['pingtarget.docker']
225+
)
226+
217227
script = io.BytesIO('\n'.join([
218228
'FROM busybox',
219-
'RUN wget http://google.com'
229+
'RUN ping -c1 pingtarget.docker'
220230
]).encode('ascii'))
221231

222232
stream = self.client.build(
223-
fileobj=script, network_mode='bridge',
224-
tag='dockerpytest_bridgebuild'
233+
fileobj=script, network_mode=network,
234+
tag='dockerpytest_customnetbuild'
225235
)
226236

227-
self.tmp_imgs.append('dockerpytest_bridgebuild')
237+
self.tmp_imgs.append('dockerpytest_customnetbuild')
228238
for chunk in stream:
229-
pass
239+
print chunk
230240

231-
assert self.client.inspect_image('dockerpytest_bridgebuild')
241+
assert self.client.inspect_image('dockerpytest_customnetbuild')
232242

233243
script.seek(0)
234244
stream = self.client.build(
@@ -260,7 +270,7 @@ def test_build_with_extra_hosts(self):
260270
fileobj=script, tag=img_name,
261271
extra_hosts={
262272
'extrahost.local.test': '127.0.0.1',
263-
'hello.world.test': '8.8.8.8',
273+
'hello.world.test': '127.0.0.1',
264274
}, decode=True
265275
)
266276
for chunk in stream:
@@ -274,7 +284,7 @@ def test_build_with_extra_hosts(self):
274284
if six.PY3:
275285
logs = logs.decode('utf-8')
276286
assert '127.0.0.1\textrahost.local.test' in logs
277-
assert '8.8.8.8\thello.world.test' in logs
287+
assert '127.0.0.1\thello.world.test' in logs
278288

279289
@requires_experimental(until=None)
280290
@requires_api_version('1.25')

0 commit comments

Comments
 (0)