Skip to content

Commit

Permalink
Make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Nov 9, 2021
1 parent a46833a commit 4acbad3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ci/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ find . ! -path '*deploy/helm/sumologic/conf/setup/setup.sh' ! -path "*/tmp/*" -n
while read -r file; do
# Run tests in their own context
echo "Checking ${file} with shellcheck"
shellcheck --enable all "${file}"
shellcheck --enable all --external-sources --exclude SC2155 "${file}"
done
4 changes: 4 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ file name, e.g. for `deploy/helm/sumologic/templates/configmap.yaml` it will be
TEST_TEMPLATE="templates/configmap.yaml"
```

There's also a shared config file: `shared_config.sh` which will be sourced for
all tests with particular tests `config.sh`s taking precedence (as they will be
sourced later).

## Input file

Input file e.g. `test_name.input.yaml` should be compatible with `values.yaml`
Expand Down
20 changes: 15 additions & 5 deletions tests/functions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2154,SC2086


TEST_TEMPLATE="${TEST_TEMPLATE:-}"
Expand Down Expand Up @@ -68,11 +69,12 @@ function patch_test() {
function generate_file {
local template_name="${1}"
local kube_api_versions_flags=""
if (( ${#KUBE_API_VERSIONS[@]} )); then
kube_api_versions_flags=${KUBE_API_VERSIONS[@]/#/--api-versions }
# shellcheck disable=SC2154
if (( ${#KUBE_API_VERSIONS[*]} )); then
kube_api_versions_flags=${KUBE_API_VERSIONS[*]/#/--api-versions }
fi

docker run --rm \
if ! docker run --rm \
-v "${TEST_SCRIPT_PATH}/../../deploy/helm/sumologic":/chart \
-v "${TEST_STATICS_PATH}/${input_file}":/values.yaml \
sumologic/kubernetes-tools:2.4.1 \
Expand All @@ -81,7 +83,12 @@ function generate_file {
--namespace sumologic \
--set sumologic.accessId='accessId' \
--set sumologic.accessKey='accessKey' \
-s "${template_name}" 2>/dev/null 1> "${TEST_OUT}"
-s "${template_name}" 1> "${TEST_OUT}" ; then
echo "Error with template ${template_name} in ${TEST_STATICS_PATH}/${input_file}"
return 1
fi

return 0
}

# Run test
Expand All @@ -95,7 +102,10 @@ function perform_test {
patch_test "${TEST_STATICS_PATH}/${output_file}" "${TEST_TMP_PATH}/${output_file}"

test_start "${test_name}"
generate_file "${template_name}"
if ! generate_file "${template_name}"; then
test_failed "${test_name}"
return
fi

test_output=$(diff -c "${TEST_TMP_PATH}/${output_file}" "${TEST_OUT}" | cat -te)
rm "${TEST_OUT}"
Expand Down
1 change: 0 additions & 1 deletion tests/metadata_logs_otc/config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash

export TEST_TEMPLATE="templates/logs/otelcol/configmap.yaml"
export KUBE_API_VERSIONS=("policy/v1/PodDisruptionBudget")
26 changes: 17 additions & 9 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ source "${SCRIPT_PATH}/functions.sh"

export TEST_SUCCESS=true

prepare_environment "${SCRIPT_PATH}/../deploy/helm/sumologic"
# prepare_environment "${SCRIPT_PATH}/../deploy/helm/sumologic"

if [[ -f "${SCRIPT_PATH}/shared_config.sh" ]] ; then
echo "Sourcing ${SCRIPT_PATH}/shared_config.sh for all tests envs"
source "${SCRIPT_PATH}/shared_config.sh"
fi

for config_file in ${CONFIG_FILES}; do
test_dir="$( dirname "$(realpath "${config_file}")" )"
echo "Performing tests for $(basename "${test_dir}")"
# shellcheck disable=SC1090
source "${config_file}"
set_variables "${test_dir}"
prepare_tests
perform_tests
cleanup_tests
# add a subshell to not inherit previous tests' envs
(
test_dir="$( dirname "$(realpath "${config_file}")" )"
echo "Performing tests for $(basename "${test_dir}")"
# shellcheck disable=SC1090
source "${config_file}"
set_variables "${test_dir}"
prepare_tests
perform_tests
cleanup_tests
)
done

if [[ "${TEST_SUCCESS}" = "true" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions tests/shared_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

export KUBE_API_VERSIONS=("policy/v1/PodDisruptionBudget")

0 comments on commit 4acbad3

Please sign in to comment.