|
@@ -1,7 +1,7 @@
|
1
|
1
|
#!/usr/bin/python3
|
2
|
2
|
|
3
|
3
|
import subprocess
|
4
|
|
-from nose_parameterized import parameterized
|
|
4
|
+from nose.tools import with_setup
|
5
|
5
|
|
6
|
6
|
|
7
|
7
|
def _run(cmd):
|
|
@@ -10,28 +10,48 @@ def _run(cmd):
|
10
|
10
|
stderr=subprocess.DEVNULL)
|
11
|
11
|
|
12
|
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', '--env=PATH=/root', '--env=Z=X', '--name=test123', '-d', 'hello-world'],
|
18
|
|
- ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world'],
|
19
|
|
- ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world'],
|
20
|
|
- ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world'],
|
21
|
|
- ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world'],
|
22
|
|
- ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world'],
|
23
|
|
- ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world'],
|
24
|
|
- ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar'],
|
25
|
|
- ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world'],
|
26
|
|
- ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world'],
|
27
|
|
- ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world'],
|
28
|
|
- ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world'],
|
29
|
|
-])
|
30
|
|
-def test_command_matches(*command):
|
|
13
|
+def setup():
|
|
14
|
+ _run(['docker', 'run', '--name=testA', '-d', 'hello-world'])
|
|
15
|
+ _run(['docker', 'run', '--name=testB', '-d', 'hello-world'])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+def teardown():
|
|
19
|
+ _run(['docker', 'rm', '-f', 'testA'])
|
|
20
|
+ _run(['docker', 'rm', '-f', 'testB'])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+def setup_each():
|
|
24
|
+ _run(['docker', 'rm', '-f', 'test123'])
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+def teardown_each():
|
31
|
28
|
_run(['docker', 'rm', '-f', 'test123'])
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+@with_setup(setup, teardown)
|
|
32
|
+def test_command_matches():
|
|
33
|
+ yield check, ['docker', 'run', '--name=test123', '-d', 'hello-world']
|
|
34
|
+ yield check, ['docker', 'run', '--name=test123', '-d', 'hello-world:latest']
|
|
35
|
+ yield check, ['docker', 'run', '--name=test123', '-d', 'hello-world', '/hello', 'world...']
|
|
36
|
+ yield check, ['docker', 'run', '--env=PATH=/root', '--env=Z=X', '--name=test123', '-d', 'hello-world']
|
|
37
|
+ yield check, ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world']
|
|
38
|
+ yield check, ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world']
|
|
39
|
+ yield check, ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world']
|
|
40
|
+ yield check, ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world']
|
|
41
|
+ yield check, ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world']
|
|
42
|
+ yield check, ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world']
|
|
43
|
+ yield check, ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar']
|
|
44
|
+ yield check, ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world']
|
|
45
|
+ yield check, ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world']
|
|
46
|
+ yield check, ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world']
|
|
47
|
+ yield check, ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world']
|
|
48
|
+ yield check, ['docker', 'run', '--link=testA:bar', '--link=testB', '--name=test123', '-d', 'hello-world']
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+@with_setup(setup_each, teardown_each)
|
|
52
|
+def check(command):
|
32
|
53
|
_run(command)
|
33
|
54
|
output = subprocess.check_output(['./docker-rerun', '--dry-run', 'test123'])
|
34
|
55
|
output = output.decode('utf-8').strip().splitlines()
|
35
|
|
- assert output[3] == ' '.join(command)
|
36
|
|
- _run(['docker', 'rm', '-f', 'test123'])
|
|
56
|
+ assert output[3] == ' '.join(command), 'Expected "%s" but got "%s"' % (' '.join(command), output[3])
|
37
|
57
|
|