add some tests

merge-requests/12/head
Michael Jerger 1 year ago
parent 1ce070beac
commit ea77c84948

@ -5,17 +5,20 @@ from .common import (
Devops, Devops,
) )
class C4k(Validateable): class C4k(Validateable):
def __init__(self, config: dict): def __init__(self, input: dict):
tmp_executabel_name = config["C4kMixin"]["executabel_name"] self.module = input.get("module")
if not tmp_executabel_name: self.stage = input.get("stage")
tmp_executabel_name = config["module"] self.executabel_name = input.get("c4k_executabel_name", input.get("module"))
self.executabel_name = tmp_executabel_name self.c4k_config = input.get("c4k_config", {})
self.c4k_mixin_config = config["C4kMixin"]["config"] self.grafana_cloud_url = input.get(
self.c4k_mixin_auth = config["C4kMixin"]["auth"] "c4k_grafana_cloud_url",
tmp = self.c4k_mixin_config["mon-cfg"] "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
tmp.update({"cluster-name": config["module"], "cluster-stage": config["stage"]}) )
self.c4k_mixin_config.update({"mon-cfg": tmp}) self.c4k_auth = input.get("c4k_auth", {})
self.grafana_cloud_user = input.get('c4k_grafana_cloud_user')
self.grafana_cloud_password = input.get('c4k_grafana_cloud_password')
self.dns_record: Optional[DnsRecord] = None self.dns_record: Optional[DnsRecord] = None
# TODO: these functions should be located at TerraformBuild later on. # TODO: these functions should be located at TerraformBuild later on.
@ -24,19 +27,38 @@ class C4k(Validateable):
def validate(self) -> List[str]: def validate(self) -> List[str]:
result = [] result = []
result += self.__validate_is_not_empty__("fqdn") result += self.__validate_is_not_empty__("module")
result += self.__validate_is_not_empty__("stage")
result += self.__validate_is_not_empty__("executabel_name")
result += self.__validate_is_not_empty__("grafana_cloud_user")
result += self.__validate_is_not_empty__("grafana_cloud_password")
if self.dns_record: if self.dns_record:
result += self.dns_record.validate() result += self.dns_record.validate()
return result return result
def config(self): def config(self):
fqdn = self.dns_record.fqdn if not self.dns_record:
self.c4k_mixin_config.update({"fqdn": fqdn}) raise ValueError("dns_reqord was not set.")
return self.c4k_mixin_config result = self.c4k_config.copy()
result["fqdn"] = self.dns_record.fqdn
result["mon-cfg"] = {
"cluster-name": self.module,
"cluster-stage": self.stage,
"grafana-cloud-url": self.grafana_cloud_url,
}
return result
def auth(self):
result = self.c4k_auth.copy()
result["mon-auth"] = {
"grafana-cloud-user": self.grafana_cloud_user,
"grafana-cloud-password": self.grafana_cloud_password,
}
return result
def command(self, build: Devops): def command(self, devops: Devops):
module = build.module module = devops.module
build_path = build.build_path() build_path = devops.build_path()
config_path = f"{build_path}/out_c4k_config.yaml" config_path = f"{build_path}/out_c4k_config.yaml"
auth_path = f"{build_path}/out_c4k_auth.yaml" auth_path = f"{build_path}/out_c4k_auth.yaml"
output_path = f"{build_path}/out_{module}.yaml" output_path = f"{build_path}/out_{module}.yaml"

@ -9,18 +9,35 @@ def test_devops_factory():
DevopsFactory().build_devops({"build_types": ["NOTEXISTING"]}) DevopsFactory().build_devops({"build_types": ["NOTEXISTING"]})
with pytest.raises(Exception): with pytest.raises(Exception):
DevopsFactory().build_devops({'build_types': ['IMAGE'],}) DevopsFactory().build_devops(
{
"build_types": ["IMAGE"],
}
)
sut = DevopsFactory().build_devops( sut = DevopsFactory().build_devops(
{ {
"build_types": ["IMAGE"],
"stage": "test", "stage": "test",
"name": "mybuild",
"module": "test_image",
"project_root_path": "../../..", "project_root_path": "../../..",
"build_types": ["IMAGE"],
"image_dockerhub_user": "dockerhub_user",
"image_dockerhub_password": "dockerhub_password",
"image_tag": "docker_image_tag",
}
)
assert sut != None
sut = DevopsFactory().build_devops(
{
"stage": "test",
"name": "mybuild", "name": "mybuild",
"module": "test_image", "module": "test_image",
"dockerhub_user": "dockerhub_user", "project_root_path": "../../..",
"dockerhub_password": "dockerhub_password", "build_types": ["C4K"],
"docker_image_tag": "docker_image_tag", "c4k_grafana_cloud_user": "user",
"c4k_grafana_cloud_password": "password",
} }
) )
assert sut != None assert sut != None

Loading…
Cancel
Save