summaryrefslogtreecommitdiff
path: root/tests/reverse/xattr_test.go
blob: 8002604126a85e7366e5efe595354ae162fbb25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
		}
	}
}