mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-08 12:29:27 +00:00
Skip dirs in copyArtifactSetRole and replace only basename
otherwise we get the error: ``` panic: open /efi/EFI/kairos/passive.efi.extra.d: is a directory ``` and we may replace parts of the path that we shouldn't. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
64
pkg/uki/common_test.go
Normal file
64
pkg/uki/common_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package uki
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
|
||||
cnst "github.com/kairos-io/kairos-agent/v2/pkg/constants"
|
||||
fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
|
||||
sdkTypes "github.com/kairos-io/kairos-sdk/types"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/twpayne/go-vfs/v4"
|
||||
"github.com/twpayne/go-vfs/v4/vfst"
|
||||
)
|
||||
|
||||
var _ = Describe("Common functions tests", func() {
|
||||
Describe("copyArtifactSetRole", func() {
|
||||
var fs vfs.FS
|
||||
var err error
|
||||
var memLog *bytes.Buffer
|
||||
var logger sdkTypes.KairosLogger
|
||||
|
||||
BeforeEach(func() {
|
||||
fs, _, err = vfst.NewTestFS(map[string]interface{}{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
logger = sdkTypes.NewBufferLogger(memLog)
|
||||
logger.SetLevel("debug")
|
||||
|
||||
Expect(fsutils.MkdirAll(fs, "/active", cnst.DirPerm)).ToNot(HaveOccurred())
|
||||
Expect(fsutils.MkdirAll(fs, "/other", cnst.DirPerm)).ToNot(HaveOccurred())
|
||||
|
||||
f, err := fs.Create("/other/active.efi")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = os.Stat(f.Name())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
f, err = fs.Create("/other/other.efi")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = os.Stat(f.Name())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("skips directories", func() {
|
||||
err = copyArtifactSetRole(fs, "/", "active", "passive", logger)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("replaces only the base file name", func() {
|
||||
err = copyArtifactSetRole(fs, "/other", "other", "newother", logger)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
glob, _ := fs.Glob("/other/*")
|
||||
Expect(glob).To(HaveExactElements([]string{
|
||||
"/other/active.efi",
|
||||
"/other/newother.efi",
|
||||
"/other/other.efi",
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user