Skip to content

Commit

Permalink
Adjust integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Petito <[email protected]>
  • Loading branch information
krissetto committed Mar 18, 2024
1 parent bd164f9 commit 20ef813
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
5 changes: 4 additions & 1 deletion tests/integration/api_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,10 @@ def test_attach_no_stream(self):
)
self.tmp_containers.append(container)
self.client.start(container)
self.client.wait(container, condition='not-running')
wait_kwargs = {}
if TEST_API_VERSION >= "1.30":
wait_kwargs['condition'] = 'not-running'
self.client.wait(container, **wait_kwargs)
output = self.client.attach(container, stream=False, logs=True)
assert output == 'hello\n'.encode(encoding='ascii')

Expand Down
26 changes: 14 additions & 12 deletions tests/integration/api_exec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ..helpers import ctrl_with
from ..helpers import requires_api_version
from .base import BaseAPIIntegrationTest
from .base import TEST_IMG
from .base import TEST_IMG, TEST_API_VERSION
from docker.utils.proxy import ProxyConfig
from docker.utils.socket import next_frame_header
from docker.utils.socket import read_exactly
Expand Down Expand Up @@ -35,17 +35,19 @@ def test_execute_command_with_proxy_env(self):
for item in expected:
assert item in output

# Overwrite some variables with a custom environment
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}

res = self.client.exec_create(container, cmd=cmd, environment=env)
output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',
'FTP_PROXY=a', 'HTTPS_PROXY=XXX', 'HTTP_PROXY=c', 'NO_PROXY=d'
]
for item in expected:
assert item in output
# Setting environment for exec is not supported in API < 1.25
if TEST_API_VERSION > "1.24":
# Overwrite some variables with a custom environment
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}

res = self.client.exec_create(container, cmd=cmd, environment=env)
output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',
'FTP_PROXY=a', 'HTTPS_PROXY=XXX', 'HTTP_PROXY=c', 'NO_PROXY=d'
]
for item in expected:
assert item in output

def test_execute_command(self):
container = self.client.create_container(TEST_IMG, 'cat',
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/api_swarm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def test_init_swarm_simple(self):

@requires_api_version('1.24')
def test_init_swarm_force_new_cluster(self):
pytest.skip('Test stalls the engine on 1.12.0')

assert self.init_swarm()
version_1 = self.client.inspect_swarm()['Version']['Index']
assert self.client.init_swarm(force_new_cluster=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/models_containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_run_with_network(self):
assert 'Networks' in attrs['NetworkSettings']
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]

@requires_api_version('1.32')
def test_run_with_networking_config(self):
net_name = random_name()
client = docker.from_env(version=TEST_API_VERSION)
Expand Down Expand Up @@ -137,6 +138,7 @@ def test_run_with_networking_config(self):
assert attrs['NetworkSettings']['Networks'][net_name]['DriverOpts'] \
== test_driver_opt

@requires_api_version('1.32')
def test_run_with_networking_config_with_undeclared_network(self):
net_name = random_name()
client = docker.from_env(version=TEST_API_VERSION)
Expand Down Expand Up @@ -165,6 +167,7 @@ def test_run_with_networking_config_with_undeclared_network(self):
)
self.tmp_containers.append(container.id)

@requires_api_version('1.32')
def test_run_with_networking_config_only_undeclared_network(self):
net_name = random_name()
client = docker.from_env(version=TEST_API_VERSION)
Expand Down
29 changes: 17 additions & 12 deletions tests/integration/models_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@ def tearDownClass(cls):
def test_create(self):
client = docker.from_env(version=TEST_API_VERSION)
name = helpers.random_name()
service = client.services.create(
create_kwargs = {
# create arguments
name=name,
labels={'foo': 'bar'},
'name': name,
'labels': {'foo': 'bar'},
# ContainerSpec arguments
image="alpine",
command="sleep 300",
container_labels={'container': 'label'},
rollback_config={'order': 'start-first'}
)
'image': "alpine",
'command': "sleep 300",
'container_labels': {'container': 'label'}
}
if TEST_API_VERSION >= "1.28":
args['rollback_config'] = {'order': 'start-first'}

service = client.services.create(**create_kwargs)

assert service.name == name
assert service.attrs['Spec']['Labels']['foo'] == 'bar'
container_spec = service.attrs['Spec']['TaskTemplate']['ContainerSpec']
assert "alpine" in container_spec['Image']
assert container_spec['Labels'] == {'container': 'label'}
spec_rollback = service.attrs['Spec'].get('RollbackConfig', None)
assert spec_rollback is not None
assert ('Order' in spec_rollback and
spec_rollback['Order'] == 'start-first')
if TEST_API_VERSION >= "1.28":
spec_rollback = service.attrs['Spec'].get('RollbackConfig', None)
assert spec_rollback is not None
assert ('Order' in spec_rollback and
spec_rollback['Order'] == 'start-first')

def test_create_with_network(self):
client = docker.from_env(version=TEST_API_VERSION)
Expand Down

0 comments on commit 20ef813

Please sign in to comment.