add some tests
This commit is contained in:
parent
eb5be21824
commit
6b1ffb6e99
3 changed files with 35 additions and 0 deletions
|
@ -12,6 +12,7 @@ classDiagram
|
|||
}
|
||||
|
||||
class Image {
|
||||
image_naming
|
||||
image_dockerhub_user
|
||||
image_dockerhub_password
|
||||
image_publish_tag
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from enum import Enum
|
||||
from typing import List, Dict
|
||||
from .common import (
|
||||
filter_none,
|
||||
|
@ -5,15 +6,23 @@ from .common import (
|
|||
)
|
||||
|
||||
|
||||
class NamingType(Enum):
|
||||
NAME_ONLY = 1
|
||||
NAME_AND_MODULE = 2
|
||||
|
||||
|
||||
class Image(Validateable):
|
||||
def __init__(
|
||||
self,
|
||||
inp: dict,
|
||||
):
|
||||
self.module = inp.get("module")
|
||||
self.name = inp.get("name")
|
||||
self.image_dockerhub_user = inp.get("image_dockerhub_user")
|
||||
self.image_dockerhub_password = inp.get("image_dockerhub_password")
|
||||
self.image_tag = inp.get("image_tag")
|
||||
self.image_build_commons_path = inp.get("image_build_commons_path")
|
||||
self.image_naming = NamingType[inp.get("image_naming", "NAME_ONLY")]
|
||||
self.image_use_package_common_files = inp.get(
|
||||
"image_use_package_common_files", True
|
||||
)
|
||||
|
@ -23,8 +32,10 @@ class Image(Validateable):
|
|||
|
||||
def validate(self) -> List[str]:
|
||||
result = []
|
||||
result += self.__validate_is_not_empty__("name")
|
||||
result += self.__validate_is_not_empty__("image_dockerhub_user")
|
||||
result += self.__validate_is_not_empty__("image_dockerhub_password")
|
||||
result += self.__validate_is_not_empty__("image_naming")
|
||||
if not self.image_use_package_common_files:
|
||||
result += self.__validate_is_not_empty__("image_build_commons_path")
|
||||
result += self.__validate_is_not_empty__("image_build_commons_dir_name")
|
||||
|
@ -37,6 +48,16 @@ class Image(Validateable):
|
|||
]
|
||||
return "/".join(filter_none(commons_path)) + "/"
|
||||
|
||||
def image_name(self) -> str:
|
||||
result: List[str] = [self.name] # type: ignore
|
||||
if (
|
||||
self.image_naming == NamingType.NAME_AND_MODULE
|
||||
and self.module
|
||||
and self.module != ""
|
||||
):
|
||||
result.append(self.module)
|
||||
return "-".join(result)
|
||||
|
||||
@classmethod
|
||||
def get_mapping_default(cls) -> List[Dict[str, str]]:
|
||||
return [
|
||||
|
|
|
@ -12,3 +12,16 @@ def test_devops_build_commons_path():
|
|||
assert image is not None
|
||||
assert image.is_valid()
|
||||
assert "docker/" == image.build_commons_path()
|
||||
|
||||
def test_should_calculate_image_name():
|
||||
sut = build_devops({})
|
||||
image = sut.specialized_builds[BuildType.IMAGE]
|
||||
assert "name" == image.image_name()
|
||||
|
||||
sut = build_devops({'image_naming': "NAME_ONLY"})
|
||||
image = sut.specialized_builds[BuildType.IMAGE]
|
||||
assert "name" == image.image_name()
|
||||
|
||||
sut = build_devops({'image_naming': "NAME_AND_MODULE"})
|
||||
image = sut.specialized_builds[BuildType.IMAGE]
|
||||
assert "name-module" == image.image_name()
|
||||
|
|
Loading…
Reference in a new issue