Skip to content

Commit 073a21c

Browse files
committed
Separate into individual tests
Signed-off-by: Joffrey F <[email protected]>
1 parent b06e437 commit 073a21c

File tree

1 file changed

+77
-63
lines changed

1 file changed

+77
-63
lines changed

tests/integration/api_exec_test.py

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -115,69 +115,6 @@ def test_exec_command_streaming(self):
115115
res += chunk
116116
assert res == b'hello\nworld\n'
117117

118-
def test_exec_command_demux(self):
119-
container = self.client.create_container(
120-
BUSYBOX, 'cat', detach=True, stdin_open=True)
121-
id = container['Id']
122-
self.client.start(id)
123-
self.tmp_containers.append(id)
124-
125-
script = ' ; '.join([
126-
# Write something on stdout
127-
'echo hello out',
128-
# Write something on stderr
129-
'echo hello err >&2'])
130-
cmd = 'sh -c "{}"'.format(script)
131-
132-
# tty=False, stream=False, demux=False
133-
res = self.client.exec_create(id, cmd)
134-
exec_log = self.client.exec_start(res)
135-
assert 'hello out\n' in exec_log
136-
assert 'hello err\n' in exec_log
137-
138-
# tty=False, stream=True, demux=False
139-
res = self.client.exec_create(id, cmd)
140-
exec_log = list(self.client.exec_start(res, stream=True))
141-
assert len(exec_log) == 2
142-
assert 'hello out\n' in exec_log
143-
assert 'hello err\n' in exec_log
144-
145-
# tty=False, stream=False, demux=True
146-
res = self.client.exec_create(id, cmd)
147-
exec_log = self.client.exec_start(res, demux=True)
148-
assert exec_log == (b'hello out\n', b'hello err\n')
149-
150-
# tty=False, stream=True, demux=True
151-
res = self.client.exec_create(id, cmd)
152-
exec_log = list(self.client.exec_start(res, demux=True, stream=True))
153-
assert len(exec_log) == 2
154-
assert (b'hello out\n', None) in exec_log
155-
assert (None, b'hello err\n') in exec_log
156-
157-
# tty=True, stream=False, demux=False
158-
res = self.client.exec_create(id, cmd, tty=True)
159-
exec_log = self.client.exec_start(res)
160-
assert exec_log == b'hello out\r\nhello err\r\n'
161-
162-
# tty=True, stream=True, demux=False
163-
res = self.client.exec_create(id, cmd, tty=True)
164-
exec_log = list(self.client.exec_start(res, stream=True))
165-
assert len(exec_log) == 2
166-
assert 'hello out\r\n' in exec_log
167-
assert 'hello err\r\n' in exec_log
168-
169-
# tty=True, stream=False, demux=True
170-
res = self.client.exec_create(id, cmd, tty=True)
171-
exec_log = self.client.exec_start(res, demux=True)
172-
assert exec_log == (b'hello out\r\nhello err\r\n', None)
173-
174-
# tty=True, stream=True, demux=True
175-
res = self.client.exec_create(id, cmd, tty=True)
176-
exec_log = list(self.client.exec_start(res, demux=True, stream=True))
177-
assert len(exec_log) == 2
178-
assert (b'hello out\r\n', None) in exec_log
179-
assert (b'hello err\r\n', None) in exec_log
180-
181118
def test_exec_start_socket(self):
182119
container = self.client.create_container(BUSYBOX, 'cat',
183120
detach=True, stdin_open=True)
@@ -307,3 +244,80 @@ def test_detach_with_arg(self):
307244
self.addCleanup(sock.close)
308245

309246
assert_cat_socket_detached_with_keys(sock, [ctrl_with('x')])
247+
248+
249+
class ExecDemuxTest(BaseAPIIntegrationTest):
250+
cmd = 'sh -c "{}"'.format(' ; '.join([
251+
# Write something on stdout
252+
'echo hello out',
253+
# Busybox's sleep does not handle sub-second times.
254+
# This loops takes ~0.3 second to execute on my machine.
255+
'for i in $(seq 1 50000); do echo $i>/dev/null; done',
256+
# Write something on stderr
257+
'echo hello err >&2'])
258+
)
259+
260+
def setUp(self):
261+
super(ExecDemuxTest, self).setUp()
262+
self.container = self.client.create_container(
263+
BUSYBOX, 'cat', detach=True, stdin_open=True
264+
)
265+
self.client.start(self.container)
266+
self.tmp_containers.append(self.container)
267+
268+
def test_exec_command_no_stream_no_demux(self):
269+
# tty=False, stream=False, demux=False
270+
res = self.client.exec_create(self.container, self.cmd)
271+
exec_log = self.client.exec_start(res)
272+
assert b'hello out\n' in exec_log
273+
assert b'hello err\n' in exec_log
274+
275+
def test_exec_command_stream_no_demux(self):
276+
# tty=False, stream=True, demux=False
277+
res = self.client.exec_create(self.container, self.cmd)
278+
exec_log = list(self.client.exec_start(res, stream=True))
279+
assert len(exec_log) == 2
280+
assert b'hello out\n' in exec_log
281+
assert b'hello err\n' in exec_log
282+
283+
def test_exec_command_no_stream_demux(self):
284+
# tty=False, stream=False, demux=True
285+
res = self.client.exec_create(self.container, self.cmd)
286+
exec_log = self.client.exec_start(res, demux=True)
287+
assert exec_log == (b'hello out\n', b'hello err\n')
288+
289+
def test_exec_command_stream_demux(self):
290+
# tty=False, stream=True, demux=True
291+
res = self.client.exec_create(self.container, self.cmd)
292+
exec_log = list(self.client.exec_start(res, demux=True, stream=True))
293+
assert len(exec_log) == 2
294+
assert (b'hello out\n', None) in exec_log
295+
assert (None, b'hello err\n') in exec_log
296+
297+
def test_exec_command_tty_no_stream_no_demux(self):
298+
# tty=True, stream=False, demux=False
299+
res = self.client.exec_create(self.container, self.cmd, tty=True)
300+
exec_log = self.client.exec_start(res)
301+
assert exec_log == b'hello out\r\nhello err\r\n'
302+
303+
def test_exec_command_tty_stream_no_demux(self):
304+
# tty=True, stream=True, demux=False
305+
res = self.client.exec_create(self.container, self.cmd, tty=True)
306+
exec_log = list(self.client.exec_start(res, stream=True))
307+
assert len(exec_log) == 2
308+
assert b'hello out\r\n' in exec_log
309+
assert b'hello err\r\n' in exec_log
310+
311+
def test_exec_command_tty_no_stream_demux(self):
312+
# tty=True, stream=False, demux=True
313+
res = self.client.exec_create(self.container, self.cmd, tty=True)
314+
exec_log = self.client.exec_start(res, demux=True)
315+
assert exec_log == (b'hello out\r\nhello err\r\n', None)
316+
317+
def test_exec_command_tty_stream_demux(self):
318+
# tty=True, stream=True, demux=True
319+
res = self.client.exec_create(self.container, self.cmd, tty=True)
320+
exec_log = list(self.client.exec_start(res, demux=True, stream=True))
321+
assert len(exec_log) == 2
322+
assert (b'hello out\r\n', None) in exec_log
323+
assert (b'hello err\r\n', None) in exec_log

0 commit comments

Comments
 (0)