2013-06-27 11:28:59 +00:00
|
|
|
import os
|
2013-07-04 09:59:15 +00:00
|
|
|
import tempfile
|
|
|
|
import unittest
|
2013-06-27 11:28:59 +00:00
|
|
|
from darc.testsuite import DarcTestCase
|
2013-07-04 09:59:15 +00:00
|
|
|
from darc.xattr import lsetxattr, llistxattr, lgetxattr, get_all, set, flistxattr, fgetxattr, fsetxattr, is_enabled
|
2013-06-27 11:28:59 +00:00
|
|
|
|
|
|
|
|
2013-07-04 09:59:15 +00:00
|
|
|
@unittest.skipUnless(is_enabled(), 'xattr not enabled on filesystem')
|
2013-06-27 11:28:59 +00:00
|
|
|
class XattrTestCase(DarcTestCase):
|
|
|
|
|
2013-06-27 19:56:14 +00:00
|
|
|
def setUp(self):
|
2013-07-04 09:59:15 +00:00
|
|
|
self.tmpfile = tempfile.NamedTemporaryFile()
|
2013-06-27 19:56:14 +00:00
|
|
|
self.symlink = os.path.join(os.path.dirname(self.tmpfile.name), 'symlink')
|
|
|
|
os.symlink(self.tmpfile.name, self.symlink)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
os.unlink(self.symlink)
|
|
|
|
|
2013-06-27 11:28:59 +00:00
|
|
|
def test_low_level(self):
|
2013-06-27 19:56:14 +00:00
|
|
|
self.assert_equal(llistxattr(self.tmpfile.name), [])
|
|
|
|
self.assert_equal(llistxattr(self.symlink), [])
|
2013-06-27 20:10:15 +00:00
|
|
|
lsetxattr(self.tmpfile.name, b'foo', b'bar')
|
|
|
|
self.assert_equal(llistxattr(self.tmpfile.name), [b'foo'])
|
|
|
|
self.assert_equal(lgetxattr(self.tmpfile.name, b'foo'), b'bar')
|
2013-06-27 19:56:14 +00:00
|
|
|
self.assert_equal(llistxattr(self.symlink), [])
|
2013-06-27 11:28:59 +00:00
|
|
|
|
|
|
|
def test_low_level_fileno(self):
|
2013-06-27 19:56:14 +00:00
|
|
|
self.assert_equal(flistxattr(self.tmpfile.fileno()), [])
|
2013-06-27 20:10:15 +00:00
|
|
|
fsetxattr(self.tmpfile.fileno(), b'foo', b'bar')
|
|
|
|
self.assert_equal(flistxattr(self.tmpfile.fileno()), [b'foo'])
|
|
|
|
self.assert_equal(fgetxattr(self.tmpfile.fileno(), b'foo'), b'bar')
|
2013-06-27 11:28:59 +00:00
|
|
|
|
|
|
|
def test_high_level(self):
|
2013-06-27 19:56:14 +00:00
|
|
|
self.assert_equal(get_all(self.tmpfile.name), {})
|
|
|
|
self.assert_equal(get_all(self.symlink), {})
|
|
|
|
set(self.tmpfile.name, b'foo', b'bar')
|
|
|
|
self.assert_equal(get_all(self.tmpfile.name), {b'foo': b'bar'})
|
|
|
|
self.assert_equal(get_all(self.symlink), {})
|
2013-06-27 11:28:59 +00:00
|
|
|
|
|
|
|
def test_high_level_fileno(self):
|
2013-06-27 19:56:14 +00:00
|
|
|
self.assert_equal(get_all(self.tmpfile.fileno()), {})
|
|
|
|
set(self.tmpfile.fileno(), b'foo', b'bar')
|
|
|
|
self.assert_equal(get_all(self.tmpfile.fileno()), {b'foo': b'bar'})
|