test_sanity_checks.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. '''
  2. Unit tests for wildcard
  3. '''
  4. import os
  5. import sys
  6. MODULE_PATH = os.path.realpath(os.path.join(__file__, os.pardir, os.pardir, 'action_plugins'))
  7. sys.path.insert(0, MODULE_PATH)
  8. # pylint: disable=import-error,wrong-import-position,missing-docstring
  9. from sanity_checks import is_registry_match # noqa: E402
  10. def test_is_registry_match():
  11. '''
  12. Test for is_registry_match
  13. '''
  14. pat_allowall = "*"
  15. pat_docker = "docker.io"
  16. pat_subdomain = "*.example.com"
  17. pat_matchport = "registry:80"
  18. assert is_registry_match("docker.io/repo/my", pat_allowall)
  19. assert is_registry_match("example.com:4000/repo/my", pat_allowall)
  20. assert is_registry_match("172.192.222.10:4000/a/b/c", pat_allowall)
  21. assert is_registry_match("https://registry.com", pat_allowall)
  22. assert is_registry_match("example.com/openshift3/ose-${component}:${version}", pat_allowall)
  23. assert is_registry_match("docker.io/repo/my", pat_docker)
  24. assert is_registry_match("docker.io:443/repo/my", pat_docker)
  25. assert is_registry_match("docker.io/openshift3/ose-${component}:${version}", pat_allowall)
  26. assert not is_registry_match("example.com:4000/repo/my", pat_docker)
  27. assert not is_registry_match("index.docker.io/a/b/c", pat_docker)
  28. assert not is_registry_match("https://registry.com", pat_docker)
  29. assert not is_registry_match("example.com/openshift3/ose-${component}:${version}", pat_docker)
  30. assert is_registry_match("apps.foo.example.com/prefix", pat_subdomain)
  31. assert is_registry_match("sub.example.com:80", pat_subdomain)
  32. assert not is_registry_match("https://example.com:443/prefix", pat_subdomain)
  33. assert not is_registry_match("docker.io/library/my", pat_subdomain)
  34. assert not is_registry_match("https://hello.example.bar", pat_subdomain)
  35. assert is_registry_match("registry:80/prefix", pat_matchport)
  36. assert is_registry_match("registry/myapp", pat_matchport)
  37. assert is_registry_match("registry:443/myap", pat_matchport)
  38. assert not is_registry_match("https://example.com:443/prefix", pat_matchport)
  39. assert not is_registry_match("docker.io/library/my", pat_matchport)
  40. assert not is_registry_match("https://hello.registry/myapp", pat_matchport)