|
@@ -0,0 +1,42 @@
|
|
1
|
+#!/usr/bin/python3
|
|
2
|
+
|
|
3
|
+import subprocess
|
|
4
|
+import unittest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+class RerunTest(unittest.TestCase):
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+ def _run(self, cmd):
|
|
11
|
+ subprocess.call(cmd,
|
|
12
|
+ stdout=subprocess.DEVNULL,
|
|
13
|
+ stderr=subprocess.DEVNULL)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+ def test_command_matches(self):
|
|
17
|
+ """
|
|
18
|
+ Tests that the command used to start a docker container exactly matches
|
|
19
|
+ that returned by ./docker-rerun --dry-run.
|
|
20
|
+ """
|
|
21
|
+ commands = [
|
|
22
|
+ 'docker run --name=test123 -d hello-world',
|
|
23
|
+ 'docker run --name=test123 --restart=always -d hello-world',
|
|
24
|
+ 'docker run --name=test123 --restart=on-failure:10 -d hello-world',
|
|
25
|
+ 'docker run --name=test123 --net=host -d hello-world',
|
|
26
|
+ 'docker run --name=test123 -d -p=127.0.0.1:443:443/tcp -p=127.0.0.1::1336/tcp hello-world',
|
|
27
|
+ 'docker run --name=test123 -d -p=443/tcp hello-world',
|
|
28
|
+ 'docker run --name=test123 --volume=/dev/null:/null --volume=/dev/urandom:/mnt/random -d hello-world',
|
|
29
|
+ ]
|
|
30
|
+
|
|
31
|
+ for command in commands:
|
|
32
|
+ with self.subTest(cmd=command):
|
|
33
|
+ self._run(['docker', 'rm', '-f', 'test123'])
|
|
34
|
+ self._run(command.split(' '))
|
|
35
|
+ output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
|
|
36
|
+ output = output.decode('utf-8').strip().splitlines()
|
|
37
|
+ self.assertEqual(output[3], command)
|
|
38
|
+ self._run(['docker', 'rm', '-f', 'test123'])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+if __name__ == '__main__':
|
|
42
|
+ unittest.main()
|