summaryrefslogtreecommitdiff
path: root/tests/integration/exec_test.py
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-09-23 17:42:29 -0700
committerJoffrey F <joffrey@docker.com>2015-10-21 16:02:09 -0700
commit93a296fb0448d9fccdf9f40f7a9996f49ea22c48 (patch)
tree633371cbdf88435664b530c4ca835c4929d92274 /tests/integration/exec_test.py
parent5a1c7ed8bf0ac9a3914de7c80c1c29c13f6a62ea (diff)
downloaddocker-py-reorganize_tests.tar.gz
Reorganize test directoriesreorganize_tests
More clearly separate unit and integration tests Allow splitting into multiple files Cleaner Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'tests/integration/exec_test.py')
-rw-r--r--tests/integration/exec_test.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/integration/exec_test.py b/tests/integration/exec_test.py
new file mode 100644
index 0000000..39883d6
--- /dev/null
+++ b/tests/integration/exec_test.py
@@ -0,0 +1,106 @@
+import pytest
+
+from . import api_test
+
+BUSYBOX = api_test.BUSYBOX
+
+
+class ExecTest(api_test.BaseTestCase):
+ def test_execute_command(self):
+ if not api_test.exec_driver_is_native():
+ pytest.skip('Exec driver not native')
+
+ container = self.client.create_container(BUSYBOX, 'cat',
+ detach=True, stdin_open=True)
+ id = container['Id']
+ self.client.start(id)
+ self.tmp_containers.append(id)
+
+ res = self.client.exec_create(id, ['echo', 'hello'])
+ self.assertIn('Id', res)
+
+ exec_log = self.client.exec_start(res)
+ self.assertEqual(exec_log, b'hello\n')
+
+ def test_exec_command_string(self):
+ if not api_test.exec_driver_is_native():
+ pytest.skip('Exec driver not native')
+
+ container = self.client.create_container(BUSYBOX, 'cat',
+ detach=True, stdin_open=True)
+ id = container['Id']
+ self.client.start(id)
+ self.tmp_containers.append(id)
+
+ res = self.client.exec_create(id, 'echo hello world')
+ self.assertIn('Id', res)
+
+ exec_log = self.client.exec_start(res)
+ self.assertEqual(exec_log, b'hello world\n')
+
+ def test_exec_command_as_user(self):
+ if not api_test.exec_driver_is_native():
+ pytest.skip('Exec driver not native')
+
+ container = self.client.create_container(BUSYBOX, 'cat',
+ detach=True, stdin_open=True)
+ id = container['Id']
+ self.client.start(id)
+ self.tmp_containers.append(id)
+
+ res = self.client.exec_create(id, 'whoami', user='default')
+ self.assertIn('Id', res)
+
+ exec_log = self.client.exec_start(res)
+ self.assertEqual(exec_log, b'default\n')
+
+ def test_exec_command_as_root(self):
+ if not api_test.exec_driver_is_native():
+ pytest.skip('Exec driver not native')
+
+ container = self.client.create_container(BUSYBOX, 'cat',
+ detach=True, stdin_open=True)
+ id = container['Id']
+ self.client.start(id)
+ self.tmp_containers.append(id)
+
+ res = self.client.exec_create(id, 'whoami')
+ self.assertIn('Id', res)
+
+ exec_log = self.client.exec_start(res)
+ self.assertEqual(exec_log, b'root\n')
+
+ def test_exec_command_streaming(self):
+ if not api_test.exec_driver_is_native():
+ pytest.skip('Exec driver not native')
+
+ container = self.client.create_container(BUSYBOX, 'cat',
+ detach=True, stdin_open=True)
+ id = container['Id']
+ self.client.start(id)
+ self.tmp_containers.append(id)
+
+ exec_id = self.client.exec_create(id, ['echo', 'hello\nworld'])
+ self.assertIn('Id', exec_id)
+
+ res = b''
+ for chunk in self.client.exec_start(exec_id, stream=True):
+ res += chunk
+ self.assertEqual(res, b'hello\nworld\n')
+
+ def test_exec_inspect(self):
+ if not api_test.exec_driver_is_native():
+ pytest.skip('Exec driver not native')
+
+ container = self.client.create_container(BUSYBOX, 'cat',
+ detach=True, stdin_open=True)
+ id = container['Id']
+ self.client.start(id)
+ self.tmp_containers.append(id)
+
+ exec_id = self.client.exec_create(id, ['mkdir', '/does/not/exist'])
+ self.assertIn('Id', exec_id)
+ self.client.exec_start(exec_id)
+ exec_info = self.client.exec_inspect(exec_id)
+ self.assertIn('ExitCode', exec_info)
+ self.assertNotEqual(exec_info['ExitCode'], 0)