aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-08-30 16:36:10 +0200
committerJakob Unterwurzacher2020-08-30 16:36:10 +0200
commit3806a8cc9392a11ad604b306ea4f5d34d741e86d (patch)
tree560ac156baaa736ca8522c8388b874524e4811e0
parentd212b246c5e24e6151bef45ad5a8185fdd12a28f (diff)
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.
-rw-r--r--tests/reverse/xattr_test.go66
1 files changed, 66 insertions, 0 deletions
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)
+ }
+ }
+}