Add unit tests for worm

Signed-off-by: Bryant G. Duffy-Ly <bduffyly@versity.com>
This commit is contained in:
Bryant G. Duffy-Ly
2022-02-03 09:26:21 -08:00
committed by Zach Brown
parent 1d55a4c099
commit 9291f1a231
3 changed files with 126 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
== test creation of worm xattr without .hide
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation of worm xattr on a directory
setfattr: /mnt/test/test/worm-xattr-unit: Invalid argument
== test creation of worm xattr
== test value is set correctly
== test deletion of xattr 1 sec after setting
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Permission denied
== test setting xattr to a previous time after setting
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Permission denied
== test deletion before expiration
rm: cannot remove /mnt/test/test/worm-xattr-unit/file-1: Permission denied
== Try to move the file prior to expiration
mv: cannot move /mnt/test/test/worm-xattr-unit/file-1 to /mnt/test/test/worm-xattr-unit/file-2: Permission denied
== Try to write to file before expiration
date: write error: Permission denied
== wait til expiration
== Try to write to file after expiration
== Try to move the file after expiration
== test deletion after expiration
== test creation with non integer value of a.a
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with non integer value of ....
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with non integer value of ...
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with no nsec value of 11.
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with no sec value of .11
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with . at start and end value .11.
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with invalid format of two characters
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with too large of a nsecs value 1.18446744073709551615
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with nsecs > NSECS_PER_SEC value 1.1000000000
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== test creation with sec > U64_MAX value of 184467440737095516159.1
setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument
== removing files after expiration
+1
View File
@@ -10,6 +10,7 @@ move-blocks.sh
enospc.sh
srch-basic-functionality.sh
simple-xattr-unit.sh
worm-xattr-unit.sh
totl-xattr-tag.sh
lock-refleak.sh
lock-shrink-consistency.sh
+84
View File
@@ -0,0 +1,84 @@
t_require_commands touch rm setfattr
touch "$T_D0/file-1"
SECS=$(date '+%s')
NSECS=$(date '+%N')
DELAY=10
EXP=$(( $SECS + $DELAY ))
EXP_DELAY=$(( $DELAY + 2 ))
echo "== test creation of worm xattr without .hide"
setfattr -n scoutfs.worm.v1_expiration -v $EXP.$NSECS "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation of worm xattr on a directory"
setfattr -n scoutfs.worm.v1_expiration -v $EXP.$NSECS "$T_D0" 2>&1 | t_filter_fs
echo "== test creation of worm xattr"
setfattr -n scoutfs.hide.worm.v1_expiration -v $EXP.$NSECS "$T_D0/file-1"
echo "== test value is set correctly"
diff -u --ignore-all-space <(echo "$EXP.$NSECS") <(getfattr --absolute-names --only-values -n scoutfs.hide.worm.v1_expiration -m - "$T_D0/file-1")
echo "== test deletion of xattr 1 sec after setting"
sleep 1
setfattr -x scoutfs.hide.worm.v1_expiration "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test setting xattr to a previous time after setting"
setfattr -n scoutfs.hide.worm.v1_expiration -v $SECS.$NSECS "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test deletion before expiration"
rm -f "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== Try to move the file prior to expiration"
mv $T_D0/file-1 $T_D0/file-2 2>&1 | t_filter_fs
echo "== Try to write to file before expiration"
date >> $T_D0/file-1
echo "== wait til expiration"
sleep $EXP_DELAY
echo "== Try to write to file after expiration"
date >> $T_D0/file-1
echo "== Try to move the file after expiration"
mv $T_D0/file-1 $T_D0/file-2
mv $T_D0/file-2 $T_D0/file-1
echo "== test deletion after expiration"
setfattr -x scoutfs.hide.worm.v1_expiration "$T_D0/file-1"
echo "== test creation with non integer value of a.a"
setfattr -n scoutfs.hide.worm.v1_expiration -v a.a "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with non integer value of ...."
setfattr -n scoutfs.hide.worm.v1_expiration -v .... "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with non integer value of ..."
setfattr -n scoutfs.hide.worm.v1_expiration -v ... "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with no nsec value of 11."
setfattr -n scoutfs.hide.worm.v1_expiration -v 11. "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with no sec value of .11"
setfattr -n scoutfs.hide.worm.v1_expiration -v .11 "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with . at start and end value .11."
setfattr -n scoutfs.hide.worm.v1_expiration -v .11. "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with invalid format of two characters"
setfattr -n scoutfs.hide.worm.v1_expiration -v 11 "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with too large of a nsecs value 1.18446744073709551615"
setfattr -n scoutfs.hide.worm.v1_expiration -v 1.18446744073709551615 "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with nsecs > NSECS_PER_SEC value 1.1000000000"
setfattr -n scoutfs.hide.worm.v1_expiration -v 1.1000000000 "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== test creation with sec > U64_MAX value of 184467440737095516159.1"
setfattr -n scoutfs.hide.worm.v1_expiration -v 184467440737095516159.1 "$T_D0/file-1" 2>&1 | t_filter_fs
echo "== removing files after expiration"
rm -f "$T_D0/file-1"
t_pass