2022-01-18 14:54:14 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import unittest
|
2022-03-30 22:15:01 +00:00
|
|
|
from unittest.mock import patch, MagicMock
|
2022-01-18 14:54:14 +00:00
|
|
|
|
2023-06-15 13:11:30 +00:00
|
|
|
from version_helper import get_version_from_string
|
|
|
|
import docker_server as ds
|
2022-03-30 22:15:01 +00:00
|
|
|
|
2022-01-18 20:09:39 +00:00
|
|
|
# di.logging.basicConfig(level=di.logging.INFO)
|
|
|
|
|
2022-01-18 14:54:14 +00:00
|
|
|
|
2022-03-30 22:15:01 +00:00
|
|
|
class TestDockerServer(unittest.TestCase):
|
|
|
|
def test_gen_tags(self):
|
2022-04-01 15:53:43 +00:00
|
|
|
version = get_version_from_string("22.2.2.2")
|
2022-03-30 22:15:01 +00:00
|
|
|
cases = (
|
2022-04-01 15:53:43 +00:00
|
|
|
("latest", ["latest", "22", "22.2", "22.2.2", "22.2.2.2"]),
|
|
|
|
("major", ["22", "22.2", "22.2.2", "22.2.2.2"]),
|
|
|
|
("minor", ["22.2", "22.2.2", "22.2.2.2"]),
|
|
|
|
("patch", ["22.2.2", "22.2.2.2"]),
|
|
|
|
("head", ["head"]),
|
2022-03-30 22:15:01 +00:00
|
|
|
)
|
|
|
|
for case in cases:
|
2022-04-01 15:53:43 +00:00
|
|
|
release_type = case[0]
|
2022-03-30 22:15:01 +00:00
|
|
|
self.assertEqual(case[1], ds.gen_tags(version, release_type))
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError):
|
2022-04-01 15:53:43 +00:00
|
|
|
ds.gen_tags(version, "auto")
|
2022-03-30 22:15:01 +00:00
|
|
|
|
|
|
|
@patch("docker_server.get_tagged_versions")
|
2022-11-10 15:57:01 +00:00
|
|
|
def test_auto_release_type(self, mock_tagged_versions: MagicMock) -> None:
|
2022-03-30 22:15:01 +00:00
|
|
|
mock_tagged_versions.return_value = [
|
|
|
|
get_version_from_string("1.1.1.1"),
|
|
|
|
get_version_from_string("1.2.1.1"),
|
|
|
|
get_version_from_string("2.1.1.1"),
|
|
|
|
get_version_from_string("2.2.1.1"),
|
|
|
|
get_version_from_string("2.2.2.1"),
|
|
|
|
]
|
2022-04-06 16:41:18 +00:00
|
|
|
|
|
|
|
cases_less = (
|
2022-04-01 15:53:43 +00:00
|
|
|
(get_version_from_string("1.0.1.1"), "minor"),
|
|
|
|
(get_version_from_string("1.1.2.1"), "minor"),
|
|
|
|
(get_version_from_string("1.3.1.1"), "major"),
|
|
|
|
(get_version_from_string("2.1.2.1"), "minor"),
|
|
|
|
(get_version_from_string("2.2.1.3"), "patch"),
|
|
|
|
(get_version_from_string("2.2.3.1"), "latest"),
|
|
|
|
(get_version_from_string("2.3.1.1"), "latest"),
|
2022-03-30 22:15:01 +00:00
|
|
|
)
|
2022-04-06 16:41:18 +00:00
|
|
|
for case in cases_less:
|
|
|
|
release = ds.auto_release_type(case[0], "auto")
|
|
|
|
self.assertEqual(case[1], release)
|
|
|
|
|
|
|
|
cases_equal = (
|
|
|
|
(get_version_from_string("1.1.1.1"), "minor"),
|
|
|
|
(get_version_from_string("1.2.1.1"), "major"),
|
|
|
|
(get_version_from_string("2.1.1.1"), "minor"),
|
|
|
|
(get_version_from_string("2.2.1.1"), "patch"),
|
|
|
|
(get_version_from_string("2.2.2.1"), "latest"),
|
|
|
|
)
|
|
|
|
for case in cases_equal:
|
2022-03-30 22:15:01 +00:00
|
|
|
release = ds.auto_release_type(case[0], "auto")
|
|
|
|
self.assertEqual(case[1], release)
|