1- #! /bin/sh
1+ #! /bin/bash
22set -e
33cd shared || true
44
55token=" $( curl http://oidc:8080/tokens | jq -r ' .[0]' ) "
6- # Upload a file and make sure it's listed
6+ # # make sure previously uploaded files are listed
77result=
" $( curl -sk -L " http://api:8080/users/[email protected] /files" -H " Authorization: Bearer $token " | jq ' . | length' ) " 88if [ " $result " -ne 2 ]; then
99 echo " wrong number of files returned for user [email protected] " 4141
4242# Reupload a file under a different name, test to delete it
4343s3cmd -c s3cfg put " NA12878.bam.c4gh" s3://test_dummy.org/NC12878.bam.c4gh
44+ stream_size=$( curl -s -u guest:guest http://rabbitmq:15672/api/queues/sda/inbox | jq ' .messages_ready' )
4445
45- echo " waiting for upload to complete"
4646URI=http://rabbitmq:15672
4747if [ -n " $PGSSLCERT " ]; then
4848 URI=https://rabbitmq:15671
4949fi
50+ stream_size=$(( stream_size + 1 ))
5051RETRY_TIMES=0
51- until [ " $( curl -s -k -u guest:guest $URI /api/queues/sda/inbox | jq -r ' ."messages_ready"' ) " -eq 4 ]; do
52- echo " waiting for upload to complete"
53- RETRY_TIMES=$(( RETRY_TIMES + 1 ))
54- if [ " $RETRY_TIMES " -eq 30 ]; then
55- echo " ::error::Time out while waiting for upload to complete"
56- exit 1
57- fi
58- sleep 2
52+
53+ until [ $(( stream_size)) -eq " $( curl -s -u guest:guest http://rabbitmq:15672/api/queues/sda/inbox | jq ' .messages_ready' ) " ]; do
54+ echo " waiting for upload to complete"
55+ RETRY_TIMES=$(( RETRY_TIMES + 1 ))
56+ if [ " $RETRY_TIMES " -eq 30 ]; then
57+ echo " Upload did not complete successfully"
58+ exit 1
59+ fi
60+ sleep 2
5961done
6062
6163# get the fileId of the new file
62- fileid=
" $( curl -k -L -H " Authorization: Bearer $token " " http://api:8080/users/[email protected] /files" | jq -r ' .[] | select(.inboxPath == "test_dummy.org/ NC12878.bam.c4gh") | .fileID' ) " 64+ fileid=
" $( curl -k -L -H " Authorization: Bearer $token " " http://api:8080/users/[email protected] /files" | jq -r ' .[] | select(.inboxPath == "NC12878.bam.c4gh") | .fileID' ) " 6365
6466output=$( s3cmd -c s3cfg ls s3://test_dummy.org/NC12878.bam.c4gh 2> /dev/null)
6567if [ -z " $output " ] ; then
104106
105107# Re-upload the file and use the api to ingest it, then try to delete it
106108s3cmd -c s3cfg put NA12878.bam.c4gh s3://test_dummy.org/NE12878.bam.c4gh
107-
108- URI=http://rabbitmq:15672
109- if [ -n " $PGSSLCERT " ]; then
110- URI=https://rabbitmq:15671
111- fi
109+ stream_size=$(( stream_size + 1 ))
112110RETRY_TIMES=0
113- until [ " $( curl -s -k -u guest:guest $URI /api/queues/sda/inbox | jq -r ' ."messages_ready" ' ) " -eq 6 ] ; do
114- echo " waiting for upload to complete "
115- RETRY_TIMES= $(( RETRY_TIMES + 1 ))
116- if [ " $ RETRY_TIMES" -eq 3 ] ; then
117- echo " ::error::Time out while waiting for upload to complete "
118- # exit 1
119- break
120- fi
121- sleep 2
111+
112+ until [ $(( stream_size )) -eq " $( curl -s -u guest:guest $URI /api/queues/sda/inbox | jq ' .messages_ready ' ) " ] ; do
113+ echo " waiting for upload to complete "
114+ RETRY_TIMES= $(( RETRY_TIMES + 1 ))
115+ if [ " $RETRY_TIMES " -eq 30 ] ; then
116+ echo " Upload did not complete successfully "
117+ exit 1
118+ fi
119+ sleep 2
122120done
123121
124122# Ingest it
125123new_payload=$(
126124jq -c -n \
127- --arg filepath " test_dummy.org/ NE12878.bam.c4gh" \
125+ --arg filepath " NE12878.bam.c4gh" \
128126129127 ' $ARGS.named'
130128)
@@ -135,7 +133,7 @@ if [ "$resp" != "200" ]; then
135133 exit 1
136134fi
137135
138- fileid=
" $( curl -k -L -H " Authorization: Bearer $token " " http://api:8080/users/[email protected] /files" | jq -r ' .[] | select(.inboxPath == "test_dummy.org/ NE12878.bam.c4gh") | .fileID' ) " 136+ fileid=
" $( curl -k -L -H " Authorization: Bearer $token " " http://api:8080/users/[email protected] /files" | jq -r ' .[] | select(.inboxPath == "NE12878.bam.c4gh") | .fileID' ) " 139137# wait for the fail to get the correct status
140138RETRY_TIMES=0
141139
@@ -150,9 +148,10 @@ until [ "$(psql -U postgres -h postgres -d sda -At -c "select id from sda.file_e
150148done
151149
152150# Try to delete file not in inbox
153- fileid=
" $( curl -k -L -H " Authorization: Bearer $token " " http://api:8080/users/[email protected] /files" | jq -r ' .[] | select(.inboxPath == "test_dummy.org/ NE12878.bam.c4gh") | .fileID' ) " 151+ fileid=
" $( curl -k -L -H " Authorization: Bearer $token " " http://api:8080/users/[email protected] /files" | jq -r ' .[] | select(.inboxPath == "NE12878.bam.c4gh") | .fileID' ) " 154152resp=
" $( curl -s -k -L -o /dev/null -w " %{http_code}\n" -H " Authorization: Bearer $token " -X DELETE " http://api:8080/file/[email protected] /$fileid " ) " 155153if [ " $resp " != " 404" ]; then
156154 echo " Error when deleting the file, expected 404 got: $resp "
157155 exit 1
158- fi
156+ fi
157+ echo " API admin tests completed successfully"
0 commit comments