Add testing

This commit is contained in:
Melody Becker 2025-04-14 16:59:59 +02:00
parent 3233f8c27f
commit 06e6d457da
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
14 changed files with 273 additions and 5 deletions

29
shared/fswrapper_test.go Normal file
View file

@ -0,0 +1,29 @@
package shared
import (
"io"
"os"
"reflect"
"testing"
)
func TestFSWrapper_Open(t *testing.T) {
rootFs := os.DirFS("/")
wrapper := NewFSWrapper(rootFs, "etc/", false)
f, err := wrapper.Open("hostname")
if err != nil {
t.Fatalf("failed to open /etc/hostname: %v", err)
}
defer f.Close()
data, err := os.ReadFile("/etc/hostname")
if err != nil {
t.Fatalf("failed to read with full path: %v", err)
}
wrappedData, err := io.ReadAll(f)
if err != nil {
t.Fatalf("failed to read from wrapped file: %v", err)
}
if !reflect.DeepEqual(wrappedData, data) {
t.Fatal("file contents are different")
}
}