paraslash 0.7.3
[paraslash.git] / t / t0004-server.sh
index c79ea24be07c3235a11d9518788dd7dac3c0d6f6..f7a407dc9e4bd99a71a3b3e364a6386fc55f1d44 100755 (executable)
@@ -21,13 +21,15 @@ pubkey=$privkey.pub
 serverlog=server.log
 
 get_audio_file_paths ogg
-oggs="$result"
+declare -a oggs=($result)
+declare -a oggs_base=(${oggs[@]##*/})
 
-declare -a commands=() cmdline=() required_objects=() good=() bad=()
+declare -a commands=() cmdline=() required_objects=() good=() bad=() \
+       expect_failure=()
 i=0
 commands[$i]="help"
-cmdline[$i]="help"
-good[$i]='help server  ----'
+cmdline[$i]="help -l"
+good[$i]='help \{1,\}----'
 
 let i++
 commands[$i]="init"
@@ -35,17 +37,62 @@ cmdline[$i]="init"
 good[$i]='^successfully'
 bad[$i]='!^successfully'
 
+let i++
+commands[$i]='add_dir'
+required_objects[$i]='ogg_afh'
+cmdline[$i]="add -v $test_audio_file_dir"
+good[$i]='^adding'
+
+let i++
+commands[$i]='rm'
+required_objects[$i]='ogg_afh'
+cmdline[$i]="rm -v $test_audio_file_dir/*"
+good[$i]='^removing'
+
 let i++
 commands[$i]="add_ogg"
 required_objects[$i]='ogg_afh'
-cmdline[$i]="add $oggs"
+cmdline[$i]="add ${oggs[@]}"
 bad[$i]='.'
 
 let i++
 commands[$i]="ls_ogg"
 required_objects[$i]='ogg_afh'
-cmdline[$i]="ls -lv -p $oggs"
-good[$i]='^path:'
+cmdline[$i]="ls -l=v -b ${oggs_base[@]}"
+good[$i]='^basename:'
+
+let i++
+commands[$i]='addatt'
+required_objects[$i]=''
+cmdline[$i]="addatt $(seq 64 | tr '\n' ' ')"
+bad[$i]='.'
+
+let i++
+commands[$i]='lsatt'
+required_objects[$i]=''
+cmdline[$i]="lsatt"
+good[$i]='^1$'
+
+let i++
+commands[$i]='setatt'
+required_objects[$i]='ogg_afh'
+cmdline[$i]="setatt 33+ ${oggs[@]}"
+bad[$i]='.'
+
+let i++
+commands[$i]="ls"
+required_objects[$i]='ogg_afh'
+cmdline[$i]="ls -l=v ${oggs[@]}"
+good[$i]='^attributes_txt: 33'
+
+let i++
+commands[$i]='addmood'
+cmdline[$i]="addmood test-mood"
+
+let i++
+commands[$i]='empty-mood-parameter'
+cmdline[$i]="select m/"
+expect_failure[$i]='true'
 
 let i++
 commands[$i]="term"
@@ -57,30 +104,34 @@ missing_objects="$result"
 test_require_executables "ssh-keygen"
 missing_executables="$result"
 
-ssh-keygen -q -t rsa -b 2048 -N "" -f $privkey
-key_gen_result=$?
+if [[ -z "$missing_objects" && -z "$missing_executables" ]]; then
+       ssh-keygen -q -t rsa -b 2048 -N "" -m PEM -f $privkey
+       key_gen_result=$?
 
-read &>/dev/null < /dev/tcp/localhost/$port
-check_port_result=$?
+       read &>/dev/null < /dev/tcp/localhost/$port
+       check_port_result=$?
 
-cat > $user_list << EOF
-user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
+       cat > $user_list << EOF
+       user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
 EOF
 
-# para_server sends this signal to all processes in the current process group.
-trap "" SIGUSR1
-
-$PARA_SERVER \
-       --logfile "$serverlog" \
-       --config_file /dev/null \
-       --daemon \
-       --loglevel $loglevel \
-       --port $port \
-       --afs_database_dir "$db" \
-       --afs_socket "$sock" \
-       --user_list "$user_list" \
-       --http_port "$stream_port" \
-       --dccp_port "$stream_port"
+       # para_server sends this signal to all processes in the current process group.
+       trap "" SIGUSR1
+
+
+       $PARA_SERVER \
+               --logfile "$serverlog" \
+               --config-file /dev/null \
+               --daemon \
+               --loglevel $loglevel \
+               --port $port \
+               --afs-database-dir "$db" \
+               --afs-socket "$sock" \
+               --user-list "$user_list" \
+               --http-port "$stream_port" \
+               --dccp-port "$stream_port"
+       (($? != 0)) && exit 1
+fi
 
 for ((i=0; i < ${#commands[@]}; i++)); do
        command=${commands[$i]}
@@ -108,14 +159,19 @@ for ((i=0; i < ${#commands[@]}; i++)); do
                        continue
                fi
        fi
-       test_expect_success "$command" "
+       if [[ -n "${expect_failure[$i]}" ]]; then
+               f=test_expect_failure
+       else
+               f=test_expect_success
+       fi
+       $f "$command" "
        $PARA_CLIENT \
                --loglevel $loglevel \
-               --server_port $port \
-               --key_file $privkey \
-               --config_file /dev/null \
+               --server-port $port \
+               --key-file $privkey \
+               --config-file /dev/null \
                -- \
-               ${cmdline[$i]} > $command.out &&
+               ${cmdline[$i]} > $command.out < /dev/null &&
                { [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
                { [[ -z \"${bad[$i]}\" ]]  || ! grep \"${bad[$i]}\"; } < $command.out
        "