Refactor test setup function 'create_single_identity'

Now produces exactly the same output variables as 'create_identities 1'
so that these two functions can be interchanged with minimal impact
on the test script.
This commit is contained in:
Andrew Bettison 2018-03-26 22:32:13 +10:30
parent f8850535ad
commit a82babf9db
2 changed files with 17 additions and 25 deletions

View File

@ -698,10 +698,6 @@ assert_all_servald_servers_no_errors() {
# servald keyring add [--option]... # servald keyring add [--option]...
# - assign a phone number (DID) and name to the new identity, use defaults # - assign a phone number (DID) and name to the new identity, use defaults
# if not specified by arg1 and arg2 # if not specified by arg1 and arg2
# - assert the new identity is the only one in this instance
# - set the SID{I} variable, eg SIDA, to the SID of the new identity
# - set the DID{I} variable, eg DIDA, to the phone number of the new identity
# - set the NAME{I} variable, eg NAMEA, to the name of the new identity
create_single_identity() { create_single_identity() {
local servald_options=() local servald_options=()
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
@ -717,18 +713,6 @@ create_single_identity() {
eval "$didvar=\"\${1-\$((5550000 + \$instance_number))}\"" eval "$didvar=\"\${1-\$((5550000 + \$instance_number))}\""
eval "$namevar=\"\${2-Agent \$instance_name Smith}\"" eval "$namevar=\"\${2-Agent \$instance_name Smith}\""
create_identities "${servald_options[@]}" 1 create_identities "${servald_options[@]}" 1
eval "SID$instance_name=\"\${!sidvar}\""
eval "ID$instance_name=\"\${!idvar}\""
eval "DID$instance_name=\"\${!didvar}\""
eval "NAME$instance_name=\"\${!namevar}\""
sidvar=SID${instance_name}
idvar=ID${instance_name}
didvar=DID${instance_name}
namevar=NAME${instance_name}
tfw_log "SID$instance_name=$(shellarg "${!sidvar}")"
tfw_log "ID$instance_name=$(shellarg "${!idvar}")"
tfw_log "DID$instance_name=$(shellarg "${!didvar}")"
tfw_log "NAME$instance_name=$(shellarg "${!namevar}")"
} }
# Utility function: # Utility function:
@ -745,9 +729,11 @@ create_single_identity() {
# - assert that all SIDs are unique # - assert that all SIDs are unique
# - assert that all SIDs appear in keyring list # - assert that all SIDs appear in keyring list
# - set variables SID{I}{1..N} to SIDs of identities, eg, SIDA1, SIDA2... # - set variables SID{I}{1..N} to SIDs of identities, eg, SIDA1, SIDA2...
# - set variables ID{I}{1..N} to IDs of identities, eg, IDA1, IDA2...
# - set variables DID{I}{1..N} to DIDs of identities, eg, DIDA1, DIDA2... # - set variables DID{I}{1..N} to DIDs of identities, eg, DIDA1, DIDA2...
# - set variables NAME{I}{1..N} to names of identities, eg, NAMEA1, NAMEA2... # - set variables NAME{I}{1..N} to names of identities, eg, NAMEA1, NAMEA2...
# - set array variable SID{I} to SIDs of identities, eg, SIDA[0], SIDA[1]... # - set array variable SID{I} to SIDs of identities, eg, SIDA[0], SIDA[1]...
# - set array variable ID{I} to IDs of identities, eg, IDA[0], IDA[1]...
# - set array variable DID{I} to DIDs of identities, eg, DIDA[0], DIDA[1]... # - set array variable DID{I} to DIDs of identities, eg, DIDA[0], DIDA[1]...
# - set array variable NAME{I} to names of identities, eg, NAMEA[0], NAMEA[1]... # - set array variable NAME{I} to names of identities, eg, NAMEA[0], NAMEA[1]...
create_identities() { create_identities() {
@ -770,15 +756,20 @@ create_identities() {
local pin="${!pinvar}" local pin="${!pinvar}"
servald_options+=(${pin:+--entry-pin="$pin"}) servald_options+=(${pin:+--entry-pin="$pin"})
done done
local sidarrayvar=SID$instance_name
local idarrayvar=ID$instance_name
local didarrayvar=DID$instance_name
local namearrayvar=NAME$instance_name
eval "$sidarrayvar=()"
eval "$idarrayvar=()"
eval "$didarrayvar=()"
eval "$namearrayvar=()"
for ((i = 1; i <= N; ++i)); do for ((i = 1; i <= N; ++i)); do
local pinvar=PIN$instance_name$i local pinvar=PIN$instance_name$i
local sidvar=SID$instance_name$i local sidvar=SID$instance_name$i
local idvar=ID$instance_name$i local idvar=ID$instance_name$i
local didvar=DID$instance_name$i local didvar=DID$instance_name$i
local namevar=NAME$instance_name$i local namevar=NAME$instance_name$i
local sidarrayvar=SID$instance_name
local didarrayvar=DID$instance_name
local namearrayvar=NAME$instance_name
local pin="${!pinvar}" local pin="${!pinvar}"
[ -n "$pin" ] && tfw_log "$pinvar=$(shellarg "$pin")" [ -n "$pin" ] && tfw_log "$pinvar=$(shellarg "$pin")"
executeOk_servald keyring add "${servald_options[@]}" "$pin" executeOk_servald keyring add "${servald_options[@]}" "$pin"
@ -786,6 +777,7 @@ create_identities() {
extract_stdout_keyvalue $sidvar sid "$rexp_sid" extract_stdout_keyvalue $sidvar sid "$rexp_sid"
extract_stdout_keyvalue $idvar identity "$rexp_id" extract_stdout_keyvalue $idvar identity "$rexp_id"
tfw_log "$sidvar=${!sidvar}" tfw_log "$sidvar=${!sidvar}"
tfw_log "$idvar=${!idvar}"
# If the DID and/or NAME is already specified in the variables, then use # If the DID and/or NAME is already specified in the variables, then use
# them, otherwise extract the DID and NAME automatically generated by # them, otherwise extract the DID and NAME automatically generated by
# servald. # servald.
@ -799,10 +791,10 @@ create_identities() {
extract_stdout_keyvalue_optional $didvar did "$rexp_did" extract_stdout_keyvalue_optional $didvar did "$rexp_did"
extract_stdout_keyvalue_optional $namevar name ".*" extract_stdout_keyvalue_optional $namevar name ".*"
fi fi
let a=i-1 eval "$sidarrayvar+=(\"\${!sidvar}\")"
eval "$sidarrayvar[$a]=\${!sidvar}" eval "$idarrayvar+=(\"\${!idvar}\")"
eval "$didarrayvar[$a]=\${!didvar}" eval "$didarrayvar+=(\"\${!didvar}\")"
eval "$namearrayvar[$a]=\${!namevar}" eval "$namearrayvar+=(\"\${!namevar}\")"
done done
for ((i = 1; i <= N; ++i)); do for ((i = 1; i <= N; ++i)); do
for ((j = 1; j <= N; ++j)); do for ((j = 1; j <= N; ++j)); do

View File

@ -467,7 +467,7 @@ rhizome_add_file() {
rhizome_add_files() { rhizome_add_files() {
local size=64 local size=64
local sidvar="SID$instance_name" local sidvar="SID${instance_name}1"
local -a names=() local -a names=()
for arg; do for arg; do
case "$arg" in case "$arg" in
@ -489,7 +489,7 @@ rhizome_update_file() {
local orig_name="$1" local orig_name="$1"
local new_name="$2" local new_name="$2"
[ -e "$new_name" ] || echo 'File $new_name' >"$new_name" [ -e "$new_name" ] || echo 'File $new_name' >"$new_name"
local sidvar="SID$instance_name" local sidvar="SID${instance_name}1"
[ "$new_name" != "$orig_name" ] && cp "$orig_name.manifest" "$new_name.manifest" [ "$new_name" != "$orig_name" ] && cp "$orig_name.manifest" "$new_name.manifest"
$SED -i -e '/^date=/d;/^filehash=/d;/^filesize=/d;/^version=/d;/^name=/d' "$new_name.manifest" $SED -i -e '/^date=/d;/^filehash=/d;/^filesize=/d;/^version=/d;/^name=/d' "$new_name.manifest"
executeOk_servald rhizome add file "${!sidvar}" "$new_name" "$new_name.manifest" executeOk_servald rhizome add file "${!sidvar}" "$new_name" "$new_name.manifest"