diff --git a/bash/against-each-pod b/bash/against-each-pod index 660c673..5c99ac5 100755 --- a/bash/against-each-pod +++ b/bash/against-each-pod @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/annotations.sh b/bash/annotations.sh index b2d14bc..8311a71 100644 --- a/bash/annotations.sh +++ b/bash/annotations.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/aws-get-kubeconfigs b/bash/aws-get-kubeconfigs index bb719bd..ae850b1 100755 --- a/bash/aws-get-kubeconfigs +++ b/bash/aws-get-kubeconfigs @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/aws.sh b/bash/aws.sh index bd20290..d4b0a88 100644 --- a/bash/aws.sh +++ b/bash/aws.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/bashadoc b/bash/bashadoc index 14f01e6..463e81d 100755 --- a/bash/bashadoc +++ b/bash/bashadoc @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -44,8 +44,9 @@ else fi echo "# $title package" for func in $funcs; do - docs=$(declare -f "$func" | grep "^\s*@doc " | sed -e 's/^\s*@doc\ *//') - args=$(declare -f "$func" | grep "^\s*@arg " | sed -e 's/^\s*@arg\ */- /') + # Use [[:space:]] (POSIX) instead of \s — BSD grep does not treat \s as whitespace. + docs=$(declare -f "$func" | grep '^[[:space:]]*@doc ' | sed -e 's/^[[:space:]]*@doc[[:space:]]*//') + args=$(declare -f "$func" | grep '^[[:space:]]*@arg ' | sed -e 's/^[[:space:]]*@arg[[:space:]]*/- /') echo echo "## \`$func\`" echo diff --git a/bash/bb b/bash/bb index 0f9fbb8..fbbf4be 100755 --- a/bash/bb +++ b/bash/bb @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/changelog b/bash/changelog index fa0a387..e9fb561 100755 --- a/bash/changelog +++ b/bash/changelog @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/check-system b/bash/check-system index 27bffc0..2a87cb9 100755 --- a/bash/check-system +++ b/bash/check-system @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/clean-branches b/bash/clean-branches index 90369b1..ac52049 100755 --- a/bash/clean-branches +++ b/bash/clean-branches @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/commands.sh b/bash/commands.sh index cff654d..b4ba1ba 100644 --- a/bash/commands.sh +++ b/bash/commands.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/copy-keys b/bash/copy-keys index 28d821d..3be10e5 100755 --- a/bash/copy-keys +++ b/bash/copy-keys @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/daml-export b/bash/daml-export index 23c662e..b89bbfd 100755 --- a/bash/daml-export +++ b/bash/daml-export @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/dirs.sh b/bash/dirs.sh index 20c5d5a..795c574 100644 --- a/bash/dirs.sh +++ b/bash/dirs.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/doc.sh b/bash/doc.sh index 6eced7a..53499db 100644 --- a/bash/doc.sh +++ b/bash/doc.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/docker.sh b/bash/docker.sh index 4c45c00..7909de4 100644 --- a/bash/docker.sh +++ b/bash/docker.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/error.sh b/bash/error.sh index dea50c6..5f15352 100644 --- a/bash/error.sh +++ b/bash/error.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/exec.sh b/bash/exec.sh index dcff5da..7ebf4d4 100644 --- a/bash/exec.sh +++ b/bash/exec.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/fetch-all-pod-logs b/bash/fetch-all-pod-logs index 554c8c6..4aa12fc 100755 --- a/bash/fetch-all-pod-logs +++ b/bash/fetch-all-pod-logs @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/find-squashable b/bash/find-squashable index 9fd2e39..e210c6e 100755 --- a/bash/find-squashable +++ b/bash/find-squashable @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/fn.sh b/bash/fn.sh index cf68460..d7abb50 100644 --- a/bash/fn.sh +++ b/bash/fn.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/git-check b/bash/git-check index d70491b..a8c5171 100755 --- a/bash/git-check +++ b/bash/git-check @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/git.sh b/bash/git.sh index 6b321ab..f402b85 100644 --- a/bash/git.sh +++ b/bash/git.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/includer.sh b/bash/includer.sh index 6f699dc..f3da3a0 100644 --- a/bash/includer.sh +++ b/bash/includer.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/k8s-support-collector b/bash/k8s-support-collector index 03829b6..c633b1e 100755 --- a/bash/k8s-support-collector +++ b/bash/k8s-support-collector @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -91,6 +91,7 @@ function logs { -p >"${out_dir_ns}/$pod/$container-previous.log" 2>/dev/null || true if [ "$container" = "validator" ]; then log::notice "$pod container \"$container\" pulling extra logs" + local pod_sname pod_sname=$(echo "$pod" | awk -F/ '{print $NF}') exec::hide k8s::cp -n "$ns" -c "$container" \ "$pod_sname:/var/log/sawtooth/validator-debug.log" \ @@ -127,6 +128,19 @@ function create_package { rm -rf "${OUT_DIR}" } +# Test seam: when sourced from bats, skip the main entry point so +# individual functions can be exercised in isolation. Top-level +# `return` is invalid when this file is executed (not sourced); Bash +# then errors and falls through into the real collector — use exit 0 +# when executed with this flag set. +if [ "${K8S_SUPPORT_COLLECTOR_SOURCE_ONLY:-}" = "true" ]; then + if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + return 0 + else + exit 0 + fi +fi + if [ "${ALL_NAMESPACES}" = "true" ]; then log::notice "Collecting information from all namespaces" for ns in $(k8s::get_ns); do diff --git a/bash/k8s.sh b/bash/k8s.sh index 167af19..f21c08b 100644 --- a/bash/k8s.sh +++ b/bash/k8s.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/log.sh b/bash/log.sh index 5e0c32e..bc8450c 100644 --- a/bash/log.sh +++ b/bash/log.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/mddoc b/bash/mddoc index d382d6c..2f8fe2b 100755 --- a/bash/mddoc +++ b/bash/mddoc @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/on-change b/bash/on-change index 0bfc009..b49ce7f 100755 --- a/bash/on-change +++ b/bash/on-change @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/options.sh b/bash/options.sh index 77807a0..a438d44 100644 --- a/bash/options.sh +++ b/bash/options.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/pack-script b/bash/pack-script index d867a3e..2e81ea9 100755 --- a/bash/pack-script +++ b/bash/pack-script @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/pagerduty-alert b/bash/pagerduty-alert index 9152848..a34e226 100755 --- a/bash/pagerduty-alert +++ b/bash/pagerduty-alert @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/pagerduty.sh b/bash/pagerduty.sh index 4e51f5b..0fe1f4d 100644 --- a/bash/pagerduty.sh +++ b/bash/pagerduty.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/plantuml-from-k8s b/bash/plantuml-from-k8s index caa5505..dc56551 100755 --- a/bash/plantuml-from-k8s +++ b/bash/plantuml-from-k8s @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/pod-console b/bash/pod-console index affa3c5..6db08a3 100755 --- a/bash/pod-console +++ b/bash/pod-console @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/pretty-labels b/bash/pretty-labels index 6b228e9..4ea3c18 100755 --- a/bash/pretty-labels +++ b/bash/pretty-labels @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/registry-cp b/bash/registry-cp index 51f4d6f..abb7d32 100755 --- a/bash/registry-cp +++ b/bash/registry-cp @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/release-images b/bash/release-images index b72b759..1f512ce 100755 --- a/bash/release-images +++ b/bash/release-images @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -57,11 +57,11 @@ else while IFS= read -r repository; do echo "Repository: $repository" docker::pull "$target_registry/$repository:$target_tag" - done < <(grep -v '^ *#' <"$IMAGES_FILE") + done < <(awk '!/^[[:space:]]*#/ && !/^[[:space:]]*$/' "$IMAGES_FILE") while IFS= read -r repository; do for additional_registry in "${additional_registries[@]}"; do docker::cp "$target_registry/$repository:$target_tag" \ "$additional_registry/$repository:$target_tag" done - done < <(grep -v '^ *#' <"$IMAGES_FILE") + done < <(awk '!/^[[:space:]]*#/ && !/^[[:space:]]*$/' "$IMAGES_FILE") fi diff --git a/bash/replace-validator b/bash/replace-validator index 3a29fd8..a74b2aa 100755 --- a/bash/replace-validator +++ b/bash/replace-validator @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/secret.sh b/bash/secret.sh index 39a37fc..cc891d8 100644 --- a/bash/secret.sh +++ b/bash/secret.sh @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/switch-to-branch b/bash/switch-to-branch index 417e4f0..62673b8 100755 --- a/bash/switch-to-branch +++ b/bash/switch-to-branch @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/trust-server b/bash/trust-server index d291447..cf70e08 100755 --- a/bash/trust-server +++ b/bash/trust-server @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/bash/update-repo-tags b/bash/update-repo-tags index 25cade1..18ae75b 100755 --- a/bash/update-repo-tags +++ b/bash/update-repo-tags @@ -5,7 +5,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/tests/k8s-support-collector.bats b/tests/k8s-support-collector.bats new file mode 100644 index 0000000..c431f1c --- /dev/null +++ b/tests/k8s-support-collector.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats +# SUR-2177: k8s-support-collector options and selected functions with +# stubbed k8s:: / exec:: / dirs. Pairs with SUR-2171 (pod_sname local). + +setup() { + load 'helpers.bash' + helpers::isolate_home + COLLECTOR="$REPO_ROOT/bash/k8s-support-collector" + export LOGFILE_DISABLE=true LOG_DISABLE_DEBUG=true LOG_DISABLE_INFO=true +} + +@test "K8S_SUPPORT_COLLECTOR_SOURCE_ONLY exits 0 when executed (no main body)" { + out=$(mktemp -d) + run env K8S_SUPPORT_COLLECTOR_SOURCE_ONLY=true \ + bash "$COLLECTOR" -n isolated-ns -o "$out" + rm -rf "$out" + [ "$status" -eq 0 ] + [[ "$output" != *"Saving topology"* ]] + [[ "$output" != *"Collecting information from all namespaces"* ]] +} + +@test "sourced collector exports NAMESPACE and OUT_DIR from flags" { + out=$(mktemp -d) + run bash -c " + export K8S_SUPPORT_COLLECTOR_SOURCE_ONLY=true + source '$COLLECTOR' -n my-namespace -o '$out' + printf 'NAMESPACE=%s OUT_DIR=%s' \"\${NAMESPACE}\" \"\${OUT_DIR}\" + " + rm -rf "$out" + [ "$status" -eq 0 ] + [[ "$output" == *"NAMESPACE=my-namespace OUT_DIR=$out"* ]] +} + +@test "logs keeps pod_sname function-local (SUR-2171)" { + out=$(mktemp -d) + run bash -c " + export K8S_SUPPORT_COLLECTOR_SOURCE_ONLY=true + source '$COLLECTOR' -n testns -o '$out' + k8s::get_pod_names() { echo 'pod/waffle-validator-0'; } + k8s::get_containers_for_pod() { echo validator; } + k8s::log() { :; } + k8s::cp() { :; } + exec::hide() { \"\$@\"; } + pod_sname='marker_before' + logs testns + printf '%s' \"\${pod_sname}\" + " + rm -rf "$out" + [ "$status" -eq 0 ] + [[ "$(printf '%s\n' "$output" | tail -1)" == "marker_before" ]] +} + +@test "create_package tarball name uses cluster and namespace" { + run bash -c " + cd '${BATS_TEST_TMPDIR}' || exit 1 + export K8S_SUPPORT_COLLECTOR_SOURCE_ONLY=true + out=\$(mktemp -d) + echo x >\"\$out/collect-me.txt\" + source '$COLLECTOR' -n prod -o \"\$out\" + k8s::current_cluster() { echo 'my/prod-cluster'; } + date() { printf '%s\n' 'TSFIX'; } + create_package + ls -1 ./*.tar.gz + " + [ "$status" -eq 0 ] + [[ "$output" == *"my_prod-cluster.prod-TSFIX.tar.gz"* ]] +} + +@test "create_package uses ALL segment when ALL_NAMESPACES is true" { + run bash -c " + cd '${BATS_TEST_TMPDIR}' || exit 1 + export K8S_SUPPORT_COLLECTOR_SOURCE_ONLY=true + out=\$(mktemp -d) + echo y >\"\$out/f.txt\" + source '$COLLECTOR' -A -n ignored -o \"\$out\" + k8s::current_cluster() { echo 'ctx/cluster'; } + date() { printf '%s\n' 'TS2'; } + create_package + ls -1 ./*.tar.gz + " + [ "$status" -eq 0 ] + [[ "$output" == *"ctx_cluster.ALL-TS2.tar.gz"* ]] +} diff --git a/tests/release-images.bats b/tests/release-images.bats new file mode 100644 index 0000000..cd2a86f --- /dev/null +++ b/tests/release-images.bats @@ -0,0 +1,61 @@ +#!/usr/bin/env bats +# SUR-2178: release-images option and IMAGES_FILE loop behavior with +# SIMULATE / DRY_RUN. SUR-2173: blank and whitespace-only lines must +# not reach docker::pull / docker::cp. + +setup() { + load 'helpers.bash' + helpers::isolate_home + RELEASE_IMAGES="$REPO_ROOT/bash/release-images" + export LOGFILE_DISABLE=true LOG_DISABLE_DEBUG=true LOG_DISABLE_INFO=true +} + +@test "release-images -d sets SIMULATE so docker is not invoked" { + imgf=$(mktemp) + printf '%s\n' 'alpha/beta' >"$imgf" + run env PATH="$REPO_ROOT/tests/stubs:$PATH" \ + DOCKER_ARGV_LOG=/dev/null \ + "$RELEASE_IMAGES" -d -t v1 -r reg.example -a other.example -f "$imgf" + rm -f "$imgf" + [ "$status" -eq 0 ] + [[ "$output" == *"docker pull -q reg.example/alpha/beta:v1"* ]] +} + +@test "release-images IMAGES_FILE skips comments, blanks, and whitespace-only lines (SUR-2173)" { + imgf=$(mktemp) + cat >"$imgf" <<'EOF' +# ignored header + +gamma/delta + + + + +# tail comment +epsilon/zeta +EOF + run env PATH="$REPO_ROOT/tests/stubs:$PATH" \ + DOCKER_ARGV_LOG=/dev/null \ + "$RELEASE_IMAGES" -d -t v1 -r reg.example -a other.example -f "$imgf" + rm -f "$imgf" + [ "$status" -eq 0 ] + [[ "$output" == *"Repository: gamma/delta"* ]] + [[ "$output" == *"Repository: epsilon/zeta"* ]] + [[ "$output" != *"reg.example/:v1"* ]] + [[ "$output" != *"reg.example/ :v1"* ]] + # First loop pulls each repo; second loop runs docker::cp which pulls again. + pull_count=$(grep -c 'docker pull -q reg.example/' <<<"$output" || true) + [[ "$pull_count" -eq 4 ]] +} + +@test "release-images IMAGES_FILE runs docker::cp once per repo per additional registry" { + imgf=$(mktemp) + printf '%s\n' 'one/r' 'two/r' >"$imgf" + run env PATH="$REPO_ROOT/tests/stubs:$PATH" \ + DOCKER_ARGV_LOG=/dev/null \ + "$RELEASE_IMAGES" -d -t t9 -r src.reg -a a.extra -f "$imgf" + rm -f "$imgf" + [ "$status" -eq 0 ] + tag_count=$(grep -c 'docker tag src\.reg/' <<<"$output" || true) + [[ "$tag_count" -eq 2 ]] +}