From 78ee1c72c670a71bfd165448676fc65bff802916 Mon Sep 17 00:00:00 2001 From: gramanas Date: Mon, 19 Nov 2018 19:11:06 +0200 Subject: Add ability to use ck without secret dir --- test/00_init | 24 --------------- test/01_add | 48 ----------------------------- test/02_list | 27 ---------------- test/03_delete | 55 --------------------------------- test/04_search | 22 ------------- test/05_restore | 46 ---------------------------- test/06_edit | 83 -------------------------------------------------- test/add.sh | 48 +++++++++++++++++++++++++++++ test/delete.sh | 55 +++++++++++++++++++++++++++++++++ test/edit.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/init.sh | 24 +++++++++++++++ test/init_no_secret.sh | 38 +++++++++++++++++++++++ test/list.sh | 27 ++++++++++++++++ test/restore.sh | 46 ++++++++++++++++++++++++++++ test/search.sh | 22 +++++++++++++ 15 files changed, 343 insertions(+), 305 deletions(-) delete mode 100644 test/00_init delete mode 100644 test/01_add delete mode 100644 test/02_list delete mode 100644 test/03_delete delete mode 100644 test/04_search delete mode 100644 test/05_restore delete mode 100644 test/06_edit create mode 100644 test/add.sh create mode 100644 test/delete.sh create mode 100644 test/edit.sh create mode 100644 test/init.sh create mode 100644 test/init_no_secret.sh create mode 100644 test/list.sh create mode 100644 test/restore.sh create mode 100644 test/search.sh (limited to 'test') diff --git a/test/00_init b/test/00_init deleted file mode 100644 index a38c81c..0000000 --- a/test/00_init +++ /dev/null @@ -1,24 +0,0 @@ -#!/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 >&${V} & -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 > /dev/null 2>&1 -echo -e $PASS diff --git a/test/01_add b/test/01_add deleted file mode 100644 index 05cf13f..0000000 --- a/test/01_add +++ /dev/null @@ -1,48 +0,0 @@ -#!/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 >&${V} & - 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 [ "$($BIN/ck -c $BIN ls -p $1)" != "$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 deleted file mode 100644 index e330dad..0000000 --- a/test/02_list +++ /dev/null @@ -1,27 +0,0 @@ -#!/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 deleted file mode 100644 index 7e31d66..0000000 --- a/test/03_delete +++ /dev/null @@ -1,55 +0,0 @@ -#!/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 prog1 `basename $path1` >&${V} & -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 prog1 `basename $path2` >&${V} & -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 >&${V} & -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 deleted file mode 100644 index a315730..0000000 --- a/test/04_search +++ /dev/null @@ -1,22 +0,0 @@ -#!/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" - -# search -if [[ $($BIN/ck -c $BIN search search-term | wc -l) != 4 ]]; then - err "search failed." -fi - -clear_tests -echo -e $PASS diff --git a/test/05_restore b/test/05_restore deleted file mode 100644 index 2d60cb9..0000000 --- a/test/05_restore +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -init restore - -# 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 prog1 links -rm "$path1" "$path2" - -# restore them -exec $BIN/ck -c $BIN restore -p prog1 >&${V} & -wait $! - -for i in $($BIN/ck -c $BIN list -p prog1); do - if [[ ! -L "$i" ]]; then - err "Couldn't restore path $i" - exit 1 - fi -done - -## delete all links -rm "$path1" "$path2" "$path3" "$path4" - -# restore all -exec $BIN/ck -c $BIN restore all >&${V} & -wait $! - -for i in $($BIN/ck -c $BIN list paths); do - if [[ ! -L "$i" ]]; then - err "Couldn't restore path $i" - exit 1 - fi -done - -clear_tests -echo -e $PASS diff --git a/test/06_edit b/test/06_edit deleted file mode 100644 index 65419b1..0000000 --- a/test/06_edit +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash - -init edit - -# add configs to ck -path1=$BIN/test1.conf -path2=$BIN/test2.conf -path3=$BIN/test3.conf -path4=$BIN/test4.conf -path5=$BIN/test5.conf - -add_config prog1 $path1 "" -p -add_config prog1 $path2 - -add_config prog2 $path3 -add_config prog2 $path4 - -add_config prog3 $path5 - -# edit primary -exec $BIN/ck -c $BIN e prog1 --command ":" > __test_file & -wait $! - -TEST_STR=$(cat __test_file) -EXPECTED_STR="Running: : $(realpath $path1)" - -echo "Expected: $EXPECTED_STR" >&${V} -echo " Actual: $TEST_STR" >&${V} - -if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then - err "Worng edit." - exit 1; -fi - -# edit specific -exec $BIN/ck -c $BIN e prog1 test2.conf --command ":" > __test_file & -wait $! - -echo "Expected: $EXPECTED_STR" >&${V} -echo " Actual: $TEST_STR" >&${V} - -TEST_STR=$(cat __test_file) -EXPECTED_STR="Running: : $(realpath $path2)" - -if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then - err "Worng edit." - exit 1; -fi - -# Ambiguous config -exec $BIN/ck -c $BIN e prog2 --command ":" > __test_file & -wait $! - -echo "Expected: $EXPECTED_STR" >&${V} -echo " Actual: $TEST_STR" >&${V} - -TEST_STR=$(head -1 __test_file) -EXPECTED_STR="Ambiguous config. Please type the config name after the program." - -if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then - err "Worng edit." - exit 1; -fi - -# solo program -exec $BIN/ck -c $BIN e prog3 --command ":" > __test_file & -wait $! - -echo "Expected: $EXPECTED_STR" >&${V} -echo " Actual: $TEST_STR" >&${V} - -TEST_STR=$(cat __test_file) -EXPECTED_STR="Running: : $(realpath $path5)" - -if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then - err "Worng edit." - exit 1; -fi - -rm __test_file - -clear_tests -echo -e $PASS diff --git a/test/add.sh b/test/add.sh new file mode 100644 index 0000000..05cf13f --- /dev/null +++ b/test/add.sh @@ -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 >&${V} & + 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 [ "$($BIN/ck -c $BIN ls -p $1)" != "$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/delete.sh b/test/delete.sh new file mode 100644 index 0000000..7e31d66 --- /dev/null +++ b/test/delete.sh @@ -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 prog1 `basename $path1` >&${V} & +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 prog1 `basename $path2` >&${V} & +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 >&${V} & +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/edit.sh b/test/edit.sh new file mode 100644 index 0000000..65419b1 --- /dev/null +++ b/test/edit.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +init edit + +# add configs to ck +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf +path4=$BIN/test4.conf +path5=$BIN/test5.conf + +add_config prog1 $path1 "" -p +add_config prog1 $path2 + +add_config prog2 $path3 +add_config prog2 $path4 + +add_config prog3 $path5 + +# edit primary +exec $BIN/ck -c $BIN e prog1 --command ":" > __test_file & +wait $! + +TEST_STR=$(cat __test_file) +EXPECTED_STR="Running: : $(realpath $path1)" + +echo "Expected: $EXPECTED_STR" >&${V} +echo " Actual: $TEST_STR" >&${V} + +if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then + err "Worng edit." + exit 1; +fi + +# edit specific +exec $BIN/ck -c $BIN e prog1 test2.conf --command ":" > __test_file & +wait $! + +echo "Expected: $EXPECTED_STR" >&${V} +echo " Actual: $TEST_STR" >&${V} + +TEST_STR=$(cat __test_file) +EXPECTED_STR="Running: : $(realpath $path2)" + +if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then + err "Worng edit." + exit 1; +fi + +# Ambiguous config +exec $BIN/ck -c $BIN e prog2 --command ":" > __test_file & +wait $! + +echo "Expected: $EXPECTED_STR" >&${V} +echo " Actual: $TEST_STR" >&${V} + +TEST_STR=$(head -1 __test_file) +EXPECTED_STR="Ambiguous config. Please type the config name after the program." + +if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then + err "Worng edit." + exit 1; +fi + +# solo program +exec $BIN/ck -c $BIN e prog3 --command ":" > __test_file & +wait $! + +echo "Expected: $EXPECTED_STR" >&${V} +echo " Actual: $TEST_STR" >&${V} + +TEST_STR=$(cat __test_file) +EXPECTED_STR="Running: : $(realpath $path5)" + +if [[ "$TEST_STR" != "$EXPECTED_STR" ]]; then + err "Worng edit." + exit 1; +fi + +rm __test_file + +clear_tests +echo -e $PASS diff --git a/test/init.sh b/test/init.sh new file mode 100644 index 0000000..a38c81c --- /dev/null +++ b/test/init.sh @@ -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 >&${V} & +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 > /dev/null 2>&1 +echo -e $PASS diff --git a/test/init_no_secret.sh b/test/init_no_secret.sh new file mode 100644 index 0000000..b135377 --- /dev/null +++ b/test/init_no_secret.sh @@ -0,0 +1,38 @@ +running init_no_secret + +mkdir -p $TEST_LOCATION/vc + +exec $BIN/ck -c $BIN init $TEST_LOCATION/vc >&${V} & +wait $! + +if [ $? -ne 0 ]; then + err "ck crashed." +fi + +if [ ! -f $BIN/ckrc ]; then + err "Config file not created." +fi + +if [ "$(sqlite3 $BIN/ckdb "select VAL from CONTEXT where KEY = 'secret_enabled';")" != "0" ]; then + err "secret_enabled should be 0." +fi + +# setup test configs +echo "Test 1" > $BIN/test1.conf + +exec $BIN/ck -c $BIN add prog1 test1.conf -s >&${V} & +wait $! + +if [ $? -eq 0 ]; then + err "Adding secret should fail" +fi + +exec $BIN/ck -c $BIN add prog1 test1.conf >&${V} & +wait $! + +if [ $? -ne 0 ]; then + err "ck crashed." +fi + +clear_tests > /dev/null 2>&1 +echo -e $PASS diff --git a/test/list.sh b/test/list.sh new file mode 100644 index 0000000..e330dad --- /dev/null +++ b/test/list.sh @@ -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/restore.sh b/test/restore.sh new file mode 100644 index 0000000..2d60cb9 --- /dev/null +++ b/test/restore.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +init restore + +# 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 prog1 links +rm "$path1" "$path2" + +# restore them +exec $BIN/ck -c $BIN restore -p prog1 >&${V} & +wait $! + +for i in $($BIN/ck -c $BIN list -p prog1); do + if [[ ! -L "$i" ]]; then + err "Couldn't restore path $i" + exit 1 + fi +done + +## delete all links +rm "$path1" "$path2" "$path3" "$path4" + +# restore all +exec $BIN/ck -c $BIN restore all >&${V} & +wait $! + +for i in $($BIN/ck -c $BIN list paths); do + if [[ ! -L "$i" ]]; then + err "Couldn't restore path $i" + exit 1 + fi +done + +clear_tests +echo -e $PASS diff --git a/test/search.sh b/test/search.sh new file mode 100644 index 0000000..a315730 --- /dev/null +++ b/test/search.sh @@ -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" + +# search +if [[ $($BIN/ck -c $BIN search search-term | wc -l) != 4 ]]; then + err "search failed." +fi + +clear_tests +echo -e $PASS -- cgit v1.2.3