]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/rgw: add static testing for `ceph-diff-sorted`
authorJ. Eric Ivancich <ivancich@redhat.com>
Mon, 30 Mar 2020 21:00:44 +0000 (17:00 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Mon, 4 May 2020 17:55:00 +0000 (13:55 -0400)
Tests are run during "make check".

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/test/rgw/CMakeLists.txt
src/test/rgw/test-ceph-diff-sorted.sh [new file with mode: 0755]

index b3dfd76e39ffea640735f461913491501f85474f..b96b06f3a13e1c8ce5d6d7f5f097b61fd177ee88 100644 (file)
@@ -201,3 +201,6 @@ target_link_libraries(unittest_rgw_url ${rgw_libs})
 add_executable(ceph_test_rgw_gc_log test_rgw_gc_log.cc $<TARGET_OBJECTS:unit-main>)
 target_link_libraries(ceph_test_rgw_gc_log ${rgw_libs} radostest-cxx)
 install(TARGETS ceph_test_rgw_gc_log DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+add_ceph_test(test-ceph-diff-sorted.sh
+  ${CMAKE_CURRENT_SOURCE_DIR}/test-ceph-diff-sorted.sh)
diff --git a/src/test/rgw/test-ceph-diff-sorted.sh b/src/test/rgw/test-ceph-diff-sorted.sh
new file mode 100755 (executable)
index 0000000..dddf4ae
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+
+# set -e -x
+
+. "`dirname $0`/test-rgw-common.sh"
+
+temp_prefix="/tmp/`basename $0`-$$"
+
+short=${temp_prefix}-short
+short_w_blank=${temp_prefix}-short-w-blank
+long=${temp_prefix}-long
+unsorted=${temp_prefix}-unsorted
+empty=${temp_prefix}-empty
+fake=${temp_prefix}-fake
+
+out1=${temp_prefix}-out1
+out2=${temp_prefix}-out2
+
+cat >"${short}" <<EOF
+bear
+fox
+hippo
+zebra
+EOF
+
+cat >"${short_w_blank}" <<EOF
+bear
+fox
+hippo
+
+zebra
+EOF
+
+cat >"${long}" <<EOF
+badger
+cuttlefish
+fox
+llama
+octopus
+penguine
+seal
+squid
+whale
+yak
+zebra
+EOF
+
+cat >"${unsorted}" <<EOF
+bear
+hippo
+fox
+zebra
+EOF
+
+touch $empty
+
+#### testing ####
+
+# test perfect match
+ceph-diff-sorted $long $long >"${out1}"
+$assert $? -eq 0
+$assert $(cat $out1 | wc -l) -eq 0
+
+# test non-match; use /bin/diff to verify
+/bin/diff $short $long >"${out2}"
+ceph-diff-sorted $short $long >"${out1}"
+$assert $? -eq 1
+$assert $(cat $out1 | grep '^<' | wc -l) -eq $(cat $out2 | grep '^<' | wc -l)
+$assert $(cat $out1 | grep '^>' | wc -l) -eq $(cat $out2 | grep '^>' | wc -l)
+
+/bin/diff $long $short >"${out2}"
+ceph-diff-sorted $long $short >"${out1}"
+$assert $? -eq 1
+$assert $(cat $out1 | grep '^<' | wc -l) -eq $(cat $out2 | grep '^<' | wc -l)
+$assert $(cat $out1 | grep '^>' | wc -l) -eq $(cat $out2 | grep '^>' | wc -l)
+
+# test w blank line
+ceph-diff-sorted $short $short_w_blank 2>/dev/null
+$assert $? -eq 4
+
+ceph-diff-sorted $short_w_blank $short 2>/dev/null
+$assert $? -eq 4
+
+# test unsorted input
+ceph-diff-sorted $short $unsorted >"${out2}" 2>/dev/null
+$assert $? -eq 4
+
+ceph-diff-sorted $unsorted $short >"${out2}" 2>/dev/null
+$assert $? -eq 4
+
+# test bad # of args
+ceph-diff-sorted 2>/dev/null
+$assert $? -eq 2
+
+ceph-diff-sorted $short 2>/dev/null
+$assert $? -eq 2
+
+# test bad file path
+
+ceph-diff-sorted $short $fake 2>/dev/null
+$assert $? -eq 3
+
+ceph-diff-sorted $fake $short 2>/dev/null
+$assert $? -eq 3
+
+#### clean-up ####
+
+/bin/rm -f $short $short_w_blank $long $unsorted $empty $out1 $out2