From 846b5a1cc5687622c5c08baba41eccd119044da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20T=C3=BCrkal?= Date: Tue, 7 May 2024 00:23:32 +0300 Subject: [PATCH] add new tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Furkan Türkal --- images/jitsucom-bulker/config/main.tf | 8 ++++ images/jitsucom-bulker/main.tf | 14 +++--- images/jitsucom-bulker/tests/log-checker.sh | 53 +++++++++++++++++++++ images/jitsucom-bulker/tests/main.tf | 32 ++++++++++++- 4 files changed, 98 insertions(+), 9 deletions(-) create mode 100755 images/jitsucom-bulker/tests/log-checker.sh diff --git a/images/jitsucom-bulker/config/main.tf b/images/jitsucom-bulker/config/main.tf index 48de99554a..5cb42a4e8f 100644 --- a/images/jitsucom-bulker/config/main.tf +++ b/images/jitsucom-bulker/config/main.tf @@ -20,5 +20,13 @@ output "config" { entrypoint = { command = "/app/${var.main_package}" } + paths = [{ + path = "~/.${var.main_package}" # https://github.com/jitsucom/bulker/blob/315237cd54707f2d9395db087ec2d4b2ed1297f4/jitsubase/appbase/app_base.go#L33 + type = "directory" + uid = module.accts.uid + gid = module.accts.gid + permissions = 509 + recursive = true + }] }) } diff --git a/images/jitsucom-bulker/main.tf b/images/jitsucom-bulker/main.tf index 7463ee5150..336f92a51a 100644 --- a/images/jitsucom-bulker/main.tf +++ b/images/jitsucom-bulker/main.tf @@ -30,7 +30,7 @@ module "latest" { name = basename(path.module) target_repository = local.repositories[each.key] config = module.config[each.key].config - # build-dev = true + build-dev = true } module "test" { @@ -46,10 +46,10 @@ resource "oci_tag" "latest" { depends_on = [module.test] } -# resource "oci_tag" "latest-dev" { -# for_each = local.components +resource "oci_tag" "latest-dev" { + for_each = local.components -# digest_ref = module.latest[each.key].dev_ref -# tag = "latest-dev" -# depends_on = [module.test] -# } + digest_ref = module.latest[each.key].dev_ref + tag = "latest-dev" + depends_on = [module.test] +} diff --git a/images/jitsucom-bulker/tests/log-checker.sh b/images/jitsucom-bulker/tests/log-checker.sh new file mode 100755 index 0000000000..14e695b054 --- /dev/null +++ b/images/jitsucom-bulker/tests/log-checker.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o errtrace -o pipefail -x + +# First argument: Kubernetes deployment name +K8S_NAME="$1" + +# Second argument: String of expected logs separated by '|' +input_logs="$2" + +# Split the input string into an array using '|' as delimiter +IFS='|' read -r -a expected_logs <<< "$input_logs" + +missing_logs=() + +RETRIES=5 +RETRY_DELAY_SECONDS=15 + +TEST_validate_container_logs() { + for ((i=1; i<=${RETRIES}; i++)); do + local logs=$(kubectl logs "deploy/${K8S_NAME}" -n "${K8S_NAMESPACE}" 2>&1) + local logs_found=true + + # Search the container logs for our expected log lines. + for log in "${expected_logs[@]}"; do + if ! echo "$logs" | grep -Fq "$log"; then + logs_found=false + fi + done + + if $logs_found; then + return 0 + elif [[ $i -lt ${RETRIES} ]]; then + echo "Some expected logs were missing. Retrying in ${RETRY_DELAY_SECONDS} seconds..." + sleep ${RETRY_DELAY_SECONDS} + fi + done + + # After all retries, record the missing logs + for log in "${expected_logs[@]}"; do + if ! echo "${logs}" | grep -Fq "$log"; then + missing_logs+=("${log}") + fi + done + + echo "FAILED: The following log lines where not found:" + printf '%s\n' "${missing_logs[@]}" + echo "Full logs:" + kubectl logs "deploy/${K8S_NAME}" -n "${K8S_NAMESPACE}" + exit 1 +} + +TEST_validate_container_logs diff --git a/images/jitsucom-bulker/tests/main.tf b/images/jitsucom-bulker/tests/main.tf index 3b3c37fdde..3a0400328b 100644 --- a/images/jitsucom-bulker/tests/main.tf +++ b/images/jitsucom-bulker/tests/main.tf @@ -19,6 +19,10 @@ data "oci_string" "ref" { input = each.value } +variable "namespace" { + default = "jitsucom-bulker" +} + data "imagetest_inventory" "this" {} resource "imagetest_harness_k3s" "this" { @@ -32,6 +36,9 @@ resource "imagetest_harness_k3s" "this" { destination = "/tests" } ] + envs = { + "K8S_NAMESPACE" = var.namespace + } } } @@ -39,7 +46,7 @@ module "helm" { source = "../../../tflib/imagetest/helm" name = "jitsucom-bulker" - namespace = "jitsucom-bulker" + namespace = var.namespace chart = "oci://registry-1.docker.io/stafftasticcharts/jitsu" values = { @@ -78,7 +85,28 @@ resource "imagetest_feature" "basic" { { name = "Helm install" cmd = module.helm.install_cmd - } + }, + { + name = "Test bulker" + cmd = <