Utility to re-run a docker container with slightly different arguments
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 1.5KB

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