summaryrefslogtreecommitdiff
path: root/tests/xattr
diff options
context:
space:
mode:
Diffstat (limited to 'tests/xattr')
-rw-r--r--tests/xattr/xattr_integration_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/xattr/xattr_integration_test.go b/tests/xattr/xattr_integration_test.go
index 1e081c2..58d62d9 100644
--- a/tests/xattr/xattr_integration_test.go
+++ b/tests/xattr/xattr_integration_test.go
@@ -66,6 +66,60 @@ func TestXattrSetGetRm(t *testing.T) {
}
}
+func TestXattrSetEmpty(t *testing.T) {
+ attr := "user.foo"
+ fn := test_helpers.DefaultPlainDir + "/TestXattrSetEmpty1"
+ err := ioutil.WriteFile(fn, nil, 0700)
+ if err != nil {
+ t.Fatalf("creating empty file failed: %v", err)
+ }
+ // Make sure it does not exist already
+ _, err = xattr.Get(fn, attr)
+ if err == nil {
+ t.Fatal("we should have got an error here")
+ }
+ // Set empty value
+ err = xattr.Set(fn, attr, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Read back
+ val, err := xattr.Get(fn, attr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(val) != 0 {
+ t.Errorf("wrong length: want=0 have=%d", len(val))
+ }
+ // Overwrite empty value with something
+ val1 := []byte("xyz123")
+ err = xattr.Set(fn, attr, val1)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Read back
+ val2, err := xattr.Get(fn, attr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !bytes.Equal(val1, val2) {
+ t.Fatalf("wrong readback value: %v != %v", val1, val2)
+ }
+ // Overwrite something with empty value
+ err = xattr.Set(fn, attr, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Read back
+ val, err = xattr.Get(fn, attr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(val) != 0 {
+ t.Errorf("wrong length: want=0 have=%d", len(val2))
+ }
+}
+
func TestXattrList(t *testing.T) {
fn := test_helpers.DefaultPlainDir + "/TestXattrList"
err := ioutil.WriteFile(fn, nil, 0700)