-
Notifications
You must be signed in to change notification settings - Fork 29
/
xattr_flags_test.go
39 lines (31 loc) · 1016 Bytes
/
xattr_flags_test.go
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
//go:build linux || darwin || solaris
// +build linux darwin solaris
package xattr
import (
"io/ioutil"
"os"
"testing"
)
func TestFlags(t *testing.T) {
tmp, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmp.Name())
err = SetWithFlags(tmp.Name(), UserPrefix+"flags-test", []byte("flags-test-attr-value"), 0)
checkIfError(t, err)
err = SetWithFlags(tmp.Name(), UserPrefix+"flags-test", []byte("flags-test-attr-value"), XATTR_CREATE)
if err == nil {
t.Fatalf("XATTR_CREATE should have failed because the xattr already exists")
}
t.Log(err)
err = SetWithFlags(tmp.Name(), UserPrefix+"flags-test", []byte("flags-test-attr-value"), XATTR_REPLACE)
checkIfError(t, err)
err = Remove(tmp.Name(), UserPrefix+"flags-test")
checkIfError(t, err)
err = SetWithFlags(tmp.Name(), UserPrefix+"flags-test", []byte("flags-test-attr-value"), XATTR_REPLACE)
if err == nil {
t.Fatalf("XATTR_REPLACE should have failed because there is nothing to replace")
}
t.Log(err)
}