From 3806a8cc9392a11ad604b306ea4f5d34d741e86d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 30 Aug 2020 16:36:10 +0200 Subject: tests/reverse: implement (skipped) xattr test v1api reverse mode did not have xattr support, the v2api version may have at some point. Prep the test already. --- tests/reverse/xattr_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/reverse/xattr_test.go (limited to 'tests/reverse') diff --git a/tests/reverse/xattr_test.go b/tests/reverse/xattr_test.go new file mode 100644 index 0000000..8002604 --- /dev/null +++ b/tests/reverse/xattr_test.go @@ -0,0 +1,66 @@ +package reverse_test + +import ( + "fmt" + "io/ioutil" + "path/filepath" + "syscall" + "testing" + + "github.com/pkg/xattr" +) + +func xattrSupported(path string) bool { + _, err := xattr.LGet(path, "user.xattrSupported-dummy-value") + if err == nil { + return true + } + err2 := err.(*xattr.Error) + if err2.Err == syscall.EOPNOTSUPP { + return false + } + return true +} + +func TestXattrList(t *testing.T) { + t.Skip("TODO: not implemented yet in reverse mode") + + if !xattrSupported(dirA) { + t.Skip() + } + fnA := filepath.Join(dirA, t.Name()) + err := ioutil.WriteFile(fnA, nil, 0700) + if err != nil { + t.Fatalf("creating empty file failed: %v", err) + } + val := []byte("xxxxxxxxyyyyyyyyyyyyyyyzzzzzzzzzzzzz") + num := 20 + var namesA map[string]string + for i := 1; i <= num; i++ { + attr := fmt.Sprintf("user.TestXattrList.%02d", i) + err = xattr.LSet(fnA, attr, val) + if err != nil { + t.Fatal(err) + } + namesA[attr] = string(val) + } + fnC := filepath.Join(dirC, t.Name()) + tmp, err := xattr.LList(fnC) + if err != nil { + t.Fatal(err) + } + var namesC map[string]string + for _, n := range tmp { + namesC[n] = string(val) + } + if len(namesA) != len(namesC) { + t.Errorf("wrong number of names, want=%d have=%d", len(namesA), len(namesC)) + } + for i := range namesC { + valA := namesA[i] + valC := namesC[i] + if valC != valA { + t.Errorf("mismatch on attr %q: valA = %q, valC = %q", i, valA, valC) + } + } +} -- cgit v1.2.3