Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/int/helpers: cleanup, enable shellcheck #3175

Merged
merged 2 commits into from
Aug 25, 2021

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Aug 23, 2021

Originally part of #3090, separated out to simplify review.

  1. tests/int/helpers: rm $bundle handling

    It is not used since PR tests/int: cleanups #2757, as all tests are run with cd to bundle
    directory.

    runc_spec argument count checking is removed since otherwise shellcheck
    complains:

    SC2120: runc_spec references arguments, but none are ever passed.

  2. tests/int/helpers: fix shellcheck warnings

    ... and add the file to be checked by shellcheck.

It is not used since PR 2757, as all tests are run with cd to bundle
directory.

runc_spec argument count checking is removed since otherwise shellcheck
complains:

> SC2120: runc_spec references arguments, but none are ever passed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
... and add the file to be checked by shellcheck.

The warnings fixed are:

In tests/integration/helpers.bash line 10:
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")")
                                           ^----------^ SC2128: Expanding an array without an index only gives the first element.

In tests/integration/helpers.bash line 22:
TESTDATA="${INTEGRATION_ROOT}/testdata"
^------^ SC2034: TESTDATA appears unused. Verify use (or export if used externally).

In tests/integration/helpers.bash line 42:
	echo "runc $@ (status=$status):" >&2
                   ^-- SC2145: Argument mixes string and array. Use * or separate argument.
                              ^-----^ SC2154: status is referenced but not assigned.

In tests/integration/helpers.bash line 43:
	echo "$output" >&2
              ^-----^ SC2154: output is referenced but not assigned.

In tests/integration/helpers.bash line 77:
			| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START + 10))"', "containerID": 1, "size": 20}]
                                                                 ^--------------------^ SC2004: $/${} is unnecessary on arithmetic variables.

In tests/integration/helpers.bash line 78:
			| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START + 100))"', "containerID": 1000, "size": '"$(($ROOTLESS_GIDMAP_LENGTH - 1000))"'}]'
                                                                 ^--------------------^ SC2004: $/${} is unnecessary on arithmetic variables.
                                                                                                                                     ^---------------------^ SC2004: $/${} is unnecessary on arithmetic variables.

In tests/integration/helpers.bash line 125:
			base_path=$(gawk '$(NF-2) == "cgroup" && $NF ~ /\<'${g}'\>/ { print $5; exit }' /proc/self/mountinfo)
                                                                           ^--^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
			base_path=$(gawk '$(NF-2) == "cgroup" && $NF ~ /\<'"${g}"'\>/ { print $5; exit }' /proc/self/mountinfo)

In tests/integration/helpers.bash line 127:
			eval CGROUP_${g^^}_BASE_PATH="${base_path}"
                                    ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
			eval CGROUP_"${g^^}"_BASE_PATH="${base_path}"

In tests/integration/helpers.bash line 229:
	if [ "x$CGROUP_UNIFIED" = "xyes" ]; then
             ^----------------^ SC2268: Avoid x-prefix in comparisons as it no longer serves a purpose.

Did you mean:
	if [ "$CGROUP_UNIFIED" = "yes" ]; then

In tests/integration/helpers.bash line 234:
		eval cgroup=\$${var}${REL_CGROUPS_PATH}
                              ^----^ SC2086: Double quote to prevent globbing and word splitting.
                                    ^-----------------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
		eval cgroup=\$"${var}""${REL_CGROUPS_PATH}"

In tests/integration/helpers.bash line 236:
	cat $cgroup/$source
            ^-----^ SC2086: Double quote to prevent globbing and word splitting.
                    ^-----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	cat "$cgroup"/"$source"

In tests/integration/helpers.bash line 242:
	current="$(get_cgroup_value $1)"
                                    ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	current="$(get_cgroup_value "$1")"

In tests/integration/helpers.bash line 245:
	echo "current" $current "!?" "$expected"
                       ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	echo "current" "$current" "!?" "$expected"

In tests/integration/helpers.bash line 257:
	[ $(id -u) != "0" ] && user="--user"
          ^------^ SC2046: Quote this to prevent word splitting.

In tests/integration/helpers.bash line 259:
	current=$(systemctl show $user --property $source $SD_UNIT_NAME | awk -F= '{print $2}')
                                                  ^-----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	current=$(systemctl show $user --property "$source" $SD_UNIT_NAME | awk -F= '{print $2}')

In tests/integration/helpers.bash line 261:
	[ "$current" = "$expected" ] || [ -n "$expected2" -a "$current" = "$expected2" ]
                                                          ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

In tests/integration/helpers.bash line 309:
	check_cgroup_value "cpu.weight" $weight
                                        ^-----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	check_cgroup_value "cpu.weight" "$weight"

In tests/integration/helpers.bash line 310:
	check_systemd_value "CPUWeight" $weight
                                        ^-----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	check_systemd_value "CPUWeight" "$weight"

In tests/integration/helpers.bash line 383:
			if [ $CGROUP_UNIFIED = "no" -a ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.memsw.limit_in_bytes" ]; then
                                                    ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

In tests/integration/helpers.bash line 412:
			local cpu_count=$(grep -c '^processor' /proc/cpuinfo)
                              ^-------^ SC2155: Declare and assign separately to avoid masking return values.

In tests/integration/helpers.bash line 450:
		sleep $delay
                      ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
		sleep "$delay"

In tests/integration/helpers.bash line 453:
	echo "Command \"$@\" failed $attempts times. Output: $output"
                        ^-- SC2145: Argument mixes string and array. Use * or separate argument.

In tests/integration/helpers.bash line 471:
	runc state $1
                   ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	runc state "$1"

In tests/integration/helpers.bash line 472:
	if [ $2 == "checkpointed" ]; then
             ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	if [ "$2" == "checkpointed" ]; then

In tests/integration/helpers.bash line 484:
	mkdir $dir
              ^--^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
	mkdir "$dir"

In tests/integration/helpers.bash line 497:
		kill -9 $(cat "$dir/pid")
                        ^---------------^ SC2046: Quote this to prevent word splitting.

In tests/integration/helpers.bash line 508:
	export ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc.XXXXXX")
               ^--^ SC2155: Declare and assign separately to avoid masking return values.

In tests/integration/helpers.bash line 512:
	cd "$ROOT/bundle"
        ^---------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Did you mean:
	cd "$ROOT/bundle" || exit

In tests/integration/helpers.bash line 535:
	cd "$INTEGRATION_ROOT"
        ^--------------------^ SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Did you mean:
	cd "$INTEGRATION_ROOT" || exit

For more information:
  https://www.shellcheck.net/wiki/SC2145 -- Argument mixes string and array. ...
  https://www.shellcheck.net/wiki/SC2034 -- TESTDATA appears unused. Verify u...
  https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin changed the title tests/int: cleanups tests/int/helpers: cleanup, enable shellcheck Aug 24, 2021
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mrunalp mrunalp merged commit 654f331 into opencontainers:master Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants