Improve 'dnaprotocol' test script

Replace hard-coded identity names and DIDs with shell variables
This commit is contained in:
Andrew Bettison 2012-08-02 15:46:53 +09:30
parent 18424a4f1e
commit 32704bf0e9
2 changed files with 28 additions and 21 deletions

View File

@ -420,7 +420,7 @@ assert_all_servald_servers_no_errors() {
# - assign a phone number (DID) and name to the new identity, use defaults
# if not specified by arg1 and arg2
# - set the SID variable to the SID of the new identity
# - set the NUMBER variable to the phone number of the new identity
# - set the DID variable to the phone number of the new identity
# - set the NAME variable to the name of the new identity
create_identity() {
executeOk_servald keyring add
@ -428,10 +428,10 @@ create_identity() {
executeOk_servald keyring list
SID=$(replayStdout | sed -ne "1s/^\($rexp_sid\):.*\$/\1/p")
assert --message='main identity known' [ -n "$SID" ]
NUMBER="${1-$((5550000 + $instance_number))}"
DID="${1-$((5550000 + $instance_number))}"
NAME="${2-Agent $instance_name Smith}"
executeOk_servald set did $SID "$NUMBER" "$NAME"
tfw_log "Identity $instance_name: $SID $NUMBER $NAME"
executeOk_servald set did $SID "$DID" "$NAME"
tfw_log "Identity $instance_name: $SID $DID $NAME"
}
# Utility function, to be overridden as needed:
@ -447,6 +447,8 @@ configure_servald_server() {
# and with its own private monitor and MDP abstract socket names
# - set variable DUMMYNET to the full path name of shared dummy interface
# - set variables SIDx to the SID of instance x: SIDA, SIDB, etc.
# - set variables DIDx to the DID of instance x: DIDA, DIDB, etc.
# - set variables NAMEx to the names of instance x: NAMEA, NAMEB, etc.
# - set variables LOGx to the full path of server log file for instance x: LOGA,
# LOGB, etc,
# - wait for all instances to detect each other
@ -465,8 +467,10 @@ start_servald_instances() {
executeOk_servald config set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name"
configure_servald_server
start_servald_server
eval SID${I#+}="$SID"
eval LOG${I#+}="$instance_servald_log"
eval SID$instance_name="$SID"
eval DID$instance_name="$(shellarg "$DID")"
eval NAME$instance_name="$(shellarg "$NAME")"
eval LOG$instance_name="$(shellarg "$instance_servald_log")"
done
# Now wait until they see each other.
wait_until --sleep=0.25 instances_see_each_other "$@"

View File

@ -71,16 +71,16 @@ doc_LookupWildcard="Lookup by wildcard"
test_LookupWildcard() {
executeOk_servald dna lookup "*"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550002:5550002:Agent B Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDA/$DIDA:$DIDA:$NAMEA$"
assertStdoutGrep --matches=1 "^sid://$SIDB/$DIDB:$DIDB:$NAMEB$"
}
doc_LookupEmpty="Lookup by empty string"
test_LookupEmpty() {
executeOk_servald dna lookup ""
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/5550002:5550002:Agent B Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDA/$DIDA:$DIDA:$NAMEA$"
assertStdoutGrep --matches=1 "^sid://$SIDB/$DIDB:$DIDB:$NAMEB$"
}
doc_LookupNumber="Lookup by phone number"
@ -91,12 +91,12 @@ test_LookupNumber() {
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "55500011"
assertStdoutLineCount '==' 0
executeOk_servald dna lookup "5550001"
executeOk_servald dna lookup "$DIDA"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDA/5550001:5550001:Agent A Smith$"
executeOk_servald dna lookup "5550002"
assertStdoutGrep --matches=1 "^sid://$SIDA/$DIDA:$DIDA:$NAMEA$"
executeOk_servald dna lookup "$DIDB"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDB/5550002:5550002:Agent B Smith$"
assertStdoutGrep --matches=1 "^sid://$SIDB/$DIDB:$DIDB:$NAMEB$"
}
doc_NodeinfoLocal="Node info auto-resolves for local identities"
@ -105,25 +105,28 @@ test_NodeinfoLocal() {
# if it isn't asked for.
executeOk_servald node info $SIDA
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "Agent A Smith"
assertStdoutGrep --matches=1 ":$SIDA:"
assertStdoutGrep --matches=1 ":$DIDA:"
assertStdoutGrep --matches=1 ":$NAMEA"
assertStdoutGrep --matches=0 "did-not-resolved"
}
doc_NodeinfoRemote="Node info resolves remote identities"
test_NodeinfoRemote() {
# if resolvedid is not specified for a remote identity, then don't resolve
# it.
# if resolvedid is not specified for a remote identity, then don't resolve it.
executeOk_servald node info $SIDB
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=0 "Agent B Smith"
assertStdoutGrep --matches=1 ":$SIDB:"
assertStdoutGrep --matches=0 ":$DIDB:"
assertStdoutGrep --matches=0 ":$NAMEB"
assertStdoutGrep --matches=1 "did-not-resolved"
# But if it resolvedid is specified, then do resolve it using DNA
executeOk_servald node info $SIDB resolvedid
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "Agent B Smith"
assertStdoutGrep --matches=1 ":$SIDB:"
assertStdoutGrep --matches=1 ":$DIDB:"
assertStdoutGrep --matches=1 ":$NAMEB"
assertStdoutGrep --matches=0 "did-not-resolved"
}
runTests "$@"