More test cases

This commit is contained in:
2022-03-21 22:45:28 +01:00
parent cac8014f15
commit 5cea7b4198

View File

@@ -16,10 +16,19 @@ _tc_tmp="${test_dir:-"/tmp"}/tmp_compete"
# Compete test suites (arrays) # Compete test suites (arrays)
compete_canonicalize=( "Canonicalize invalid path" compete_canonicalize=( "Canonicalize invalid path"
"-v" # Not recommended file naming
"///tmp//./b" "///tmp//./b"
#"//tmp//./b/.." # TODO return empty "//tmp//./b/.."
#"//tmp//./b/." # TODO return empty "//tmp//./b/."
"//tmp//./b/"
"///notthere//...../help/."
)
compete_relative=( "Resolving of relative links"
# Invalid
"nofile_l"
"nopath_l"
# Valid
"dir_1/file" # Valid relative link to path with relative element
) )
compete_all=( "Test - everything starting from /" compete_all=( "Test - everything starting from /"
@@ -30,12 +39,18 @@ compete_all=( "Test - everything starting from /"
tocompete_init() { tocompete_init() {
# initialize custom test structure # initialize custom test structure
{ {
tocompete_clean
mkdir -p "${_tc_tmp}" mkdir -p "${_tc_tmp}"
cd "${_tc_tmp}"
# compete_links # compete_links
touch "${_tc_tmp}/a" touch "${_tc_tmp}/a"
ln -s "${_tc_tmp}/a" "${_tc_tmp}/a 2" ln -s "${_tc_tmp}/a" "${_tc_tmp}/a 2"
ln -s "${_tc_tmp}/a 2" "${_tc_tmp}/a 3" ln -s "${_tc_tmp}/a 2" "${_tc_tmp}/a 3"
mkdir -p "dir_1"
mkdir -p "dir_2/dir_22"
touch "dir_2/dir_22/file"
ln -s "dir_2/dir_22" "dir_3_l"
ln -s "../dir_3_l/file" "dir_1/file"
# compete_no_permission # compete_no_permission
mkdir -p "${_tc_tmp}/noperm" mkdir -p "${_tc_tmp}/noperm"
@@ -43,14 +58,19 @@ tocompete_init() {
ln -s "noperm" "${_tc_tmp}/noperml" ln -s "noperm" "${_tc_tmp}/noperml"
ln -s "/" "${_tc_tmp}/lroot" ln -s "/" "${_tc_tmp}/lroot"
ln -s "/root" "${_tc_tmp}/lroothome" ln -s "/root" "${_tc_tmp}/lroothome"
# compete_relative
ln -s "../nofile" "${_tc_tmp}/nofile_l"
ln -s "../nodir/nofile" "${_tc_tmp}/nopath_l"
#echo "rl: " && readlink "${_tc_tmp}/lnoperm" #echo "rl: " && readlink "${_tc_tmp}/lnoperm"
#ls -l "${_tc_tmp}" #ls -l "${_tc_tmp}"
} }
# Base directory for the test # Base directory for the test
cd "${_tc_tmp}" cd "${_tc_tmp}"
# Compete test arrays with "dynamic" cases need to be inside the init function # Compete test arrays with "dynamic" cases need to be inside the init function
# e.g. "$(cd ../test && pwd)/file" - base directory must be set first # e.g. "$(cd ../test && pwd)/file" - base directory must be set first
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first # e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
@@ -58,33 +78,40 @@ tocompete_init() {
"${_tc_tmp}/invalid_file" "${_tc_tmp}/invalid_file"
"/invalid_file" "/invalid_file"
"/invalid_direcotry/invalidfile" "/invalid_direcotry/invalidfile"
"-v" # Not recommended file naming
"../-v" # Not recommended file naming
"-v/.." # Not recommended file naming
) )
compete_links=( "Test - Valid links" compete_links=( "Test - Valid links"
"${_tc_tmp}/a 3" # slink chain a3 -> a2 -> a "${_tc_tmp}/a 3" # slink chain a3 -> a2 -> a
"${_tc_tmp}/a"* "${_tc_tmp}/a"*
"/dev/stdin" "/dev/stdin"
"/bin/adb" #"/dev/stdout" skip - Always different
"/dev/fd" # Test skip - /dev/fd is different on every call #"/dev/fd" # Test skip - /dev/fd is different on every call
"/dev/stdout" # skip - different output #"/etc/mtab" # skip - Always different
"/etc/mtab" # skip - Always different #"/proc/mounts" # skip - Always different
"/proc/mounts" # skip - Always different #"/proc/net/"* # skip - Always different
"/proc/net/"* # skip - Always different
) )
compete_no_permission=( "No permission to enter directory (direct and link)" compete_no_permission=( "No permission to enter directory (direct and link)"
"/proc/"**/cwd # special - no permission for links
"noperm"* "noperm"*
"lroot"* "lroot"*
"/" "/"
"/root"
"/root/"
"/root/."
"/root/.."
"/proc/"**/cwd # special - no permission for links
) )
# Add tests to global test array from test_rdlink # Add tests to global test array from test_rdlink
tocompete+=( tocompete+=(
compete_invalid
compete_links
compete_no_permission
compete_canonicalize compete_canonicalize
compete_invalid
compete_relative
compete_no_permission
compete_links
compete_all compete_all
) )
} }