2023-03-05 12:01:17 +00:00
|
|
|
from pybuilder.core import Project
|
2023-03-14 11:04:52 +00:00
|
|
|
from src.main.python.ddadevops.domain import Validateable, DnsRecord, C4kBuild, Devops
|
2023-03-05 12:01:17 +00:00
|
|
|
from src.main.python.ddadevops.c4k_mixin import add_c4k_mixin_config
|
|
|
|
|
|
|
|
|
|
|
|
class TestValidateable(Validateable):
|
|
|
|
def __init__(self, value):
|
|
|
|
self.field = value
|
|
|
|
|
|
|
|
def validate(self):
|
|
|
|
return self.__validate_is_not_empty__("field")
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_validate_non_empty_strings():
|
|
|
|
sut = TestValidateable("content")
|
|
|
|
assert sut.is_valid()
|
|
|
|
|
|
|
|
sut = TestValidateable(None)
|
|
|
|
assert not sut.is_valid()
|
|
|
|
|
|
|
|
sut = TestValidateable("")
|
|
|
|
assert not sut.is_valid()
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_validate_non_empty_others():
|
|
|
|
sut = TestValidateable(1)
|
|
|
|
assert sut.is_valid()
|
|
|
|
|
|
|
|
sut = TestValidateable(1.0)
|
|
|
|
assert sut.is_valid()
|
|
|
|
|
|
|
|
sut = TestValidateable(True)
|
|
|
|
assert sut.is_valid()
|
|
|
|
|
|
|
|
sut = TestValidateable(None)
|
|
|
|
assert not sut.is_valid()
|
|
|
|
|
|
|
|
|
|
|
|
def test_validate_with_reason():
|
|
|
|
sut = TestValidateable(None)
|
|
|
|
assert sut.validate()[0] == "Field 'field' may not be empty."
|
|
|
|
|
|
|
|
|
2023-03-12 18:09:32 +00:00
|
|
|
def test_should_validate_DnsRecord():
|
|
|
|
sut = DnsRecord(None)
|
|
|
|
assert not sut.is_valid()
|
|
|
|
|
|
|
|
sut = DnsRecord('name')
|
|
|
|
assert not sut.is_valid()
|
|
|
|
|
|
|
|
sut = DnsRecord('name', ipv4='1.2.3.4')
|
|
|
|
assert sut.is_valid()
|
|
|
|
|
|
|
|
sut = DnsRecord('name', ipv6='1::')
|
|
|
|
assert sut.is_valid()
|
|
|
|
|
|
|
|
|
2023-03-05 12:01:17 +00:00
|
|
|
def test_c4k_build_should_update_fqdn(tmp_path):
|
2023-03-12 16:40:10 +00:00
|
|
|
project = Project(str(tmp_path), name="name")
|
2023-03-05 12:01:17 +00:00
|
|
|
project_config = {
|
|
|
|
"stage": "test",
|
2023-03-12 16:40:10 +00:00
|
|
|
"name": "name",
|
2023-03-05 12:01:17 +00:00
|
|
|
"project_root_path": str(tmp_path),
|
2023-03-11 16:16:49 +00:00
|
|
|
"module": "module",
|
2023-03-05 12:01:17 +00:00
|
|
|
"build_dir_name": "target",
|
|
|
|
}
|
|
|
|
config = {"issuer": "staging"}
|
|
|
|
auth = {
|
|
|
|
"jvb-auth-password": "pw1",
|
|
|
|
"jicofo-auth-password": "pw2",
|
|
|
|
"jicofo-component-secret": "pw3",
|
|
|
|
}
|
|
|
|
add_c4k_mixin_config(
|
|
|
|
project_config,
|
|
|
|
config,
|
|
|
|
auth,
|
|
|
|
grafana_cloud_user="user",
|
|
|
|
grafana_cloud_password="password",
|
|
|
|
)
|
2023-03-14 11:04:52 +00:00
|
|
|
build = Devops(project_config)
|
2023-03-12 18:09:32 +00:00
|
|
|
sut = C4kBuild(project_config)
|
|
|
|
sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
|
2023-03-05 12:01:17 +00:00
|
|
|
|
|
|
|
assert {
|
|
|
|
"issuer": "staging",
|
2023-03-11 16:16:49 +00:00
|
|
|
"fqdn": "test.de",
|
2023-03-05 12:01:17 +00:00
|
|
|
"mon-cfg": {
|
2023-03-05 12:09:46 +00:00
|
|
|
"cluster-name": "module",
|
2023-03-05 12:01:17 +00:00
|
|
|
"cluster-stage": "test",
|
|
|
|
"grafana-cloud-url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
|
|
|
|
},
|
2023-03-05 12:39:47 +00:00
|
|
|
} == sut.config()
|
2023-03-11 16:16:49 +00:00
|
|
|
assert {
|
|
|
|
"jicofo-auth-password": "pw2",
|
|
|
|
"jicofo-component-secret": "pw3",
|
|
|
|
"jvb-auth-password": "pw1",
|
|
|
|
"mon-auth": {
|
|
|
|
"grafana-cloud-password": "password",
|
|
|
|
"grafana-cloud-user": "user",
|
|
|
|
},
|
|
|
|
} == sut.c4k_mixin_auth
|
2023-03-05 12:01:17 +00:00
|
|
|
|
2023-03-11 16:16:49 +00:00
|
|
|
|
|
|
|
def test_c4k_build_should_calculate_command(tmp_path):
|
2023-03-12 16:40:10 +00:00
|
|
|
project = Project(str(tmp_path), name="name")
|
2023-03-11 16:16:49 +00:00
|
|
|
project_config = {
|
|
|
|
"stage": "test",
|
2023-03-12 16:40:10 +00:00
|
|
|
"name": "name",
|
2023-03-11 16:16:49 +00:00
|
|
|
"project_root_path": "",
|
|
|
|
"module": "module",
|
|
|
|
"build_dir_name": "target",
|
|
|
|
}
|
|
|
|
add_c4k_mixin_config(
|
|
|
|
project_config,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
grafana_cloud_user="user",
|
|
|
|
grafana_cloud_password="password",
|
|
|
|
)
|
2023-03-14 11:04:52 +00:00
|
|
|
build = Devops(project_config)
|
2023-03-12 18:09:32 +00:00
|
|
|
sut = C4kBuild(project_config)
|
2023-03-11 16:16:49 +00:00
|
|
|
assert (
|
|
|
|
"c4k-module-standalone.jar "
|
2023-03-12 16:40:10 +00:00
|
|
|
+ "/target/name/module/out_c4k_config.yaml "
|
|
|
|
+ "/target/name/module/out_c4k_auth.yaml > "
|
|
|
|
+ "/target/name/module/out_module.yaml"
|
2023-03-12 18:09:32 +00:00
|
|
|
== sut.command(build)
|
2023-03-11 16:16:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
project_config = {
|
|
|
|
"stage": "test",
|
2023-03-12 16:40:10 +00:00
|
|
|
"name": "name",
|
2023-03-11 16:16:49 +00:00
|
|
|
"project_root_path": "",
|
|
|
|
"module": "module",
|
|
|
|
"build_dir_name": "target",
|
|
|
|
}
|
|
|
|
add_c4k_mixin_config(
|
|
|
|
project_config,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
executabel_name = "executabel_name",
|
|
|
|
grafana_cloud_user="user",
|
|
|
|
grafana_cloud_password="password",
|
|
|
|
)
|
2023-03-14 11:04:52 +00:00
|
|
|
build = Devops(project_config)
|
2023-03-12 18:09:32 +00:00
|
|
|
sut = C4kBuild(project_config)
|
2023-03-11 16:16:49 +00:00
|
|
|
assert (
|
|
|
|
"c4k-executabel_name-standalone.jar "
|
2023-03-12 16:40:10 +00:00
|
|
|
+ "/target/name/module/out_c4k_config.yaml "
|
|
|
|
+ "/target/name/module/out_c4k_auth.yaml > "
|
|
|
|
+ "/target/name/module/out_module.yaml"
|
2023-03-12 18:09:32 +00:00
|
|
|
== sut.command(build)
|
2023-03-11 16:16:49 +00:00
|
|
|
)
|
|
|
|
|