From bcaab38ef0508d0c23f2dbdebfb267e3188a039a Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Wed, 3 Jan 2024 15:20:54 +0200 Subject: [PATCH] Add a test Signed-off-by: Kimmo Lehto --- pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go | 6 +++++- pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go index b9f5a55c..a10f56ad 100644 --- a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go +++ b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go @@ -371,13 +371,17 @@ func (h *Host) K0sServiceName() string { } } +func (h *Host) k0sBinaryPathDir() string { + return gopath.Dir(h.Configurer.K0sBinaryPath()) +} + // InstallK0sBinary installs the k0s binary from the provided file path to K0sBinaryPath func (h *Host) InstallK0sBinary(path string) error { if !h.Configurer.FileExist(h, path) { return fmt.Errorf("k0s binary tempfile not found") } - dir := gopath.Dir(h.Configurer.K0sBinaryPath()) + dir := h.k0sBinaryPathDir() if err := h.Execf(`install -m 0755 -o root -g root -d "%s"`, dir, exec.Sudo(h)); err != nil { return fmt.Errorf("create k0s binary dir: %w", err) } diff --git a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go index 812681ba..7758c4dd 100644 --- a/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go +++ b/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go @@ -134,3 +134,10 @@ func TestValidation(t *testing.T) { require.ErrorContains(t, h.Validate(), "unbalanced quotes") }) } + +func TestBinaryPath(t *testing.T) { + h := Host{} + h.Configurer = &mockconfigurer{} + h.Configurer.SetPath("K0sBinaryPath", "/foo/bar/k0s") + require.Equal(t, "/foo/bar", h.k0sBinaryPathDir()) +}