diff --git a/tests/Makefile.am b/tests/Makefile.am index fba09319..60596173 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,4 +10,4 @@ check_baton_SOURCES = check_baton.c $(top_builddir)/src/baton.h check_baton_CFLAGS = @CHECK_CFLAGS@ check_baton_LDADD = $(top_builddir)/src/libbaton.la @CHECK_LIBS@ -EXTRA_DIST = data metadata scripts +EXTRA_DIST = data metadata scripts sql diff --git a/tests/check_baton.c b/tests/check_baton.c index 4b621e89..93b4fcf7 100644 --- a/tests/check_baton.c +++ b/tests/check_baton.c @@ -37,9 +37,13 @@ static int MAX_PATH_LEN = 4096; static char *BASIC_COLL = "baton-basic-test"; static char *BASIC_DATA_PATH = "data"; static char *BASIC_METADATA_PATH = "metadata/meta1.imeta"; +static char *SQL_PATH = "sql/specific_queries.sql"; -static char *SETUP_SCRIPT = "scripts/setup_irods.sh"; -static char *TEARDOWN_SCRIPT = "scripts/teardown_irods.sh"; +static char *SETUP_SCRIPT = "scripts/setup_irods.sh"; +static char *SQL_SETUP_SCRIPT = "scripts/setup_sql.sh"; + +static char *TEARDOWN_SCRIPT = "scripts/teardown_irods.sh"; +static char *SQL_TEARDOWN_SCRIPT = "scripts/teardown_sql.sh"; static void set_current_rods_root(char *in, char *out) { rodsEnv rodsEnv; @@ -55,10 +59,34 @@ static void set_current_rods_root(char *in, char *out) { static void setup() { set_log_threshold(WARN); + + char command[MAX_COMMAND_LEN]; + char rods_root[MAX_PATH_LEN]; + set_current_rods_root(BASIC_COLL, rods_root); + + snprintf(command, MAX_COMMAND_LEN, "%s/%s %s/%s", + TEST_ROOT, SQL_SETUP_SCRIPT, + TEST_ROOT, SQL_PATH); + + printf("Setup: %s\n", command); + int ret = system(command); + + if (ret != 0) raise(SIGTERM); } static void teardown() { + char command[MAX_COMMAND_LEN]; + char rods_root[MAX_PATH_LEN]; + set_current_rods_root(BASIC_COLL, rods_root); + + snprintf(command, MAX_COMMAND_LEN, "%s/%s %s/%s", + TEST_ROOT, SQL_TEARDOWN_SCRIPT, + TEST_ROOT, SQL_PATH); + + printf("Teardown: %s\n", command); + int ret = system(command); + if (ret != 0) raise(SIGINT); } static void basic_setup() { @@ -73,8 +101,7 @@ static void basic_setup() { TEST_RESOURCE, TEST_ROOT, BASIC_METADATA_PATH); - printf("Setup: %s\n", command); - + printf("Data setup: %s\n", command); int ret = system(command); if (ret != 0) raise(SIGTERM); @@ -89,12 +116,18 @@ static void basic_teardown() { TEST_ROOT, TEARDOWN_SCRIPT, rods_root); - printf("Teardown: %s\n", command); + printf("Data teardown: %s\n", command); int ret = system(command); if (ret != 0) raise(SIGINT); } +static int have_rodsadmin() { + char *command = "iuserinfo |grep 'type: rodsadmin'"; + + return system(command); +} + START_TEST(test_str_starts_with) { size_t len = MAX_STR_LEN; ck_assert_msg(str_starts_with("", "", len), "'' starts with ''"); diff --git a/tests/scripts/setup_irods.sh b/tests/scripts/setup_irods.sh index 1ae473a7..add69bc0 100755 --- a/tests/scripts/setup_irods.sh +++ b/tests/scripts/setup_irods.sh @@ -1,8 +1,8 @@ #!/bin/bash # -# This script is run on fixture setup. It copies test data to iRODS -# and if provided with a file of imeta commands, executes imeta to add -# metadata. +# This script is run on checked fixture setup. It copies test data to +# iRODS and if provided with a file of imeta commands, executes imeta +# to add metadata. # E_ARGS_MISSING=3 @@ -79,7 +79,6 @@ then exit $status fi - # Add metadata if required if [[ ! -z "$meta_path" ]] then diff --git a/tests/scripts/setup_sql.sh b/tests/scripts/setup_sql.sh new file mode 100755 index 00000000..2437dab9 --- /dev/null +++ b/tests/scripts/setup_sql.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# This script is run on unchecked fixture setup. It installs iRODS +# specific query SQL if rodsadmin is available. +# + +E_ARGS_MISSING=3 +E_INPUT_MISSING=4 + +sql_path=$1 + +if [ $# -lt 1 ] +then + echo "Insufficient command line arguments; expected 1" + exit $E_ARGS_MISSING +fi + +if [[ ! -z "$sql_path" ]] +then + if [[ ! -f $sql_path ]] + then + echo "SQL input file '$sql_path' not found. Aborting" + exit $E_INPUT_MISSING + else + # Test for admin capabilities + iuserinfo | grep 'type: rodsadmin' >/dev/null + status=$? + + if [[ $status -eq 0 ]] + then + echo "# Installing specific queries" + awk '{print "asq $s"}' < $sql_path | iadmin >/dev/null + status=$? + + if [[ $status -ne 0 ]] + then + echo "Failed to install SQL in '$sql_path'" + exit $status + fi + else + echo "# Not installing specific queries" + fi + fi +fi diff --git a/tests/scripts/teardown_irods.sh b/tests/scripts/teardown_irods.sh index 69f4c6f3..1f9bc66d 100755 --- a/tests/scripts/teardown_irods.sh +++ b/tests/scripts/teardown_irods.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# This script is run on fixture teardown. It deletes the test data -# from iRODS on a successful result. +# This script is run on checked fixture teardown. It deletes the test +# data from iRODS on a successful result. # E_ARGS_MISSING=3 @@ -15,4 +15,5 @@ then fi irm -rf $in_path + exit diff --git a/tests/scripts/teardown_sql.sh b/tests/scripts/teardown_sql.sh new file mode 100755 index 00000000..3cea6f38 --- /dev/null +++ b/tests/scripts/teardown_sql.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# This script is run on unchecked fixture teardown. It removes iRODS +# specific query SQL if rodsadmin is available. +# + +E_ARGS_MISSING=3 +E_INPUT_MISSING=4 + +sql_path=$1 + +if [[ $# < 1 ]] +then + echo "Insufficient command line arguments; expected 1" + exit $E_ARGS_MISSING +fi + +if [[ ! -z "$sql_path" ]] +then + if [[ ! -f $sql_path ]] + then + echo "SQL input file '$sql_path' not found. Aborting" + exit $E_INPUT_MISSING + else + # Test for admin capabilities + iuserinfo | grep 'type: rodsadmin' >/dev/null + status=$? + + if [[ $status -eq 0 ]] + then + echo "# Removing specific queries" + awk '{print "rsq $s"}' < $sql_path | iadmin >/dev/null + status=$? + + if [[ $status -ne 0 ]] + then + echo "Failed to remove SQL in '$sql_path'" + exit $status + fi + else + echo "# Not removing specific queries" + fi + fi +fi diff --git a/tests/sql/specific_queries.sql b/tests/sql/specific_queries.sql new file mode 100644 index 00000000..e69de29b