k0sproject/k0sctl

Unit tests fail when sudo is not available

twz123 opened this issue · 2 comments

Since 0.17.2, the unit tests fail if there's no sudo available on the host machine. I think this has been introduced in #620.

=== RUN TestK0sInstallCommand
DEBUG [local] localhost: executing uname | grep -q Linux
DEBUG [local] localhost: executing cat /etc/os-release || cat /usr/lib/os-release
DEBUG [local] localhost: NAME="Alpine Linux"
DEBUG [local] localhost: ID=alpine
DEBUG [local] localhost: VERSION_ID=3.20.0_alpha20231219
DEBUG [local] localhost: PRETTY_NAME="Alpine Linux edge"
DEBUG [local] localhost: HOME_URL="https://alpinelinux.org/"
DEBUG [local] localhost: BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
DEBUG [local] localhost: executing [ "$(id -u)" = 0 ]
DEBUG [local] localhost: executing sudo -n true
DEBUG [local] localhost: (stderr) sh: sudo: not found
DEBUG [local] localhost: executing doas -n -- "${SHELL-sh}" -c true
host_test.go:82:
Error Trace: github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go:82
Error: Should be true
Test: TestK0sInstallCommand
--- FAIL: TestK0sInstallCommand (0.01s)

kke commented

Actually it's probably because the doasifier wraps the command in quotes and escapes ".

	require.True(t, strings.HasSuffix(cmd, `k0s install worker --data-dir=/tmp/k0s --token-file "from-configurer"`))
func sudoDoas(cmd string) string {
	return `doas -n -- "${SHELL-sh}" -c ` + shellescape.Quote(cmd)
}