Skip to content

Commit

Permalink
chore: add tests for ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminek committed Nov 28, 2023
1 parent f000411 commit bca394a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ingress.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "kubernetes_ingress_v1" "main" {
depends_on = [kubernetes_service.main]
depends_on = [kubernetes_deployment.main]
count = var.ingress_enabled ? 1 : 0
wait_for_load_balancer = var.wait_for_load_balancer
metadata {
Expand Down
51 changes: 51 additions & 0 deletions ingress.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
variables {
ingress_enabled = true
service_enabled = false
app_name = "some-app"
namespace = "some-namespace"
app_docker_image = "busybox"
readiness_probe_enabled = false
liveness_probe_enabled = false
hosts = ["some-app.example.com", "some-app-2.example.com"]
tls_hosts = ["some-app.example.com", "*.example.com"]
}

run "it deploys ingress for app in k8s" {
command = plan

assert {
condition = kubernetes_ingress_v1.main[0].metadata[0].name == "some-app"

error_message = "Ingress name is not correct"
}
assert {
condition = kubernetes_ingress_v1.main[0].metadata[0].namespace == "some-namespace"

error_message = "Ingress namespace is not correct"
}
assert {
condition = kubernetes_ingress_v1.main[0].spec[0].tls[0].hosts[0] == "*.example.com"

error_message = "Ingress tls hosts are not correct"
}
assert {
condition = kubernetes_ingress_v1.main[0].spec[0].tls[0].hosts[1] == "some-app.example.com"

error_message = "Ingress tls hosts are not correct"
}
assert {
condition = kubernetes_ingress_v1.main[0].spec[0].rule[0].host == "some-app-2.example.com"

error_message = "Ingress hosts are not correct"
}
assert {
condition = kubernetes_ingress_v1.main[0].spec[0].rule[1].host == "some-app.example.com"

error_message = "Ingress hosts are not correct"
}
assert {
condition = kubernetes_ingress_v1.main[0].spec[0].tls[0].secret_name == "some-app-tls"

error_message = "Ingress tls secret name is not correct"
}
}

0 comments on commit bca394a

Please sign in to comment.