diff --git a/src/test/python/domain/helper.py b/src/test/python/domain/helper.py index 413d06c..bef79d7 100644 --- a/src/test/python/domain/helper.py +++ b/src/test/python/domain/helper.py @@ -24,7 +24,7 @@ def devops_config(overrides: dict) -> dict: "k3s_letsencrypt_endpoint": "k3s_letsencrypt_endpoint", "k3s_enable_echo": "false", "k3s_app_filename_to_provision": "k3s_app.yaml", - "tf_provider_types": ["DIGITALOCEAN", "HETZNER", "AWS"], + "tf_provider_types": ["DIGITALOCEAN", "HETZNER", "AWS", "TERRAFORM_BACKEND_GIT"], "tf_additional_vars": [], "tf_output_json_name": "the_out.json", "tf_use_workspace": None, @@ -58,6 +58,11 @@ def devops_config(overrides: dict) -> dict: "release_artifact_server_url": None, "release_organisation": None, "release_repository_name": None, + "git_backend_repo": "https://repo.example.com/meissa/infra-states", + "git_backend_ref": "main", + "git_backend_state": "test.json", + "git_backend_username": "tf_backend_user", + "git_backend_token": "324asd234df435sfdgh", "credentials_mappings": [ { "gopass_path": "a/path", diff --git a/src/test/python/domain/test_provider_tf_backend_git.py b/src/test/python/domain/test_provider_tf_backend_git.py new file mode 100644 index 0000000..5e42d22 --- /dev/null +++ b/src/test/python/domain/test_provider_tf_backend_git.py @@ -0,0 +1,30 @@ +from pybuilder.core import Project +from pathlib import Path +from src.main.python.ddadevops.domain import ( + BuildType, + TerraformBackendGit, +) +from .helper import devops_config + +def test_tf_backend_git_creation(): + sut = TerraformBackendGit( + { + "module": "module", + "stage": "test", + "git_backend_repo": "https://repo.example.com/meissa/infra-states", + "git_backend_ref": "main", + "git_backend_state": "test.json", + "git_backend_username": "tf_backend_user", + "git_backend_token": "324asd234df435sfdgh", + } + ) + assert sut is not None + assert sut.is_valid() + +def test_should_calculate_backend_config(): + sut = TerraformBackendGit(devops_config({})) + assert { + "address": "http://localhost:6061/?type=git&repository=https://repo.example.com/meissa/infra-states&ref=main&state=test/module/test.json", + "lock_address": "http://localhost:6061/?type=git&repository=https://repo.example.com/meissa/infra-states&ref=main&state=test/module/test.json", + "unlock_address": "http://localhost:6061/?type=git&repository=https://repo.example.com/meissa/infra-states&ref=main&state=test/module/test.json", + } == sut.backend_config() \ No newline at end of file diff --git a/src/test/python/domain/test_terraform.py b/src/test/python/domain/test_terraform.py index d93773d..b67486f 100644 --- a/src/test/python/domain/test_terraform.py +++ b/src/test/python/domain/test_terraform.py @@ -17,6 +17,7 @@ def test_creation(): assert sut.providers[ProviderType.DIGITALOCEAN] assert sut.providers[ProviderType.HETZNER] assert sut.providers[ProviderType.AWS] + assert sut.providers[ProviderType.TERRAFORM_BACKEND_GIT] def test_should_calculate_output_json_name(): @@ -188,3 +189,7 @@ def test_should_calculate_local_state_handling(): ) ) assert not sut.is_local_state() + +def test_should_use_backend_git(): + sut = TerraformDomain(devops_config({})) + assert TerraformDomain.uses_backend_git() \ No newline at end of file