Fix: Issue with copying
This commit is contained in:
parent
0170b7cd90
commit
b618f7348c
3 changed files with 70 additions and 5 deletions
33
internal/configs/configs_test.go
Normal file
33
internal/configs/configs_test.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package configs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCopyToSystem(t *testing.T) {
|
||||
if err := os.Mkdir("testdir", 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tFilePath := filepath.Join("testdir", "testfile")
|
||||
if err := os.WriteFile(tFilePath, []byte("test"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := os.RemoveAll("testdir"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
isRoot := os.Getuid() == 0
|
||||
switch isRoot {
|
||||
case true:
|
||||
t.Run("TestCopyToSystem_AsRoot", func(t *testing.T) {
|
||||
CopyToSystem(true, tFilePath, "/etc/testfile")
|
||||
})
|
||||
default:
|
||||
t.Run("TestCopyToSystem_AsUser", func(t *testing.T) {
|
||||
CopyToSystem(false, tFilePath, "/etc/testfile")
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue