blob: 3b9b05c7475166b2d3960b8aec924cff689ecda2 [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
Mate Lakat2781f3b2013-12-11 13:41:54 +000038 return 1
Euan Harris6f001712013-07-10 16:30:31 +010039 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
Mate Lakat085abd82013-12-11 12:21:12 +000076 echo "Mock test does not implement the requested function: ${1:-}"
Mate Lakat57e3da92013-03-22 16:34:05 +000077 exit 1
78}
Mate Lakatfe586b12013-03-28 15:02:27 +000079
Mate Lakat2781f3b2013-12-11 13:41:54 +000080function die_with_error {
81 echo "$1" >> $DEAD_MESSAGES
82}
83
Mate Lakatfe586b12013-03-28 15:02:27 +000084function xe {
85 cat $XE_RESPONSE
86 {
87 for i in $(seq "$#")
88 do
89 eval "echo \"\$$i\""
90 done
91 } >> $XE_CALLS
92}