From 3c62528dd476fecd5512519d206e92f1ebb8f7c6 Mon Sep 17 00:00:00 2001 From: RouxAntoine Date: Wed, 29 May 2024 23:13:36 +0200 Subject: [PATCH] feature: add first unit test on application_name and replicas --- .terraform.lock.hcl | 40 ++++++++++++++++++++++++++++++++++++++++ main.tf | 1 + tests/main.tftest.hcl | 21 +++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 .terraform.lock.hcl create mode 100644 tests/main.tftest.hcl diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..19fe23d --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,40 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/kubernetes" { + version = "2.30.0" + hashes = [ + "h1:+Je5UPTWMmO4eG5ep1WfujkXQI9tDk0OsMU4olU76Bg=", + "zh:06531333a72fe6d2829f37a328e08a3fc4ed66226344a003b62418a834ac6c69", + "zh:34480263939ef5007ce65c9f4945df5cab363f91e5260ae552bcd9f2ffeed444", + "zh:59e71f9177da570c33507c44828288264c082d512138c5755800f2cd706c62bc", + "zh:6e979b0c07326f9c8d1999096a920322d22261ca61d346b3a9775283d00a2fa5", + "zh:73e3f228de0077b5c0a84ec5b1ada507fbb3456cba35a6b5758723f77715b7af", + "zh:79e0de985159c056f001cc47a654620d51f5d55f554bcbcde1fe7d52f667db40", + "zh:8accb9100f609377db42e3ced42cc9d5c36065a06644dfb21d3893bb8d4797fd", + "zh:9f99aa0bf5caa4223a7dbf5d22d71c16083e782c4eea4b0130abfd6e6f1cec18", + "zh:bcb2ad76ad05ec23f8da62231a2360d1f70bbcd28abd06b8458a9e2f17da7873", + "zh:bce317d7790c2d3c4e724726dc78070db28daf7d861faa646fc891fe28842a29", + "zh:ed0a8e7fa8a1c419a19840b421d18200c3a63cf16ccbcbc400cb375d5397f615", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/hashicorp/random" { + version = "3.6.2" + hashes = [ + "h1:VavG5unYCa3SYISMKF9pzc3718M0bhPlcbUZZGl7wuo=", + "zh:0ef01a4f81147b32c1bea3429974d4d104bbc4be2ba3cfa667031a8183ef88ec", + "zh:1bcd2d8161e89e39886119965ef0f37fcce2da9c1aca34263dd3002ba05fcb53", + "zh:37c75d15e9514556a5f4ed02e1548aaa95c0ecd6ff9af1119ac905144c70c114", + "zh:4210550a767226976bc7e57d988b9ce48f4411fa8a60cd74a6b246baf7589dad", + "zh:562007382520cd4baa7320f35e1370ffe84e46ed4e2071fdc7e4b1a9b1f8ae9b", + "zh:5efb9da90f665e43f22c2e13e0ce48e86cae2d960aaf1abf721b497f32025916", + "zh:6f71257a6b1218d02a573fc9bff0657410404fb2ef23bc66ae8cd968f98d5ff6", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:9647e18f221380a85f2f0ab387c68fdafd58af6193a932417299cdcae4710150", + "zh:bb6297ce412c3c2fa9fec726114e5e0508dd2638cad6a0cb433194930c97a544", + "zh:f83e925ed73ff8a5ef6e3608ad9225baa5376446349572c2449c0c0b3cf184b7", + "zh:fbef0781cb64de76b1df1ca11078aecba7800d82fd4a956302734999cfd9a4af", + ] +} diff --git a/main.tf b/main.tf index 2a4709e..98bbced 100644 --- a/main.tf +++ b/main.tf @@ -43,6 +43,7 @@ resource "kubernetes_deployment_v1" "deployment" { } } spec { + replicas = "1" selector { match_labels = { "app.kubernetes.io/name" = local.label_name diff --git a/tests/main.tftest.hcl b/tests/main.tftest.hcl new file mode 100644 index 0000000..54c11ba --- /dev/null +++ b/tests/main.tftest.hcl @@ -0,0 +1,21 @@ +run "terraform-plan" { + command = plan + + variables { + application_name = "test-application" + namespace = "test-namespace" + image = { + name = "container.localdomain/test-image" + } + } + + assert { + condition = var.application_name == "test-application" + error_message = "incorrect application name" + } + + assert { + condition = kubernetes_deployment_v1.deployment.spec[0].replicas == "1" + error_message = "invalid number of replicas" + } +}