summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2011-10-10 13:54:08 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2011-10-10 13:54:08 +0100
commit1e9d1410e355d8ad0ab1cdcc12c396e0670882c0 (patch)
tree93240faae9f8cbcbf4af748f08363f2a91ca37b3 /tests
parent665beee6012505d0a3e54cc06f73ef21884e889d (diff)
downloadtbdiff-1e9d1410e355d8ad0ab1cdcc12c396e0670882c0.tar.gz
Added test for extended attributes
Diffstat (limited to 'tests')
-rwxr-xr-xtests/15_xattr_add.sh34
-rw-r--r--tests/test_lib.sh29
2 files changed, 61 insertions, 2 deletions
diff --git a/tests/15_xattr_add.sh b/tests/15_xattr_add.sh
new file mode 100755
index 0000000..18156aa
--- /dev/null
+++ b/tests/15_xattr_add.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+TEST_ID="15"
+TEST_NAME="Extended Attributes manipulation"
+
+CREATE=`pwd`/$1
+DEPLOY=`pwd`/$2
+TEST_TOOLS=$3
+
+. ./test_lib.sh
+
+############# Test specific code ############
+if is_command getfattr && is_command setfattr; then :; else
+ echo Test requires commands: getfattr, setfattr, attr >&2
+ exit 127
+fi
+
+setup () {
+ touch $ORIGIN/file &&
+ setfattr -n "user.preserve" -v "true" $ORIGIN/file &&
+ setfattr -n "user.change" -v "false" $ORIGIN/file &&
+ setfattr -n "user.remove" -v "false" $ORIGIN/file &&
+ touch $TARGET/file &&
+ setfattr -n "user.preserve" -v "true" $TARGET/file &&
+ setfattr -n "user.change" -v "true" $TARGET/file &&
+ setfattr -n "user.add" -v "true" $TARGET/file
+}
+
+check_results () {
+ check_xattrs $ORIGIN/file $TARGET/file
+}
+
+#############################################
+main $@
diff --git a/tests/test_lib.sh b/tests/test_lib.sh
index e95759d..eb66c9e 100644
--- a/tests/test_lib.sh
+++ b/tests/test_lib.sh
@@ -21,12 +21,12 @@ check_same_mode () {
test $(stat -c "%f" $1) = $(stat -c "%f" $2)
}
-# check_content FILE EXPECTED_OCTAL_PERMISSIONS
+# check_perm FILE EXPECTED_OCTAL_PERMISSIONS
check_perm () {
test $(stat -c %a $1) = $2
}
-# check_content FILE EXPECTED_OCTAL_PERMISSIONS
+# check_symlink FILE EXPECTED_PATH
check_symlink () {
test $(readlink $1) = $2
}
@@ -41,6 +41,31 @@ check_group () {
test $(stat -c %G $1) = $2
}
+# check_xattrs FILE1 FILE2
+# check that two files have the same attributes
+check_xattrs () {
+ test "`getfattr --dump --encoding=base64 $1 | tail -n +2`" = \
+ "`getfattr --dump --encoding=base64 $2 | tail -n +2`"
+}
+
+# check_xattr_exists FILE KEY
+check_xattr_exists () {
+ # attr doesn't use user. prefix, but getfattr returns 0 on non-existant
+ noprefix=`echo $2 | sed s/user.//`
+ attr -g $2 $1 >dev/null 2>/dev/null
+}
+
+# xattr_get FILE KEY
+xattr_get () {
+ getfattr --only-values --name=$2 $1
+}
+
+# check_xattr_value FILE KEY VALUE
+check_xattr_value () {
+ check_xattr_exists &&
+ test "`xattr_get $1 $2`" = "$3"
+}
+
# tests whether a command exists
is_command () {
type $1 >/dev/null 2>/dev/null