add some tests
This commit is contained in:
parent
1ce070beac
commit
ea77c84948
2 changed files with 62 additions and 23 deletions
|
@ -5,17 +5,20 @@ from .common import (
|
|||
Devops,
|
||||
)
|
||||
|
||||
|
||||
class C4k(Validateable):
|
||||
def __init__(self, config: dict):
|
||||
tmp_executabel_name = config["C4kMixin"]["executabel_name"]
|
||||
if not tmp_executabel_name:
|
||||
tmp_executabel_name = config["module"]
|
||||
self.executabel_name = tmp_executabel_name
|
||||
self.c4k_mixin_config = config["C4kMixin"]["config"]
|
||||
self.c4k_mixin_auth = config["C4kMixin"]["auth"]
|
||||
tmp = self.c4k_mixin_config["mon-cfg"]
|
||||
tmp.update({"cluster-name": config["module"], "cluster-stage": config["stage"]})
|
||||
self.c4k_mixin_config.update({"mon-cfg": tmp})
|
||||
def __init__(self, input: dict):
|
||||
self.module = input.get("module")
|
||||
self.stage = input.get("stage")
|
||||
self.executabel_name = input.get("c4k_executabel_name", input.get("module"))
|
||||
self.c4k_config = input.get("c4k_config", {})
|
||||
self.grafana_cloud_url = input.get(
|
||||
"c4k_grafana_cloud_url",
|
||||
"https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
|
||||
)
|
||||
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
|
||||
|
||||
# TODO: these functions should be located at TerraformBuild later on.
|
||||
|
@ -24,19 +27,38 @@ class C4k(Validateable):
|
|||
|
||||
def validate(self) -> List[str]:
|
||||
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:
|
||||
result += self.dns_record.validate()
|
||||
return result
|
||||
|
||||
def config(self):
|
||||
fqdn = self.dns_record.fqdn
|
||||
self.c4k_mixin_config.update({"fqdn": fqdn})
|
||||
return self.c4k_mixin_config
|
||||
if not self.dns_record:
|
||||
raise ValueError("dns_reqord was not set.")
|
||||
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 command(self, build: Devops):
|
||||
module = build.module
|
||||
build_path = build.build_path()
|
||||
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, devops: Devops):
|
||||
module = devops.module
|
||||
build_path = devops.build_path()
|
||||
config_path = f"{build_path}/out_c4k_config.yaml"
|
||||
auth_path = f"{build_path}/out_c4k_auth.yaml"
|
||||
output_path = f"{build_path}/out_{module}.yaml"
|
||||
|
|
|
@ -9,18 +9,35 @@ def test_devops_factory():
|
|||
DevopsFactory().build_devops({"build_types": ["NOTEXISTING"]})
|
||||
|
||||
with pytest.raises(Exception):
|
||||
DevopsFactory().build_devops({'build_types': ['IMAGE'],})
|
||||
DevopsFactory().build_devops(
|
||||
{
|
||||
"build_types": ["IMAGE"],
|
||||
}
|
||||
)
|
||||
|
||||
sut = DevopsFactory().build_devops(
|
||||
{
|
||||
"build_types": ["IMAGE"],
|
||||
"stage": "test",
|
||||
"project_root_path": "../../..",
|
||||
"name": "mybuild",
|
||||
"module": "test_image",
|
||||
"dockerhub_user": "dockerhub_user",
|
||||
"dockerhub_password": "dockerhub_password",
|
||||
"docker_image_tag": "docker_image_tag",
|
||||
"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",
|
||||
"module": "test_image",
|
||||
"project_root_path": "../../..",
|
||||
"build_types": ["C4K"],
|
||||
"c4k_grafana_cloud_user": "user",
|
||||
"c4k_grafana_cloud_password": "password",
|
||||
}
|
||||
)
|
||||
assert sut != None
|
||||
|
|
Loading…
Reference in a new issue