test_dir="@abs_top_srcdir@/src/bin/admin/tests"
script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
- output_file="$test_dir/data/lease4_dump_test.output.csv"
- tmp_file="$test_dir/data/lease4_dump_test.output.csv.tmp"
+ output_file="$test_dir/data/mysql.lease4_dump_test.output.csv"
+ tmp_file="$output_file.tmp"
ref_file="$test_dir/data/mysql.lease4_dump_test.reference.csv"
# wipe out any residuals from prior failed runs
# Ok, now let's initalize the database
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $script_dir
ERRCODE=$?
- assert_eq 0 $ERRCODE "could not create database, status code %d"
+ assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
# Insert the reference record
insert_sql="\
mysql_execute "$insert_sql"
ERRCODE=$?
- assert_eq 0 $ERRCODE "insert into lease4 failed, status code %d"
+ assert_eq 0 $ERRCODE "insert into lease4 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file
${keaadmin} lease-dump mysql -4 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
ERRCODE=$?
- assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, status code %d"
+ assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical
cmp -s $output_file $ref_file
ERRCODE=$?
- assert_eq 0 $ERRCODE "dump file does not match reference file"
+ assert_eq 0 $ERRCODE "dump file does not match reference file, expected exit code %d, actual %d"
# remove the output file
rm $output_file
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
- output_file="$test_dir/data/lease6_dump_test.output.csv"
- tmp_file="$test_dir/data/lease6_dump_test.output.csv.tmp"
+ output_file="$test_dir/data/mysql.lease6_dump_test.output.csv"
+ tmp_file="$output_file.tmp"
ref_file="$test_dir/data/mysql.lease6_dump_test.reference.csv"
# wipe out any residuals from prior failed runs
# Ok, now let's initalize the database
${keaadmin} lease-init mysql -u $db_user -p $db_password -n $db_name -d $script_dir
ERRCODE=$?
- assert_eq 0 $ERRCODE "could not create database, status code %d"
+ assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
# Insert the reference record
insert_sql="\
mysql_execute "$insert_sql"
ERRCODE=$?
- assert_eq 0 $ERRCODE "insert into lease6 failed, status code %d"
+ assert_eq 0 $ERRCODE "insert into lease6 failed, expected exit code %, actual %d"
# Dump lease4 to output_file
${keaadmin} lease-dump mysql -6 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
# Compare the dump output to reference file, they should be identical
cmp -s $output_file $ref_file
ERRCODE=$?
- assert_eq 0 $ERRCODE "dump file does not match reference file"
+ assert_eq 0 $ERRCODE "dump file does not match reference file, expected exit code %, actual %d"
# remove the output file
rm $output_file
# Make a set of drop commands, one for each table owned by keatest
RESULT=`pgsql_execute "SELECT 'drop table if exists '||t.tablename || ' cascade;' as dcmd FROM pg_catalog.pg_tables t WHERE t.tableowner = 'keatest';"`
assert_eq 0 $? "pgsql_wipe select failed, expected exit code: %d, actual: %d"
+
# Now execute the set of drop commands from the result set returned
RESULT=`pgsql_execute "$RESULT"`
assert_eq 0 $? "pgsql_wipe drop failed, expected exit code: %d, actual: %d"
test_finish 0
}
+# Test verifies the ability to dump lease4 data to CSV file
+# The dump output file is compared against a reference file.
+# If the dump is successful, the file contents will be the
+# same. Note that the expire field in the lease4 table
+# is of data type "timestamp with timezone". This means that
+# the dumped file content is dependent upon the timezone
+# setting the PostgreSQL server is using. To account for
+# this the reference data contains a tag, "<timestamp>"
+# where the expire column's data would normally be. This
+# tag is replaced during text execution with a value
+# determined by querying the PostgreSQL server. This
+# updated reference data is captured in a temporary file
+# which is used for the actual comparison.
+pgsql_lease4_dump_test() {
+ test_start "pgsql.lease4_dump_test"
+
+ test_dir="@abs_top_srcdir@/src/bin/admin/tests"
+ script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
+ output_file="$test_dir/data/pgsql.lease4_dump_test.output.csv"
+ ref_file="$test_dir/data/pgsql.lease4_dump_test.reference.csv"
+ ref_file_tmp=$ref_file.tmp
+
+ # wipe out any residuals from prior failed runs
+ if [ -e $output_file ]
+ then
+ rm $output_file
+ fi
+
+ if [ -e $ref_file_tmp ]
+ then
+ rm $ref_file_tmp
+ fi
+
+ # Let's wipe the whole database
+ pgsql_wipe
+
+ # Ok, now let's initalize the database
+ ${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $script_dir
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "could not create database, expected exit code %d, actual %d"
+
+ # Insert the reference records
+ insert_sql="\
+insert into lease4 values(10,E'\\x20',E'\\x30',40,'2001-01-01 00:00:00',50,'t','t','one.example.com');\
+insert into lease4 values(11,'',E'\\x0123',40,'2001-01-01 00:00:00',50,'t','t','');\
+insert into lease4 values(12,E'\\x22','',40,'2001-01-01 00:00:00',50,'t','t','three.example.com');"
+
+ pgsql_execute "$insert_sql"
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "insert into lease4 failed, expected exit code %d, actual %d"
+
+ # Dump lease4 to output_file
+ ${keaadmin} lease-dump pgsql -4 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "kea-admin lease-dump -4 failed, status code %d"
+
+ # Expiration field is a "timestamp with timezone" so we need a reference
+ # time for the machine/DB this test is running upon.
+ ref_timestamp=`pgsql_execute "SELECT timestamptz '2001-01-01 00:00:00';"`
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "reference time query failed, expected exit code %d, actual %d"
+ printf "reference timestamp is [$ref_timestamp]\n"
+
+ # Create the comparison file by replacing the <timestamp> tags
+ # with the local reference timestamp
+ sedstr="'s/<timestamp>/$ref_timestamp/g'"
+ eval sed $sedstr $ref_file >$ref_file_tmp
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "timestamp replacement failed, expected exit code %d, actual %d"
+
+ # Compare the dump output to reference file, they should be identical
+ cmp -s $output_file $ref_file_tmp
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "dump file does not match reference file, expected exit code %d, actual %d"
+
+ # Remove the output file and temporary reference file
+ rm $output_file
+ rm $ref_file_tmp
+
+ # Let's wipe the whole database
+ pgsql_wipe
+
+ test_finish 0
+}
+
+# Test verifies the ability to dump lease6 data to CSV file
+# The dump output file is compared against a reference file.
+# If the dump is successful, the file contents will be the
+# same. Note that the expire field in the lease6 table
+# is of data type "timestamp with timezone". This means that
+# the dumped file content is dependent upon the timezone
+# setting the PostgreSQL server is using. To account for
+# this the reference data contains a tag, "<timestamp>"
+# where the expire column's data would normally be. This
+# tag is replaced during text execution with a value
+# determined by querying the PostgreSQL server. This
+# updated reference data is captured in a temporary file
+# which is used for the actual comparison.
+pgsql_lease6_dump_test() {
+ test_start "pgsql.lease6_dump_test"
+
+ test_dir="@abs_top_srcdir@/src/bin/admin/tests"
+ script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
+ output_file="$test_dir/data/pgsql.lease6_dump_test.output.csv"
+ ref_file="$test_dir/data/pgsql.lease6_dump_test.reference.csv"
+ ref_file_tmp=$ref_file.tmp
+
+ # wipe out any residuals from prior failed runs
+ if [ -e $output_file ]
+ then
+ rm $output_file
+ fi
+
+ if [ -e $ref_file_tmp ]
+ then
+ rm $ref_file_tmp
+ fi
+
+ # Let's wipe the whole database
+ pgsql_wipe
+
+ # Ok, now let's initalize the database
+ ${keaadmin} lease-init pgsql -u $db_user -p $db_password -n $db_name -d $script_dir
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "could not create database, status code %d"
+
+ # Insert the reference records
+ insert_sql="\
+insert into lease6 values(10,E'\\x20',30,'2001-01-01 00:00:00',40,50,1,60,70,'t','t','one.example.com');\
+insert into lease6 values(11,'',30,'2001-01-01 00:00:00',40,50,1,60,70,'t','t','');\
+insert into lease6 values(12,E'\\x21',30,'2001-01-01 00:00:00',40,50,1,60,70,'t','t','three.example.com');"
+
+ pgsql_execute "$insert_sql"
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "insert into lease6 failed, status code %d"
+
+ # Dump lease6 to output_file
+ ${keaadmin} lease-dump pgsql -6 -u $db_user -p $db_password -n $db_name -d $script_dir -o $output_file
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "kea-admin lease-dump -6 failed, status code %d"
+
+ # Expiration field is a "timestamp with timezone" so we need a reference
+ # time for the machine/DB this test is running upon.
+ ref_timestamp=`pgsql_execute "SELECT timestamptz '2001-01-01 00:00:00';"`
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "reference time query failed, expected exit code %d, actual %d"
+ printf "reference timestamp is [$ref_timestamp]\n"
+
+ # Create the comparison file by replacing the <timestamp> tags
+ # with the local reference timestamp
+ sedstr="'s/<timestamp>/$ref_timestamp/g'"
+ eval sed $sedstr $ref_file >$ref_file_tmp
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "timestamp replacement failed, expected exit code %d, actual %d"
+
+ # Compare the dump output to reference file, they should be identical
+ cmp -s $output_file $ref_file_tmp
+ ERRCODE=$?
+ assert_eq 0 $ERRCODE "dump file does not match reference file"
+
+ # Remove the output file and temporary reference file
+ rm $output_file
+ rm $ref_file_tmp
+
+ # Let's wipe the whole database
+ pgsql_wipe
+
+ test_finish 0
+}
+
pgsql_lease_init_test
pgsql_lease_version_test
pgsql_upgrade_test
+pgsql_lease4_dump_test
+pgsql_lease6_dump_test