121 lines
3.5 KiB
HCL
121 lines
3.5 KiB
HCL
# ─────────────────────────────────────────────────────────────────────────────
|
|
# K8s stack unit tests — run with: tofu test (from k8s/ directory)
|
|
# Requires OpenTofu >= 1.7.0 (mock_provider support)
|
|
#
|
|
# Both providers are mocked — no real Kubernetes cluster needed.
|
|
# Tests cover: variable validation, plan with/without RabbitMQ, Traefik API group.
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
mock_provider "kubernetes" {}
|
|
|
|
mock_provider "kubectl" {}
|
|
|
|
# ─── Shared baseline variables ────────────────────────────────────────────────
|
|
|
|
variables {
|
|
kubeconfig_path = "/tmp/test-kubeconfig"
|
|
|
|
app_name = "testapp"
|
|
environment = "dev"
|
|
|
|
app_image = "nodered/node-red:3.1.9"
|
|
app_port = 1880
|
|
init_container_image = "gitea.example.com/org/testapp-init:v1.0.0"
|
|
|
|
app_path_prefix = "/testapp"
|
|
loki_endpoint = "http://loki.monitoring.svc:3100/loki/api/v1/push"
|
|
}
|
|
|
|
# ─── Smoke tests: valid configurations plan without error ─────────────────────
|
|
|
|
run "valid_minimal_no_rabbitmq" {
|
|
command = plan
|
|
# Baseline: no RabbitMQ, default storage class, no Loki auth
|
|
}
|
|
|
|
run "valid_with_rabbitmq" {
|
|
command = plan
|
|
variables {
|
|
enable_rabbitmq = true
|
|
rabbitmq_user = "testapp"
|
|
rabbitmq_password = "rabbit-secret"
|
|
rabbitmq_vhost = "testapp"
|
|
}
|
|
}
|
|
|
|
run "valid_prod_environment" {
|
|
command = plan
|
|
variables {
|
|
environment = "prod"
|
|
enable_rabbitmq = true
|
|
rabbitmq_password = "rabbit-secret"
|
|
}
|
|
}
|
|
|
|
run "valid_with_loki_auth" {
|
|
command = plan
|
|
variables {
|
|
loki_auth_token = "glc_supersecrettoken"
|
|
}
|
|
}
|
|
|
|
run "valid_custom_storage_class" {
|
|
command = plan
|
|
variables {
|
|
storage_class = "longhorn"
|
|
app_pvc_size = "5Gi"
|
|
}
|
|
}
|
|
|
|
run "valid_websecure_entrypoint" {
|
|
command = plan
|
|
variables {
|
|
traefik_entrypoint = "websecure"
|
|
}
|
|
}
|
|
|
|
# ─── Traefik API group: both supported values plan without error ───────────────
|
|
|
|
run "valid_traefik_api_group_new" {
|
|
command = plan
|
|
variables {
|
|
traefik_api_group = "traefik.io/v1alpha1"
|
|
}
|
|
}
|
|
|
|
run "valid_traefik_api_group_legacy" {
|
|
command = plan
|
|
variables {
|
|
traefik_api_group = "traefik.containo.us/v1alpha1"
|
|
}
|
|
}
|
|
|
|
# ─── Output assertions ────────────────────────────────────────────────────────
|
|
|
|
run "rabbitmq_amqp_url_empty_when_disabled" {
|
|
command = plan
|
|
variables {
|
|
enable_rabbitmq = false
|
|
}
|
|
assert {
|
|
condition = output.rabbitmq_amqp_url == ""
|
|
error_message = "AMQP URL should be empty string when RabbitMQ is disabled."
|
|
}
|
|
}
|
|
|
|
run "namespace_matches_app_name" {
|
|
command = plan
|
|
assert {
|
|
condition = output.namespace == var.app_name
|
|
error_message = "Namespace should equal app_name."
|
|
}
|
|
}
|
|
|
|
run "app_url_path_matches_prefix" {
|
|
command = plan
|
|
assert {
|
|
condition = output.app_url_path == var.app_path_prefix
|
|
error_message = "app_url_path output should match app_path_prefix variable."
|
|
}
|
|
}
|