Browse Source

Add tests.

tags/v0.1.1
Chris Smith 7 years ago
parent
commit
0397482230
3 changed files with 46 additions and 1 deletions
  1. 1
    0
      .gitignore
  2. 3
    1
      circle.yml
  3. 42
    0
      test.py

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+/__pycache__

+ 3
- 1
circle.yml View File

@@ -5,8 +5,10 @@ machine:
5 5
 
6 6
 dependencies:
7 7
   pre:
8
-    - pip install pylint
8
+    - pip install nose pylint
9 9
 
10 10
 test:
11 11
   override:
12 12
     - pylint -d invalid-name docker-rerun
13
+    - nosetests test.py
14
+

+ 42
- 0
test.py View File

@@ -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()

Loading…
Cancel
Save