Skip to content

Commit

Permalink
Wrap all bash variable assignments in quotes
Browse files Browse the repository at this point in the history
These don't make any difference because the right side of variable
assignments is not subject to word splitting and globbing, but
unconditionally wrapping all variable/expression substitutions means
people don't need to know/remember when the shell splits words, and
when it doesn't.

Signed-off-by: Jan Dubois <jan.dubois@suse.com>
  • Loading branch information
jandubois committed May 1, 2023
1 parent 0fa05ff commit 1d0faa4
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions bats/tests/containers/switch-engines.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load '../helpers/load'
RD_CONTAINER_ENGINE=moby

switch_container_engine() {
local name=$1
local name="$1"
RD_CONTAINER_ENGINE="${name}"
rdctl set --container-engine.name="${name}"
wait_for_container_engine
Expand Down Expand Up @@ -40,7 +40,7 @@ verify_post_switch_containers() {
}

switch_back_verify_post_switch_containers() {
local name=$1
local name="$1"
switch_container_engine "${name}"
try --max 12 --delay 5 verify_post_switch_containers
assert_success
Expand Down
2 changes: 1 addition & 1 deletion bats/tests/helpers/commands.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
EXE=""
PLATFORM=$OS
PLATFORM="$OS"
if is_windows; then
PLATFORM=linux
if using_windows_exe; then
Expand Down
2 changes: 1 addition & 1 deletion bats/tests/helpers/defaults.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
validate_enum() {
local var=$1
local var="$1"
shift
for value in "$@"; do
if [ "${!var}" = "$value" ]; then
Expand Down
4 changes: 2 additions & 2 deletions bats/tests/helpers/kubernetes.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ wait_for_apiserver() {
run kubectl get node -o jsonpath="{.items[0].status.nodeInfo.kubeletVersion}"
if [ "$status" -eq 0 ]; then
# Turn "v1.23.4+k3s1" into "1.23.4"
local version=${output#v}
version=${version%+*}
local version="${output#v}"
version="${version%+*}"
[ "$version" == "$desired_version" ] && return 0
fi
sleep 1
Expand Down
4 changes: 2 additions & 2 deletions bats/tests/helpers/load.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ absolute_path() {
)
}

PATH_BATS_HELPERS=$(absolute_path "$(dirname "${BASH_SOURCE[0]}")")
PATH_BATS_ROOT=$(absolute_path "$PATH_BATS_HELPERS/../..")
PATH_BATS_HELPERS="$(absolute_path "$(dirname "${BASH_SOURCE[0]}")")"
PATH_BATS_ROOT="$(absolute_path "$PATH_BATS_HELPERS/../..")"

# Use fatal() to abort loading helpers; don't run any tests
fatal() {
Expand Down
4 changes: 2 additions & 2 deletions bats/tests/helpers/os.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://www.shellcheck.net/wiki/SC2120 -- disabled due to complaining about not referencing arguments that are optional on functions is_platformName
# shellcheck disable=SC2120
UNAME=$(uname)
ARCH=$(uname -m)
UNAME="$(uname)"
ARCH="$(uname -m)"

case $UNAME in
Darwin)
Expand Down
10 changes: 5 additions & 5 deletions bats/tests/helpers/paths.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# PATH_BATS_ROOT and PATH_BATS_HELPERS are already set by load.bash

PATH_REPO_ROOT=$(absolute_path "$PATH_BATS_ROOT/..")
PATH_REPO_ROOT="$(absolute_path "$PATH_BATS_ROOT/..")"

inside_repo_clone() {
[ -d "$PATH_REPO_ROOT/pkg/rancher-desktop" ]
}

set_path_resources() {
local system=$1
local user=$2
local dist=$3
local subdir=$4
local system="$1"
local user="$2"
local dist="$3"
local subdir="$4"

if [ -z "$RD_LOCATION" ]; then
if [ -d "$system" ]; then
Expand Down
10 changes: 5 additions & 5 deletions bats/tests/helpers/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ try() {
while [[ $# -gt 0 ]] && [[ $1 == -* ]]; do
case "$1" in
--max)
max=$2
max="$2"
shift
;;
--delay)
delay=$2
delay="$2"
shift
;;
--)
Expand All @@ -55,13 +55,13 @@ try() {
run "$@"
[ "$status" -eq 0 ] && return
sleep "$delay"
count=$((count + 1))
count="$((count + 1))"
done
}

update_allowed_patterns() {
local enabled=$1
local patterns=$2
local enabled="$1"
local patterns="$2"
rdctl api settings -X PUT --input - <<EOF
{
"version": 7,
Expand Down
2 changes: 1 addition & 1 deletion bats/tests/k8s/helm-install-rancher.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setup() {

get_host() {
if is_windows; then
local LB_IP=$(kubectl get svc traefik --namespace kube-system | awk 'NR==2{print $4}')
local LB_IP="$(kubectl get svc traefik --namespace kube-system | awk 'NR==2{print $4}')"
echo "$LB_IP.sslip.io"
else
echo "localhost"
Expand Down
2 changes: 1 addition & 1 deletion bats/tests/k8s/up-downgrade-k8s.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ verify_images() {
# the current k8s version in that directory.

verify_kuberlr_for_version() {
local K8S_VERSION=$1
local K8S_VERSION="$1"
local KUBERLR_DIR="${HOME}/.kuberlr/${OS}-${ARCH_FOR_KUBERLR}"
rm -f "${KUBERLR_DIR}/kubectl"*
run kubectl version
Expand Down
4 changes: 2 additions & 2 deletions bats/tests/k8s/verify-cached-images.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ load '../helpers/load'
}

test_k8s_version_has_correct_cached_extension() {
local K8S_VERSION=$1
local EXTENSION=$2
local K8S_VERSION="$1"
local EXTENSION="$2"
rdctl set --kubernetes-version "$K8S_VERSION"
wait_for_apiserver "$K8S_VERSION"
run ls "$PATH_CACHE/k3s/v${K8S_VERSION}"*k3s*/k3s-airgap-images-*."${EXTENSION}"
Expand Down

0 comments on commit 1d0faa4

Please sign in to comment.