Fix: Issue with copying

This commit is contained in:
kayos@tcp.direct 2024-06-19 09:45:23 -07:00
parent 0170b7cd90
commit b618f7348c
No known key found for this signature in database
GPG key ID: 4B841471B4BEE979
3 changed files with 70 additions and 5 deletions

View 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")
})
}
}