Skip to content

Commit

Permalink
Merge pull request #136 from keithj/sql-query-test
Browse files Browse the repository at this point in the history
Support for setting up iRODS specific query SQL for tests.
  • Loading branch information
dkj committed Oct 14, 2015
2 parents 20a895e + 46ab922 commit 71249cb
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 38 additions & 5 deletions tests/check_baton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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);
Expand All @@ -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 ''");
Expand Down
7 changes: 3 additions & 4 deletions tests/scripts/setup_irods.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -79,7 +79,6 @@ then
exit $status
fi


# Add metadata if required
if [[ ! -z "$meta_path" ]]
then
Expand Down
44 changes: 44 additions & 0 deletions tests/scripts/setup_sql.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions tests/scripts/teardown_irods.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,4 +15,5 @@ then
fi

irm -rf $in_path

exit
44 changes: 44 additions & 0 deletions tests/scripts/teardown_sql.sh
Original file line number Diff line number Diff line change
@@ -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
Empty file added tests/sql/specific_queries.sql
Empty file.

0 comments on commit 71249cb

Please sign in to comment.