diff --git a/vkpr-test/loki-test.bats b/vkpr-test/loki-test.bats new file mode 100644 index 00000000..82eb4e67 --- /dev/null +++ b/vkpr-test/loki-test.bats @@ -0,0 +1,37 @@ +VKPR_HOME=~/.vkpr +setup_file() { + load 'common-setup' + _common_setup + if [ "$VKPR_TEST_SKIP_SETUP" == "true" ]; then + echo "setup: skipping setup due to VKPR_TEST_SKIP_SETUP=true" >&3 + else + echo "setup: installing loki...." >&3 + rit vkpr loki install + kubectl wait --for=condition=ready --timeout=1m pod --all + sleep 2 + fi +} + +setup() { + load $VKPR_HOME/bats/bats-support/load.bash + load $VKPR_HOME/bats/bats-assert/load.bash +} + +@test "curl to Loki must return ready" { + run echo "$(kubectl run --wait --timeout 1m curl-test --image=radial/busyboxplus:curl -i --rm --restart=Never --command -- curl -s -H "Content-Type: application/json" http://vkpr-loki-stack:3100/ready)" + actual="${lines[0]}" + trim "$actual" + actual="$TRIMMED" + expected="ready" + assert_equal "$actual" "$expected" + +} + +trim() { + local var="$*" + # remove leading whitespace characters + var="${var#"${var%%[![:space:]]*}"}" + # remove trailing whitespace characters + var="${var%"${var##*[![:space:]]}"}" + TRIMMED="$var" +} \ No newline at end of file diff --git a/vkpr/loki/install/src/unix/formula/formula.sh b/vkpr/loki/install/src/unix/formula/formula.sh index 0f0b3908..46365c21 100755 --- a/vkpr/loki/install/src/unix/formula/formula.sh +++ b/vkpr/loki/install/src/unix/formula/formula.sh @@ -20,7 +20,7 @@ addRepLoki(){ existGrafana(){ check_pod_name "vkpr-prometheus-stack-grafana" - if [[ $POD_EXISTS ]]; then + if [[ $POD_EXISTS == true ]]; then echoColor "yellow" "Adding Loki to Grafana's datasource..." local LOGINGRAFANA="$($VKPR_KUBECTL get secret vkpr-prometheus-stack-grafana -o yaml | $VKPR_YQ eval '.data.admin-user' - | base64 -d):$($VKPR_KUBECTL get secret vkpr-prometheus-stack-grafana -o yaml | $VKPR_YQ eval '.data.admin-password' - | base64 -d)" local TOKEN_API_GRAFANA=$(curl -k -X POST -H "Host: grafana.localhost" -H "Content-Type: application/json" -d '{"name": "apikeycurl","role": "Admin"}' http://$LOGINGRAFANA@127.0.0.1:8000/api/auth/keys | $VKPR_JQ --raw-output '.key')