Overhaul test scripts: use "servald" instead of "dna"

This commit is contained in:
Andrew Bettison 2012-05-20 13:48:02 +09:30
parent d90508b2ba
commit 4d6c48a68f
6 changed files with 198 additions and 184 deletions

View File

@ -1,63 +1,70 @@
# Common definitions for all test suites in test/*
testdefs_sh=$(abspath "${BASH_SOURCE[0]}")
dna_source_root="${testdefs_sh%/*}"
dna_build_root="$dna_source_root"
servald_source_root="${testdefs_sh%/*}"
servald_build_root="$servald_source_root"
# Utility function for setting up a fixture with a DNA server process:
# - Ensure that no dna processes are running
# - Start a dna server process
# - Ensure that no servald processes are running
# - Start a servald server process
# - Ensure that it is still running after one second
start_dna_server() {
check_no_dna_processes
start_servald_server() {
check_no_servald_processes
# Start DNA server
$dna -v verbose -f $hlr_dat -S 1 -n "$@" >$DNATMP/dna.log 2>&1 &
set -- $servald -v verbose -f $hlr_dat -S -n "$@"
echo "+ run $*"
"$@" >$DNATMP/servald.log 2>&1 &
sleep 1
pid=$(ps -u$UID | awk '$4 == "dna" {print $1}')
local servald_basename="${servald##*/}"
if [ -z "$servald_basename" ]; then
error "cannot run test: \$servald not set"
return 1
fi
pid=$(ps -u$UID | awk '$4 == "'"$servald_basename"'" {print $1}')
if [ -z "$pid" ]; then
echo "dna server did not start"
tfw_cat --header=dna.log $SERVALINSTANCE_PATH/dna.log
echo "servald server did not start"
tfw_cat --header=servald.log $SERVALINSTANCE_PATH/servald.log
fail
fi
if ! [ -s $SERVALINSTANCE_PATH/serval.pid ] && kill -0 $(cat $SERVALINSTANCE_PATH/serval.pid); then
echo "serval.pid was not created"
tfw_cat --header=dna.log $SERVALINSTANCE_PATH/dna.log
tfw_cat --header=servald.log $SERVALINSTANCE_PATH/servald.log
fail
fi
echo "# Started dna server process, pid=$pid"
echo "# Started servald server process, pid=$pid"
}
# Utility function for tearing down DNA fixtures:
# - If a dna server process is running, then kill it
# - Cat any dna log file into the test log
# - Ensure that no dna processes are running
stop_dna_server() {
if [ -s $SERVALINSTANCE_PATH/serval.pid ]; then
local pid=$(cat $SERVALINSTANCE_PATH/serval.pid)
# - If a servald server process is running, then kill it
# - Cat any servald log file into the test log
# - Ensure that no servald processes are running
stop_servald_server() {
if [ -s $SERVALINSTANCE_PATH/servald.pid ]; then
local pid=$(cat $SERVALINSTANCE_PATH/servald.pid)
if kill $pid; then
echo "# Killed dna process pid=$pid"
echo "# Killed servald process pid=$pid"
else
error "# Dna process pid=$pid was not running"
fi
fi
if [ -s $DNATMP/dna.log ]; then
tfw_cat --header=dna.log $DNATMP/dna.log
if [ -s $DNATMP/servald.log ]; then
tfw_cat --header=servald.log $DNATMP/servald.log
fi
check_no_dna_processes
check_no_servald_processes
}
# Utility function for creating DNA fixtures:
# - Create a temporary directory to contain all dna-related files
# - set $dna and $hlr_dat variables
# - Create a temporary directory to contain all servald-related files
# - set $servald and $hlr_dat variables
# - set SERVALINSTANCE_PATH environment variable
# - mkdir $SERVALINSTANCE_PATH unless --no-mkdir option given
setup_dna() {
dna=$(abspath "$dna_build_root/dna") # The DNA executable under test
if ! [ -x "$dna" ]; then
error "dna executable not present: $dna"
setup_servald() {
servald=$(abspath "$servald_build_root/dna") # The DNA executable under test
if ! [ -x "$servald" ]; then
error "servald executable not present: $servald"
return 1
fi
export DNATMP=$TFWTMP/dnatmp
export DNATMP=$TFWTMP/servaldtmp
[ "$1" = --no-mkdir ] || mkdir $DNATMP
export SERVALINSTANCE_PATH=$DNATMP
hlr_dat=$SERVALINSTANCE_PATH/hlr.dat
@ -68,18 +75,23 @@ setup_dna() {
# - check that libservald.so is present
# - set LD_LIBRARY_PATH so that libservald.so can be found
setup_servald_so() {
assert [ -r "$dna_build_root/libservald.so" ]
export LD_LIBRARY_PATH="$dna_build_root"
assert [ -r "$servald_build_root/libservald.so" ]
export LD_LIBRARY_PATH="$servald_build_root"
}
# Utility function for managing DNA fixtures:
# - Ensure there are no existing DNA server processes
check_no_dna_processes() {
local pids=$(ps -u$UID | awk '$4 == "dna" {print $1}')
if [ -n "$pids" ]; then
error "cannot run test: dna process already running with pid: $pids"
check_no_servald_processes() {
local servald_basename="${servald##*/}"
if [ -z "$servald_basename" ]; then
error "cannot run test: \$servald not set"
return 1
fi
echo "# No other dna processes running for uid=$UID"
local pids=$(ps -u$UID | awk '$4 == "'"$servald_basename"'" {print $1}')
if [ -n "$pids" ]; then
error "cannot run test: $servald_basename process already running with pid: $pids"
return 1
fi
echo "# No other $servald_basename processes running for uid=$UID"
return 0
}

View File

@ -23,15 +23,15 @@ source "${0%/*}/../testdefs.sh"
# Default teardown function
teardown() {
stop_dna_server
stop_servald_server
}
# Test case, transcribed from ../testdna
doc_BitErrorCreateSID='Create new SID despite bit errors'
setup_BitErrorCreateSID() {
ber=0.001
setup_dna
start_dna_server -B $ber
setup_servald
start_servald_server -B $ber
}
test_BitErrorCreateSID() {
local iterations=10
@ -40,7 +40,7 @@ test_BitErrorCreateSID() {
local totaltime_ms=0
local maxtime_ms=0
while [ $i -lt $iterations ]; do
executeOk $dna -B $ber -d 0427679796 -C
executeOk $servald -B $ber -d 0427679796 -C
sid=`replayStdout | grep '^OK:' | cut -f2 -d:`
let totaltime_ms=totaltime_ms+realtime_ms
[ $realtime_ms -gt $maxtime_ms ] && maxtime_ms=$realtime_ms
@ -64,16 +64,16 @@ test_BitErrorCreateSID() {
doc_SetVarBigValueBitErrors='Can set variable with multi-packet value despite bit errors'
setup_SetVarBigValueBitErrors() {
ber=0.00001
setup_dna
start_dna_server -B $ber
echo_long_message >$DNATMP/dnatest.in
setup_servald
start_servald_server -B $ber
echo_long_message >$DNATMP/servaldtest.in
}
test_SetVarBigValueBitErrors() {
executeOk $dna -B $ber -s $sid -i 0 -W note="@dnatest.in"
executeOk $servald -B $ber -s $sid -i 0 -W note="@servaldtest.in"
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
executeOk $dna -v verbose -B $ber -s $sid -O $DNATMP/dnatest.out -i 0 -R note
executeOk $servald -v verbose -B $ber -s $sid -O $DNATMP/servaldtest.out -i 0 -R note
assertStdoutGrep --matches=1 --message='variable new value returned' "^NOTE:$sid:[0-9]\+:0"
assert --message='long value read correctly' cmp --quiet $DNATMP/dnatest.in $DNATMP/dnatest.out
assert --message='long value read correctly' cmp --quiet $DNATMP/servaldtest.in $DNATMP/servaldtest.out
}
runTests "$@"

View File

@ -22,48 +22,48 @@ source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
setup() {
setup_dna
setup_servald
}
doc_GetCreateInstanceDir="Get creates instance directory"
setup_GetCreateInstanceDir() {
setup_dna --no-mkdir
setup_servald --no-mkdir
assert [ ! -d $SERVALINSTANCE_PATH ]
}
test_GetCreateInstanceDir() {
executeOk $dna config get
executeOk $servald config get
assert [ -d $SERVALINSTANCE_PATH ]
}
doc_SetCreateInstanceDir="Set creates instance directory"
setup_SetCreateInstanceDir() {
setup_dna --no-mkdir
setup_servald --no-mkdir
assert [ ! -d $SERVALINSTANCE_PATH ]
}
test_SetCreateInstanceDir() {
executeOk $dna config set foo bar
executeOk $servald config set foo bar
assert [ -d $SERVALINSTANCE_PATH ]
}
doc_GetNull="Get an unset config item"
test_GetNull() {
executeOk $dna config get foo
executeOk $servald config get foo
assertStdoutLineCount '==' 0
}
doc_SetGet="Set and get a single config item"
test_SetGet() {
executeOk $dna config set foo bar
executeOk $dna config get foo
executeOk $servald config set foo bar
executeOk $servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
}
doc_GetAll="Get all config items"
test_GetAll() {
executeOk $dna config set foo bar
executeOk $dna config set hello world
executeOk $dna config get
executeOk $servald config set foo bar
executeOk $servald config set hello world
executeOk $servald config get
assertStdoutLineCount '==' 2
assertStdoutGrep --stdout --matches=1 '^foo=bar$'
assertStdoutGrep --stdout --matches=1 '^hello=world$'
@ -71,93 +71,93 @@ test_GetAll() {
doc_SetTwice="Set a single config item twice"
test_SetTwice() {
executeOk $dna config set foo bar
executeOk $dna config get foo
executeOk $servald config set foo bar
executeOk $servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
executeOk $dna config set foo wah
executeOk $dna config get foo
executeOk $servald config set foo wah
executeOk $servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=wah$'
}
doc_DelNull="Delete an unset config item"
test_DelNull() {
executeOk $dna config del foo
executeOk $servald config del foo
assertStdoutLineCount '==' 0
}
doc_Del="Delete single config item"
test_Del() {
executeOk $dna config set foo bar
executeOk $dna config set hello world
executeOk $dna config get
executeOk $servald config set foo bar
executeOk $servald config set hello world
executeOk $servald config get
assertStdoutLineCount '==' 2
executeOk $dna config del foo
executeOk $dna config get
executeOk $servald config del foo
executeOk $servald config get
assertStdoutLineCount '==' 1
executeOk $dna config get foo
executeOk $servald config get foo
assertStdoutLineCount '==' 0
}
doc_CaseInsensitive="Config item names are case insensitive"
test_CaseInsensitive() {
executeOk $dna config set foo bar
executeOk $dna config get foo
executeOk $servald config set foo bar
executeOk $servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
executeOk $dna config get Foo
executeOk $servald config get Foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
executeOk $dna config set FOO wah
executeOk $dna config get foo
executeOk $servald config set FOO wah
executeOk $servald config get foo
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^FOO=wah$'
}
doc_DotsInNames="Config item names can have internal dots"
test_DotsInNames() {
executeOk $dna config set foo.bar yes
executeOk $dna config get foo.bar
executeOk $servald config set foo.bar yes
executeOk $servald config get foo.bar
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.bar=yes$'
execute $dna config set foo. yes
execute $servald config set foo. yes
assertExitStatus '!=' 0
execute $dna config set .foo yes
execute $servald config set .foo yes
assertExitStatus '!=' 0
execute $dna config set foo..bar yes
execute $servald config set foo..bar yes
assertExitStatus '!=' 0
executeOk $dna config set foo.x.bar yes
executeOk $dna config get foo.x.bar
executeOk $servald config set foo.x.bar yes
executeOk $servald config get foo.x.bar
assertStdoutLineCount '==' 1
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.x\.bar=yes$'
}
doc_DebugFlags="Debug config options affect verbosity"
test_DebugFlags() {
executeOk $dna echo one two three
executeOk $servald echo one two three
assertStderrGrep --matches=0 '\<echo:argv\['
executeOk $dna config set debug.verbose true
executeOk $dna echo one two three
executeOk $servald config set debug.verbose true
executeOk $servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
executeOk $dna config set debug.verbose false
executeOk $dna echo one two three
executeOk $servald config set debug.verbose false
executeOk $servald echo one two three
assertStderrGrep --matches=0 '\<echo:argv\['
}
doc_DebugFlagAll="Debug config options override debug.all"
test_DebugFlagAll() {
executeOk $dna config set debug.all yes
executeOk $dna echo one two three
executeOk $servald config set debug.all yes
executeOk $servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
executeOk $dna config set debug.verbose false
executeOk $dna echo one two three
executeOk $servald config set debug.verbose false
executeOk $servald echo one two three
assertStderrGrep --matches=0 '\<echo:argv\['
executeOk $dna config set debug.verbose true
executeOk $dna echo one two three
executeOk $servald config set debug.verbose true
executeOk $servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
executeOk $dna config set debug.all off
executeOk $dna echo one two three
executeOk $servald config set debug.all off
executeOk $servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
}

View File

@ -23,19 +23,19 @@ source "${0%/*}/../testdefs.sh"
# Default teardown function
teardown() {
stop_dna_server
stop_servald_server
}
# Utility function
create_sid() {
executeOk $dna "$@" -d 0427679796 -C
executeOk $servald "$@" -d 0427679796 -C
assertStdoutGrep --matches=1 '^OK:'
sid=`replayStdout | grep '^OK:' | cut -f2 -d:`
}
# Utility function
set_short_var() {
executeOk $dna -s $sid -i 0 -W note="a short literal value"
executeOk $servald -s $sid -i 0 -W note="a short literal value"
}
# Utility function
@ -50,8 +50,8 @@ echo_long_message() {
# Test case, transcribed from ../testdna
doc_CreateSID='Create new SID'
setup_CreateSID() {
setup_dna
start_dna_server
setup_servald
start_servald_server
}
test_CreateSID() {
create_sid
@ -62,12 +62,12 @@ test_CreateSID() {
# Test case, transcribed from ../testdna
doc_GetShortVar='Get short variable'
setup_GetShortVar() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
}
test_GetShortVar() {
executeOk $dna -d 0427679796 -R dids
executeOk $servald -d 0427679796 -R dids
assertRealTime '>' 2.9 # Waited for all replies
assertStdoutGrep --message='received an existing DID' "^DIDS:${sid}:[0-9]\+:0:0427679796"
assertStdoutGrep --matches=1 --message='filtered out duplicate responses' "^DIDS:${sid}:[0-9]\+:0:0427679796"
@ -76,8 +76,8 @@ test_GetShortVar() {
# Test case, transcribed from ../testdna
doc_SetShortVar='Set short variable'
setup_SetShortVar() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
}
test_SetShortVar() {
@ -89,13 +89,13 @@ test_SetShortVar() {
# Test case, transcribed from ../testdna
doc_SetGetShortVar='Set then get short variable'
setup_SetGetShortVar() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
}
test_SetGetShortVar() {
executeOk $dna -s $sid -i 0 -R note
executeOk $servald -s $sid -i 0 -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='read variable correctly' "^NOTE:$sid:[0-9]\+:0:a short literal value"
}
@ -103,33 +103,33 @@ test_SetGetShortVar() {
# Test case, transcribed from ../testdna
doc_GetShortVarToFile='Get variable into a file'
setup_GetShortVarToFile() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
}
test_GetShortVarToFile() {
echo "WARNING: Known issue: output to file does not work with DID lists"
dnatest_dat=$DNATMP/dnatest.dat
executeOk $dna -s $sid -O $dnatest_dat -i 0 -R note
servaldtest_dat=$DNATMP/servaldtest.dat
executeOk $servald -s $sid -O $servaldtest_dat -i 0 -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='read variable into file' "^NOTE:$sid:[0-9]\+:0"
assertFileContents $dnatest_dat 'a short literal value'
assertFileContents $servaldtest_dat 'a short literal value'
}
# Test case, transcribed from ../testdna
doc_SetMultiShortVar='Set multiple instances of a short variable'
setup_SetMultiShortVar() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
}
test_SetMultiShortVar() {
executeOk $dna -s $sid -i 1 -W note='$414243'
executeOk $servald -s $sid -i 1 -W note='$414243'
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
executeOk $dna -s $sid -i 1 -R note
executeOk $servald -s $sid -i 1 -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='new variable correctly set in hex' "^NOTE:$sid:[0-9]\+:1:ABC$"
}
@ -137,15 +137,15 @@ test_SetMultiShortVar() {
# Test case, transcribed from ../testdna
doc_GetMultiShortVar='Get multiple instances of a short variable'
setup_GetMultiShortVar() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
executeOk $dna -s $sid -i 1 -W note='$414243'
executeOk $dna -s $sid -i 2 -W note
executeOk $servald -s $sid -i 1 -W note='$414243'
executeOk $servald -s $sid -i 2 -W note
}
test_GetMultiShortVar() {
executeOk $dna -s $sid -m -R note
executeOk $servald -s $sid -m -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='first variable read correctly' "^NOTE:$sid:[0-9]\+:0:a short literal value$"
assertStdoutGrep --matches=1 --message='second variable read correctly' "^NOTE:$sid:[0-9]\+:1:ABC$"
@ -155,16 +155,16 @@ test_GetMultiShortVar() {
# Test case, transcribed from ../testdna
doc_OverwriteVarNoUpdate='Set does not overwrite variable'
setup_OverwriteVarNoUpdate() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
}
test_OverwriteVarNoUpdate() {
executeOk $dna -s $sid -i 0 -W note="replacement short literal value"
executeOk $servald -s $sid -i 0 -W note="replacement short literal value"
assertRealTime '<' 0.5
assertStdoutGrep --matches=0 --message='variable write not confirmed' "^WROTE:$sid$"
executeOk $dna -s $sid -i 0 -R note
executeOk $servald -s $sid -i 0 -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='variable retains original value' "^NOTE:$sid:[0-9]\+:0:a short literal value"
}
@ -172,16 +172,16 @@ test_OverwriteVarNoUpdate() {
# Test case, transcribed from ../testdna
doc_UpdateVar='Update overwrites variable'
setup_UpdateVar() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
}
test_UpdateVar() {
executeOk $dna -s $sid -i 0 -U note="replacement short literal value"
executeOk $servald -s $sid -i 0 -U note="replacement short literal value"
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
executeOk $dna -s $sid -i 0 -R note
executeOk $servald -s $sid -i 0 -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='variable has new value' "^NOTE:$sid:[0-9]\+:0:replacement short literal value"
}
@ -189,20 +189,20 @@ test_UpdateVar() {
# Test case, transcribed from ../testdna
doc_UpdateVarBigValue='Can set variable with multi-packet value'
setup_UpdateVarBigValue() {
setup_dna
start_dna_server
setup_servald
start_servald_server
create_sid
set_short_var
echo_long_message >$DNATMP/dnatest.in
echo_long_message >$DNATMP/servaldtest.in
}
test_UpdateVarBigValue() {
executeOk $dna -s $sid -i 0 -U note="@dnatest.in"
executeOk $servald -s $sid -i 0 -U note="@servaldtest.in"
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
executeOk $dna -v verbose -s $sid -O $DNATMP/dnatest.out -i 0 -R note
executeOk $servald -v verbose -s $sid -O $DNATMP/servaldtest.out -i 0 -R note
assertRealTime '<' 0.5
assertStdoutGrep --matches=1 --message='variable new value returned' "^NOTE:$sid:[0-9]\+:0"
assert --message='long value read correctly' cmp --quiet $DNATMP/dnatest.in $DNATMP/dnatest.out
assert --message='long value read correctly' cmp --quiet $DNATMP/servaldtest.in $DNATMP/servaldtest.out
}
runTests "$@"

View File

@ -23,7 +23,7 @@ source "${0%/*}/../testdefs.sh"
source "${0%/*}/../testconfig.sh"
setup() {
setup_dna
setup_servald
assert_echo_works
compile_java_classes
setup_servald_so
@ -32,14 +32,14 @@ setup() {
compile_java_classes() {
assert --message='Java compiler was detected by ./configure' [ "$JAVAC" ]
mkdir classes
assert $JAVAC -d classes "$dna_source_root"/java/org/servalproject/servald/*.java
assert $JAVAC -d classes "$servald_source_root"/java/org/servalproject/servald/*.java
assert [ -r classes/org/servalproject/servald/ServalD.class ]
assert [ -r classes/org/servalproject/servald/ServalDTests.class ]
}
# Make sure that the normal echo command-line works, without JNI.
assert_echo_works() {
executeOk $dna echo 'Hello,' 'world!'
executeOk $servald echo 'Hello,' 'world!'
assertStdoutIs -e 'Hello,\nworld!\n'
}
@ -51,12 +51,12 @@ test_Echo() {
doc_Delim="Serval non-JNI output delimiter environment variable"
setup_Delim() {
setup_dna
setup_servald
assert_echo_works
}
test_Delim() {
export SERVALD_OUTPUT_DELIMITER=:::
executeOk $dna echo 'Hello,' 'world!'
executeOk $servald echo 'Hello,' 'world!'
assertStdoutIs 'Hello,:::world!:::'
}

View File

@ -21,17 +21,17 @@
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
setup_dna_rhizome() {
setup_dna "$@"
executeOk $dna config set debug.rhizome on
executeOk $dna keyring add
executeOk $dna keyring list
setup_servald_rhizome() {
setup_servald "$@"
executeOk $servald config set debug.rhizome on
executeOk $servald keyring add
executeOk $servald keyring list
sid=$(replayStdout | sed -ne '1s/^\([0-9a-fA-F]\{64\}\):.*$/\1/p')
assert --message='identity known' [ -n "$sid" ]
}
assert_rhizome_list() {
executeOk $dna rhizome list
executeOk $servald rhizome list
assertStdoutLineCount '==' $(($# + 2))
assertStdoutIs --line=1 -e '8\n'
assertStdoutIs --line=2 -e 'service:fileid:manifestid:version:inserttime:length:date:name\n'
@ -119,7 +119,7 @@ extract_manifest_version() {
doc_InitialEmptyList="Initial list is empty"
setup_InitialEmptyList() {
setup_dna_rhizome
setup_servald_rhizome
}
test_InitialEmptyList() {
assert_rhizome_list
@ -127,42 +127,43 @@ test_InitialEmptyList() {
doc_AddNoAuthorNoManifest="Add with no author and no manifest file"
setup_AddNoAuthorNoManifest() {
setup_dna_rhizome
setup_servald_rhizome
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNoAuthorNoManifest() {
executeOk $dna rhizome add file '' '' file1
executeOk $servald rhizome add file '' '' file1
assert_stdout_add_file file1
}
doc_AddNoManifest="Add with no manifest file"
setup_AddNoManifest() {
setup_dna_rhizome
setup_servald_rhizome
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNoManifest() {
executeOk $dna rhizome add file $sid '' file1
executeOk $servald rhizome add file $sid '' file1
assert_stdout_add_file file1
}
doc_AddNonExistManifest="Add with non-existent manifest file"
setup_AddNonExistManifest() {
setup_dna_rhizome
setup_servald_rhizome
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNonExistManifest() {
assert --error-on-fail [ ! -e file1.manifest ]
executeOk $dna rhizome add file $sid '' file1 file1.manifest
executeOk $servald rhizome add file $sid '' file1 file1.manifest
assert_stdout_add_file file1
assert [ -r file1.manifest ]
tfw_cat -v file1.manifest
assertGrep file1.manifest '^service=file$'
assertGrep file1.manifest '^BK=[0-9a-fA-F]\+$'
assertGrep file1.manifest '^name=file1$'
assertGrep file1.manifest '^date=[0-9]\+$'
assertGrep file1.manifest '^version=[0-9]\+$'
@ -173,17 +174,18 @@ test_AddNonExistManifest() {
doc_AddManifest="Add with minimal manifest file"
setup_AddManifest() {
setup_dna_rhizome
setup_servald_rhizome
assert_rhizome_list
echo "A test file" >file1
echo -e 'name=wah\ndate=12345' >file1.manifest
echo "Another test file" >file2
}
test_AddManifest() {
executeOk $dna rhizome add file $sid '' file1 file1.manifest
executeOk $servald rhizome add file $sid '' file1 file1.manifest
tfw_cat --stdout --stderr -v file1.manifest
assert_stdout_add_file file1 wah
assertGrep file1.manifest '^service=file$'
assertGrep file1.manifest '^BK=[0-9a-fA-F]\+$'
assertGrep file1.manifest '^name=wah$'
assertGrep file1.manifest '^version=[0-9]\+$'
assertGrep file1.manifest '^date=12345$'
@ -194,32 +196,32 @@ test_AddManifest() {
doc_AddThenList="List contains one file after one add"
setup_AddThenList() {
setup_dna_rhizome
setup_servald_rhizome
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddThenList() {
# Add first file
executeOk $dna rhizome add file $sid '' file1 file1.manifest
executeOk $servald rhizome add file $sid '' file1 file1.manifest
assert_rhizome_list file1
# Add second file
executeOk $dna rhizome add file $sid '' file2 file2.manifest
executeOk $servald rhizome add file $sid '' file2 file2.manifest
assert_rhizome_list file1 file2
}
doc_AddThenExtractManifest="Extract manifest after one add"
setup_AddThenExtractManifest() {
setup_dna_rhizome
setup_servald_rhizome
echo "A test file" >file1
executeOk $dna rhizome add file $sid '' file1 file1.manifest
executeOk $servald rhizome add file $sid '' file1 file1.manifest
assert_rhizome_list file1
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
extract_manifest_filehash filehash file1.manifest
}
test_AddThenExtractManifest() {
executeOk $dna rhizome extract manifest $manifestid file1x.manifest
executeOk $servald rhizome extract manifest $manifestid file1x.manifest
assert cmp file1.manifest file1x.manifest
assertStdoutLineCount '==' 6
local size=$(( $(cat file1 | wc -c) + 0 ))
@ -233,41 +235,41 @@ test_AddThenExtractManifest() {
doc_ExtractMissingManifest="Extract non-existent manifest"
setup_ExtractMissingManifest() {
setup_dna_rhizome
setup_servald_rhizome
manifestid=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
}
test_ExtractMissingManifest() {
execute --exit-status=1 $dna rhizome extract manifest $manifestid foo.manifest
execute --exit-status=1 $servald rhizome extract manifest $manifestid foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
}
doc_ExtractManifestInvalidID="Extract manifest using invalid ID"
setup_ExtractManifestInvalidID() {
setup_dna_rhizome
setup_servald_rhizome
}
test_ExtractManifestInvalidID() {
execute --exit-status=255 $dna rhizome extract manifest 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo.manifest
execute --exit-status=255 $servald rhizome extract manifest 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
execute --exit-status=255 $dna rhizome extract manifest 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo.manifest
execute --exit-status=255 $servald rhizome extract manifest 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
execute --exit-status=255 $dna rhizome extract manifest '' foo.manifest
execute --exit-status=255 $servald rhizome extract manifest '' foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
}
doc_AddThenExtractFile="Extract file after one add"
setup_AddThenExtractFile() {
setup_dna_rhizome
setup_servald_rhizome
echo "A test file" >file1
executeOk $dna rhizome add file $sid '' file1 file1.manifest
executeOk $servald rhizome add file $sid '' file1 file1.manifest
assert_rhizome_list file1
extract_manifest_filehash filehash file1.manifest
}
test_AddThenExtractFile() {
executeOk $dna rhizome extract file $filehash file1x
executeOk $servald rhizome extract file $filehash file1x
assert cmp file1 file1x
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutLineCount '==' 2
@ -277,42 +279,42 @@ test_AddThenExtractFile() {
doc_ExtractMissingFile="Extract non-existent file"
setup_ExtractMissingFile() {
setup_dna_rhizome
setup_servald_rhizome
filehash=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
}
test_ExtractMissingFile() {
execute --exit-status=1 $dna rhizome extract file $filehash foo
execute --exit-status=1 $servald rhizome extract file $filehash foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
}
doc_ExtractFileInvalidID="Extract file using invalid ID"
setup_ExtractFileInvalidID() {
setup_dna_rhizome
setup_servald_rhizome
}
test_ExtractFileInvalidID() {
execute --exit-status=255 $dna rhizome extract file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo
execute --exit-status=255 $servald rhizome extract file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $dna rhizome extract file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo
execute --exit-status=255 $servald rhizome extract file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $dna rhizome extract file '' foo
execute --exit-status=255 $servald rhizome extract file '' foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
}
doc_AddDuplicate="Add same manifest detects duplicate"
setup_AddDuplicate() {
setup_dna_rhizome
setup_servald_rhizome
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
echo "A test file, second version" >file1_2
# Add first file
executeOk $dna rhizome add file $sid '' file1 file1.manifest
executeOk $servald rhizome add file $sid '' file1 file1.manifest
# Add second file
executeOk $dna rhizome add file $sid '' file2 file2.manifest
executeOk $servald rhizome add file $sid '' file2 file2.manifest
# Make sure they are both in the list.
assert_rhizome_list file1 file2
}
@ -320,14 +322,14 @@ test_AddDuplicate() {
# Add first file again - nothing should change in its manifests, and it
# should appear that the add command succeeded (with perhaps some grumbling
# on stderr).
execute --exit-status=2 $dna rhizome add file $sid '' file1 file1.manifestA
execute --exit-status=2 $servald rhizome add file $sid '' file1 file1.manifestA
assert [ -s file1.manifestA ]
assert_stdout_add_file file1
assert_rhizome_list file1 file2
strip_signatures file1.manifest file1.manifestA
assert diff file1.manifest file1.manifestA
# Repeat for second file.
execute --exit-status=2 $dna rhizome add file $sid '' file2 file2.manifestA
execute --exit-status=2 $servald rhizome add file $sid '' file2 file2.manifestA
assert [ -s file2.manifestA ]
assert_stdout_add_file file2
assert_rhizome_list file1 file2
@ -343,7 +345,7 @@ test_AddMismatched() {
# Try to add another file using an existing manifest, should fail and leave
# the manifest file unchanged.
cp file1.manifest file1_2.manifest
execute $dna rhizome add file $sid '' file1_2 file1_2.manifest
execute $servald rhizome add file $sid '' file1_2 file1_2.manifest
assertExitStatus '!=' 0
assert cmp file1.manifest file1_2.manifest
# And rhizome store should be unchanged.
@ -364,7 +366,7 @@ setup_AddUpdateSameVersion() {
}
test_AddUpdateSameVersion() {
tfw_cat -v file1_2.manifest
execute $dna rhizome add file $sid '' file1_2 file1_2.manifest
execute $servald rhizome add file $sid '' file1_2 file1_2.manifest
assertExitStatus --stderr '!=' 0
tfw_cat -v file1_2.manifest
assert cmp file1_2.manifest file1_2.manifest.orig
@ -382,7 +384,7 @@ setup_AddUpdateNewVersion() {
}
test_AddUpdateNewVersion() {
tfw_cat -v file1_2.manifest
executeOk $dna rhizome add file $sid '' file1_2 file1_2.manifest
executeOk $servald rhizome add file $sid '' file1_2 file1_2.manifest
assert_stdout_add_file file1_2 file1
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
@ -399,7 +401,7 @@ setup_AddUpdateAutoVersion() {
test_AddUpdateAutoVersion() {
tfw_cat -v file1_2.manifest
sleep 0.001 # Ensure that at least one millisecond has elapsed
executeOk $dna rhizome add file $sid '' file1_2 file1_2.manifest
executeOk $servald rhizome add file $sid '' file1_2 file1_2.manifest
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
mv -f file1_2.manifest file1.manifest