Move sysrepo test preparations out of the cpp file

Setting up tests using calls to system() is not good, because ctest
doesn't know which tests can be parallelized. This change moves test
preparations outside of the cpp files and makes use of fixtures for
setup and cleanup tests.

The tests/sysrepoctl-manage-module.sh script comes from cla-sysrepo,
commit d39cc7797ea371e90711ee0ed317cadc91c8368e

Change-Id: I7d6edd2988321dbc58b0b0520f088ee018742e31
diff --git a/tests/sysrepoctl-manage-module.sh b/tests/sysrepoctl-manage-module.sh
new file mode 100755
index 0000000..e9693bb
--- /dev/null
+++ b/tests/sysrepoctl-manage-module.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+set -eux -o pipefail
+shopt -s failglob
+
+SYSREPOCTL="${1}"
+shift
+if [[ ! -x "${SYSREPOCTL}" ]]; then
+  echo "Cannot locate \$SYSREPOCTL"
+  exit 1
+fi
+
+SYSREPOCFG="${1}"
+shift
+if [[ ! -x "${SYSREPOCFG}" ]]; then
+  echo "Cannot locate \$SYSREPOCFG"
+  exit 1
+fi
+
+MODE="${1}"
+shift
+
+if [[ ! -f "${1}" ]]; then
+  echo "No YANG file specified"
+  exit 1
+fi
+
+MODULE=$(basename --suffix .yang "${1}")
+YANG_DIR=$(dirname "${1}")
+
+if [[ "${MODE}" == "install" ]]; then
+  ${SYSREPOCTL} --uninstall --module "${MODULE}" || true
+  ${SYSREPOCTL} --install --yang "${1}"
+  JSON_DATA="${YANG_DIR}/${MODULE}.json"
+  XML_DATA="${YANG_DIR}/${MODULE}.startup.xml"
+  if [[ -f "${JSON_DATA}" ]] ;then
+    ${SYSREPOCFG} -d startup -f json "${MODULE}" -i "${JSON_DATA}"
+  elif [[ -f "${XML_DATA}" ]]; then
+    ${SYSREPOCFG} -d startup -f xml "${MODULE}" -i "${XML_DATA}"
+  fi
+elif [[ "${MODE}" == "uninstall" ]]; then
+  ${SYSREPOCTL} --uninstall --module "${MODULE}"
+else
+  echo "Mode of operation not specified"
+  exit 1
+fi