xenapi: Extract plugin installation functions
This change extracts the plugin installation functions, and covers the
extracted functions with tests. Use:
./test_funtions.sh run_tests
to run the tests.
Change-Id: I1d78d9e8cc4d52ee2df83d07e4c74dda4805f21a
diff --git a/tools/xen/mocks b/tools/xen/mocks
new file mode 100644
index 0000000..b006558
--- /dev/null
+++ b/tools/xen/mocks
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+test ! -e "$LIST_OF_ACTIONS" && {
+ echo "Mocking is not set up properly."
+ echo "LIST_OF_ACTIONS should point to an existing file."
+ exit 1
+}
+
+test ! -e "$LIST_OF_DIRECTORIES" && {
+ echo "Mocking is not set up properly."
+ echo "LIST_OF_DIRECTORIES should point to an existing file."
+ exit 1
+}
+
+function mktemp {
+ if test "${1:-}" = "-d";
+ then
+ echo "tempdir"
+ else
+ echo "tempfile"
+ fi
+}
+
+function wget {
+ echo "wget $@" >> $LIST_OF_ACTIONS
+}
+
+function mkdir {
+ if test "${1:-}" = "-p";
+ then
+ echo "$2" >> $LIST_OF_DIRECTORIES
+ fi
+}
+
+function unzip {
+ echo "Random rubbish from unzip"
+ echo "unzip $@" >> $LIST_OF_ACTIONS
+}
+
+function rm {
+ echo "rm $@" >> $LIST_OF_ACTIONS
+}
+
+function [ {
+ if test "${1:-}" = "-d";
+ then
+ echo "[ $@" >> $LIST_OF_ACTIONS
+ for directory in $(cat $LIST_OF_DIRECTORIES)
+ do
+ if test "$directory" = "$2"
+ then
+ return 0
+ fi
+ done
+ return 1
+ fi
+ echo "Mock test does not implement the requested function"
+ exit 1
+}