diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/00_init | 24 | ||||
-rw-r--r-- | test/01_add | 48 | ||||
-rw-r--r-- | test/02_list | 27 | ||||
-rw-r--r-- | test/03_delete | 55 | ||||
-rw-r--r-- | test/04_search | 22 |
5 files changed, 176 insertions, 0 deletions
diff --git a/test/00_init b/test/00_init new file mode 100644 index 0000000..1f3f2a6 --- /dev/null +++ b/test/00_init @@ -0,0 +1,24 @@ +#!/bin/bash + +running init + +mkdir -p $TEST_LOCATION/vc +mkdir $TEST_LOCATION/sec + +exec $BIN/ck -c $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & +wait $! + +if [ $? -ne 0 ]; then + err "ck crashed." +fi + +if [ ! -f $BIN/ckrc ]; then + err "Config file not created." +fi + +if [ ! -f $BIN/ckdb ]; then + err "DB file not created." +fi + +clear_tests 2&>1 /dev/null +echo -e $PASS diff --git a/test/01_add b/test/01_add new file mode 100644 index 0000000..1de64bf --- /dev/null +++ b/test/01_add @@ -0,0 +1,48 @@ +#!/bin/bash + +init add + +# setup test configs +echo "Test 1" > $BIN/test1.conf +echo "Test 2" > $BIN/test2.conf +echo "Test 3" > $BIN/test3.conf + +function run_add { + # add configs to ck + exec $BIN/ck -c $BIN add $1 $BIN/$2 $3 $4 > /dev/null & + wait $! + + if [ $? -ne 0 ]; then + err "ck crashed." + fi + + # check db + if [ "$(sqlite3 $BIN/ckdb "select name from program where name = '$1'")" != "$1" ]; then + err "$1 is not in the db." + fi + + if [ "$(sqlite3 $BIN/ckdb "select path from config where path = '$BIN/$2'")" != "$BIN/$2" ]; then + err "$2 is not in the db." + fi + + # check files + FOLDER=vc + if [[ "$3" = "-s" || "$4" = "-s" ]]; then + FOLDER=sec + fi + + if [ ! -f $TEST_LOCATION/$FOLDER/$1/$2 ]; then + err "$2 No move (add $3 $4)" + fi + + if [ ! -L $BIN/$2 ]; then + err "$2 No symlink (add $3 $4)" + fi +} + +run_add prog1 test1.conf -p +run_add prog2 test2.conf -s +run_add prog3 test3.conf -p -s + +clear_tests +echo -e $PASS diff --git a/test/02_list b/test/02_list new file mode 100644 index 0000000..e330dad --- /dev/null +++ b/test/02_list @@ -0,0 +1,27 @@ +#!/bin/bash + +init list + +# add configs to ck +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf + +add_config prog1 $path1 +add_config prog2 $path2 +add_config prog3 $path3 + +for i in $($BIN/ck -c $BIN list paths); do + if [[ "$i" != "$path1" ]] && [[ "$i" != "$path2" ]] && [[ "$i" != "$path3" ]]; then + err "Listing paths" + fi +done + +for i in $($BIN/ck -c $BIN list programs); do + if [[ "$i" != "prog1" ]] && [[ "$i" != "prog2" ]] && [[ "$i" != "prog3" ]]; then + err "Listing programs" + fi +done + +clear_tests +echo -e $PASS diff --git a/test/03_delete b/test/03_delete new file mode 100644 index 0000000..1668576 --- /dev/null +++ b/test/03_delete @@ -0,0 +1,55 @@ +#!/bin/bash + +init delete + +# setup test configs +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf +path4=$BIN/test4.conf + +add_config prog1 $path1 +add_config prog1 $path2 + +add_config prog2 $path3 +add_config prog2 $path4 + +# delete path1 +exec $BIN/ck -c $BIN del -c $path1 > /dev/null & +wait $! + +for i in $($BIN/ck -c $BIN list paths); do + if [[ "$i" == "$path1" ]]; then + err "Couldn't delete path." + exit 1 + fi +done + +# delete path2 (also prog1) +exec $BIN/ck -c $BIN del -c $path2 > /dev/null & +wait $! + +for i in $($BIN/ck -c $BIN list programs); do + if [[ "$i" == "prog1" ]]; then + err "Removing all configs should delete the correspondig program." + fi +done + +# delete prog2 +exec $BIN/ck -c $BIN del prog2 > /dev/null & +wait $! + +for i in $($BIN/ck -c $BIN list paths); do + if [[ "$i" == "$path3" ]] || [[ "$i" == "$path4" ]]; then + err "Removing the program should delete all it's configs." + fi +done + +for i in $($BIN/ck -c $BIN list programs); do + if [[ "$i" == "prog1" ]]; then + err "Couldn't remove program." + fi +done + +clear_tests +echo -e $PASS diff --git a/test/04_search b/test/04_search new file mode 100644 index 0000000..c3600c1 --- /dev/null +++ b/test/04_search @@ -0,0 +1,22 @@ +#!/bin/bash + +init search + +# setup test configs +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf +path4=$BIN/test4.conf + +add_config prog1 $path1 "search-term" +add_config prog1 $path2 "search-term" +add_config prog2 $path3 "search-term" +add_config prog3 $path4 "search-term" + +# delete path1 +if [[ $($BIN/ck -c $BIN search search-term | wc -l) != 4 ]]; then + err "search failed." +fi + +clear_tests +echo -e $PASS |