Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Jan 3, 2024
1 parent 0f2938a commit bcaab38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit bcaab38

Please sign in to comment.