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/sysrepo.cpp b/tests/sysrepo.cpp
index ea468aa..f5476ef 100644
--- a/tests/sysrepo.cpp
+++ b/tests/sysrepo.cpp
@@ -10,7 +10,6 @@
 
 #include "sysrepo_access.hpp"
 #include "sysrepo_subscription.hpp"
-#include "sysrepo_vars.hpp"
 
 class MockRecorder : public Recorder {
 public:
@@ -19,12 +18,6 @@
 
 TEST_CASE("setting values")
 {
-    if (system(SYSREPOCTLEXECUTABLE " --uninstall --module example-schema > /dev/null") != 0) {
-        // uninstall can fail if it isn't already installed -> do nothing
-        // This crappy comment is here due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
-    }
-    REQUIRE(system(SYSREPOCTLEXECUTABLE " --install --yang " EXAMPLE_SCHEMA_LOCATION " > /dev/null") == 0);
-
     trompeloeil::sequence seq1;
     MockRecorder mock;
     SysrepoSubscription subscription(&mock);
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