Files
OpenTofuPlayground/tests/docker_validation.tftest.hcl
Lutz Finsterle 3bf5960302
Some checks failed
Deploy / Update K8s Apps / Detect changed K8s tfvars (push) Failing after 13s
Deploy / Update Apps / Detect changed tfvars files (push) Failing after 13s
Test / Static Analysis (push) Failing after 11s
Test / Unit Tests — Docker Stack (push) Has been skipped
Test / Unit Tests — K8s Stack (push) Has been skipped
Deploy / Update K8s Apps / Deploy ${{ matrix.tfvars }} (push) Has been skipped
Deploy / Update K8s Apps / Destroy ${{ matrix.tfvars }} (push) Has been skipped
Deploy / Update Apps / Deploy ${{ matrix.tfvars }} (push) Has been skipped
Deploy / Update Apps / Destroy ${{ matrix.tfvars }} (push) Has been skipped
Test / Integration Test — K8s (k3d) (push) Has been skipped
Initial Commit
2026-03-06 19:17:15 +01:00

147 lines
4.1 KiB
HCL

# ─────────────────────────────────────────────────────────────────────────────
# Docker stack unit tests — run with: tofu test (from repo root)
# Requires OpenTofu >= 1.7.0 (mock_provider support)
#
# All providers are mocked — no real Docker host needed.
# Tests cover: variable validation, plan structure, source type modes.
# ─────────────────────────────────────────────────────────────────────────────
mock_provider "docker" {}
# ─── Shared baseline variables ────────────────────────────────────────────────
# Every run block below can override individual values.
variables {
ssh_host = "test-host.example.com"
ssh_user = "deploy"
ssh_key_path = "/tmp/test-key"
app_name = "testapp"
environment = "dev"
openresty_source_type = "bind_mount"
openresty_remote_config_path = "/opt/apps/testapp/openresty"
openresty_external_port = 8080
db_name = "testdb"
db_user = "testuser"
db_password = "test-secret"
}
# ─── Smoke tests: valid configurations plan without error ─────────────────────
run "valid_dev_bind_mount" {
command = plan
# Verifies the baseline dev/bind_mount config produces a valid plan.
}
run "valid_prod_bind_mount" {
command = plan
variables {
environment = "prod"
}
}
run "valid_git_clone_with_tag" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_repo = "https://gitea.example.com/org/myapp.git"
openresty_git_ref = "v2.1.0"
}
}
run "valid_git_clone_with_commit_sha" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_repo = "https://gitea.example.com/org/myapp.git"
openresty_git_ref = "a3f8c1d2e4b56789abcdef0123456789abcdef01"
}
}
run "valid_local_build" {
command = plan
variables {
openresty_source_type = "local_build"
openresty_local_build_context = "./openresty"
openresty_dockerfile = "Dockerfile"
}
}
# ─── Validation: git_ref must not be a mutable branch name ───────────────────
run "reject_git_ref_main" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_repo = "https://gitea.example.com/org/myapp.git"
openresty_git_ref = "main"
}
expect_failures = [var.openresty_git_ref]
}
run "reject_git_ref_master" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_ref = "master"
}
expect_failures = [var.openresty_git_ref]
}
run "reject_git_ref_develop" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_ref = "develop"
}
expect_failures = [var.openresty_git_ref]
}
run "reject_git_ref_HEAD" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_ref = "HEAD"
}
expect_failures = [var.openresty_git_ref]
}
run "reject_git_ref_latest" {
command = plan
variables {
openresty_source_type = "git_clone"
openresty_git_ref = "latest"
}
expect_failures = [var.openresty_git_ref]
}
# ─── Validation: environment must be 'prod' or 'dev' ─────────────────────────
run "reject_environment_staging" {
command = plan
variables {
environment = "staging"
}
expect_failures = [var.environment]
}
run "reject_environment_production" {
command = plan
variables {
environment = "production"
}
expect_failures = [var.environment]
}
# ─── Validation: openresty_source_type must be one of the three modes ─────────
run "reject_invalid_source_type" {
command = plan
variables {
openresty_source_type = "s3_bucket"
}
expect_failures = [var.openresty_source_type]
}