#!/bin/bash
# Recursive removal of a directory 
# meta: proxy=true
# meta: preconfig=../../DPM-config

source davlib

PROXY_NEEDED

# Directory to be used
TEST_DIR=${DPNS_HOME}/rmdir.`date +%s`


# Simple create/remove
echo "Simple directory"
MKCOL  "${TEST_DIR}"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not create the root directory"
fi
DELETE "${TEST_DIR}"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not remove the root directory"
fi
echo

# Recursive one level
echo "Recursive one level"
MKCOL  "${TEST_DIR}"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not create the root directory"
fi
MKCOL  "${TEST_DIR}/level1"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not create the nested directory"
fi
DELETE "${TEST_DIR}"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not remove the root directory"
fi
echo

# Recursive two levels
echo "Recursive two levels"
MKCOL  "${TEST_DIR}"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not create the root directory"
fi
MKCOL  "${TEST_DIR}/level1"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not remove the first level directory"
fi
MKCOL  "${TEST_DIR}/level1/level2"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not remove the second level directory"
fi
DELETE "${TEST_DIR}"
if [ $HTTP_CODE -lt 200 ] || [ $HTTP_CODE -gt 299 ]; then
  cat ${DAVLIB_LOG}
  TEST_FAILED "Could not remove the root directory"
fi
echo

# Done here
TEST_PASSED

