Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
Signed-off-by: Furkan Türkal <furkan.turkal@chainguard.dev>
  • Loading branch information
Dentrax committed May 7, 2024
1 parent fb7e8b3 commit 5f1e223
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
8 changes: 8 additions & 0 deletions images/jitsucom-bulker/config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]
})
}
53 changes: 53 additions & 0 deletions images/jitsucom-bulker/tests/log-checker.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 30 additions & 2 deletions images/jitsucom-bulker/tests/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -32,14 +36,17 @@ resource "imagetest_harness_k3s" "this" {
destination = "/tests"
}
]
envs = {
"K8S_NAMESPACE" = var.namespace
}
}
}

module "helm" {
source = "../../../tflib/imagetest/helm"

name = "jitsucom-bulker"
namespace = "jitsucom-bulker"
namespace = var.namespace
chart = "oci://registry-1.docker.io/stafftasticcharts/jitsu"

values = {
Expand Down Expand Up @@ -78,7 +85,28 @@ resource "imagetest_feature" "basic" {
{
name = "Helm install"
cmd = module.helm.install_cmd
}
},
{
name = "Test bulker"
cmd = <<EOF
/tests/log-checker.sh "jitsucom-bulker-bulker" "[metrics_server] Starting metrics server|Starting http server|[topic-manager] Created topic: destination-messages"
EOF
retry = { attempts = 3, delay = "5s" }
},
{
name = "Test ingest"
cmd = <<EOF
/tests/log-checker.sh "jitsucom-bulker-ingest" "[metrics_server] Starting metrics server|Starting http server|[router] Data hosts"
EOF
retry = { attempts = 3, delay = "5s" }
},
{
name = "Test syncctl"
cmd = <<EOF
/tests/log-checker.sh "jitsucom-bulker-syncctl" "foo|bar"
EOF
retry = { attempts = 3, delay = "5s" }
},
]

labels = {
Expand Down

0 comments on commit 5f1e223

Please sign in to comment.