|
@@ -1,37 +1,32 @@
|
1
|
1
|
#!/usr/bin/python3
|
2
|
2
|
|
3
|
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
|
|
- commands = [
|
18
|
|
- 'docker run --name=test123 -d hello-world',
|
19
|
|
- 'docker run --name=test123 -d hello-world:latest',
|
20
|
|
- 'docker run --name=test123 -d hello-world /hello world...',
|
21
|
|
- 'docker run --name=test123 --restart=always -d hello-world',
|
22
|
|
- 'docker run --name=test123 --restart=on-failure:10 -d hello-world',
|
23
|
|
- 'docker run --name=test123 --net=host -d hello-world',
|
24
|
|
- 'docker run --name=test123 -d -p=127.0.0.1:443:443/tcp -p=127.0.0.1::1336/tcp hello-world',
|
25
|
|
- 'docker run --name=test123 -d -p=443/tcp hello-world',
|
26
|
|
- 'docker run --name=test123 --volume=/dev/null:/null --volume=/dev/urandom:/mnt/random -d hello-world',
|
27
|
|
- ]
|
28
|
|
-
|
29
|
|
- for command in commands:
|
30
|
|
- with self.subTest(cmd=command):
|
31
|
|
- self._run(['docker', 'rm', '-f', 'test123'])
|
32
|
|
- self._run(command.split(' '))
|
33
|
|
- output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
|
34
|
|
- output = output.decode('utf-8').strip().splitlines()
|
35
|
|
- self.assertEqual(output[3], command)
|
36
|
|
- self._run(['docker', 'rm', '-f', 'test123'])
|
|
4
|
+from nose_parameterized import parameterized
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+def _run(cmd):
|
|
8
|
+ subprocess.call(cmd,
|
|
9
|
+ stdout=subprocess.DEVNULL,
|
|
10
|
+ stderr=subprocess.DEVNULL)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+@parameterized([
|
|
14
|
+ 'docker run --name=test123 -d hello-world',
|
|
15
|
+ 'docker run --name=test123 -d hello-world:latest',
|
|
16
|
+ 'docker run --name=test123 -d hello-world /hello world...',
|
|
17
|
+ 'docker run --name=test123 --restart=always -d hello-world',
|
|
18
|
+ 'docker run --name=test123 --restart=on-failure:10 -d hello-world',
|
|
19
|
+ 'docker run --name=test123 --net=host -d hello-world',
|
|
20
|
+ 'docker run --name=test123 -d -p=127.0.0.1:443:443/tcp -p=127.0.0.1::1336/tcp hello-world',
|
|
21
|
+ 'docker run --name=test123 -d -p=443/tcp hello-world',
|
|
22
|
+ 'docker run --name=test123 --user=root -d hello-world /hello foobar',
|
|
23
|
+ 'docker run --name=test123 --volume=/dev/null:/null --volume=/dev/urandom:/mnt/random -d hello-world',
|
|
24
|
+])
|
|
25
|
+def test_command_matches(command):
|
|
26
|
+ _run(['docker', 'rm', '-f', 'test123'])
|
|
27
|
+ _run(command.split(' '))
|
|
28
|
+ output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
|
|
29
|
+ output = output.decode('utf-8').strip().splitlines()
|
|
30
|
+ assert output[3] == command
|
|
31
|
+ _run(['docker', 'rm', '-f', 'test123'])
|
37
|
32
|
|