#!/bin/bash
# Tests the SDP - basic tests

/p4/reset_sdp.sh
[[ -L /p4/test_SDP.py ]] || ln -s /sdp/Server/test/test_SDP.py /p4/
[[ -L /p4/test_Upgrade.py ]] || ln -s /sdp/Server/test/test_Upgrade.py /p4/

if ! python3 /p4/test_SDP.py; then
   tail /tmp/SDPTest.log
   exit 1
fi

if ! python3 /p4/test_Upgrade.py; then
   tail /tmp/UpgradeSDPTest.log
   exit 1
fi

# Test SDP Upgrade
echo Testing the SDP Upgrade Procedure
cd /hxdepots
[[ -d downloads ]] || mkdir downloads
cd downloads
[[ -d new ]] && mv new old.$(date +'%Y%m%d-%H%M')
## This curl won't work until after SDP r2021.1 ships and the live sdp.Unix.tgz is updated. Hack around this for
## now.
##curl -s -k -O https://swarm.workshop.perforce.com/projects/perforce-software-sdp/download/downloads/sdp.Unix.tgz

##
mkdir new
cd new
##tar -xzf ../sdp.Unix.tgz
rsync -a /hxdepots/sdp/ /hxdepots/downloads/new/sdp
##
cd /hxdepots/downloads/new/sdp/Server/Unix/p4/common/sdp_upgrade

if ./sdp_upgrade.sh -y > /tmp/sdp_upgrade.log 2>&1; then
   echo SDP Upgrade OK.
else
   echo SDP Upgrade FAILED.
   tail /tmp/sdp_upgrade.log
   exit 1
fi

exit 0
