blob: 94b0ca4d02b61c3c9a59b61a7a10ffb05c1d29c7 [file] [log] [blame]
Mate Lakat57e3da92013-03-22 16:34:05 +00001#!/bin/bash
2
3test ! -e "$LIST_OF_ACTIONS" && {
4 echo "Mocking is not set up properly."
5 echo "LIST_OF_ACTIONS should point to an existing file."
6 exit 1
7}
8
9test ! -e "$LIST_OF_DIRECTORIES" && {
10 echo "Mocking is not set up properly."
11 echo "LIST_OF_DIRECTORIES should point to an existing file."
12 exit 1
13}
14
Mate Lakatfe586b12013-03-28 15:02:27 +000015test ! -e "$XE_RESPONSE" && {
16 echo "Mocking is not set up properly."
17 echo "XE_RESPONSE should point to an existing file."
18 exit 1
19}
20
21test ! -e "$XE_CALLS" && {
22 echo "Mocking is not set up properly."
23 echo "XE_CALLS should point to an existing file."
24 exit 1
25}
26
Mate Lakat57e3da92013-03-22 16:34:05 +000027function mktemp {
28 if test "${1:-}" = "-d";
29 then
30 echo "tempdir"
31 else
32 echo "tempfile"
33 fi
34}
35
36function wget {
Euan Harris6f001712013-07-10 16:30:31 +010037 if [[ $@ =~ "failurl" ]]; then
38 exit 1
39 fi
Mate Lakat57e3da92013-03-22 16:34:05 +000040 echo "wget $@" >> $LIST_OF_ACTIONS
41}
42
43function mkdir {
44 if test "${1:-}" = "-p";
45 then
46 echo "$2" >> $LIST_OF_DIRECTORIES
47 fi
48}
49
50function unzip {
51 echo "Random rubbish from unzip"
52 echo "unzip $@" >> $LIST_OF_ACTIONS
53}
54
55function rm {
56 echo "rm $@" >> $LIST_OF_ACTIONS
57}
58
Mate Lakatfe586b12013-03-28 15:02:27 +000059function ln {
60 echo "ln $@" >> $LIST_OF_ACTIONS
61}
62
Mate Lakat57e3da92013-03-22 16:34:05 +000063function [ {
64 if test "${1:-}" = "-d";
65 then
66 echo "[ $@" >> $LIST_OF_ACTIONS
67 for directory in $(cat $LIST_OF_DIRECTORIES)
68 do
69 if test "$directory" = "$2"
70 then
71 return 0
72 fi
73 done
74 return 1
75 fi
76 echo "Mock test does not implement the requested function"
77 exit 1
78}
Mate Lakatfe586b12013-03-28 15:02:27 +000079
80function xe {
81 cat $XE_RESPONSE
82 {
83 for i in $(seq "$#")
84 do
85 eval "echo \"\$$i\""
86 done
87 } >> $XE_CALLS
88}