Skip to content

Commit 6add067

Browse files
ARCH-2011 - Add support files for testing
1 parent fb63da2 commit 6add067

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

test/assert-dir-does-not-exist.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
dir=''
4+
5+
6+
for arg in "$@"; do
7+
case $arg in
8+
--dir)
9+
dir=$2
10+
shift # Remove argument --name from `$@`
11+
shift # Remove argument value from `$@`
12+
;;
13+
esac
14+
done
15+
16+
echo "
17+
Asserting '$dir' does not exist"
18+
19+
if [ -d "$dir" ]; then
20+
echo "The target directory exists when it should not."
21+
exit 1
22+
else
23+
echo "The target directory does not exist, which is expected."
24+
fi

test/assert-dir-exists.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
dir=''
4+
5+
6+
for arg in "$@"; do
7+
case $arg in
8+
--dir)
9+
dir=$2
10+
shift # Remove argument --name from `$@`
11+
shift # Remove argument value from `$@`
12+
;;
13+
esac
14+
done
15+
16+
echo "
17+
Asserting '$dir' exists"
18+
19+
if [ -d "$dir" ]; then
20+
echo "The target directory exists, which is expected."
21+
else
22+
echo "The target directory does not exist but it should."
23+
exit 1
24+
fi
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
name=''
4+
expectedContents=''
5+
fileName=''
6+
7+
for arg in "$@"; do
8+
case $arg in
9+
--name)
10+
name=$2
11+
shift # Remove argument --name from `$@`
12+
shift # Remove argument value from `$@`
13+
;;
14+
--expectedContents)
15+
expectedContents=$2
16+
shift # Remove argument --expected from `$@`
17+
shift # Remove argument value from `$@`
18+
;;
19+
--fileName)
20+
fileName=$2
21+
shift # Remove argument --actual from `$@`
22+
shift # Remove argument value from `$@`
23+
;;
24+
25+
esac
26+
done
27+
28+
echo "
29+
Asserting file contents match:
30+
File with expected contents: '$expectedContents'
31+
File with actual contents: '$fileName'"
32+
33+
# First make sure the actual file exists
34+
if [ -f "$fileName" ]
35+
then
36+
echo "The file with actual contents exists which is expected."
37+
actualFileContents=$(cat $fileName)
38+
else
39+
echo "The file with actual contents does not exist which is not expected"
40+
exit 1
41+
fi
42+
expectedFileContents=$(cat $expectedContents)
43+
44+
# Then print the contents
45+
echo "::group::Expected file contents"
46+
echo "$expectedFileContents"
47+
echo "::endgroup::"
48+
49+
echo "::group::Actual file contents"
50+
echo "$actualFileContents"
51+
echo "::endgroup::"
52+
53+
# And finally compare the contents
54+
if echo "$actualFileContents" | grep -q "$expectedFileContents"; then
55+
echo "The actual contents contain the expected cotnents, which is expected."
56+
else
57+
echo "The actual contents do not contain the expected contents, which is not expected."
58+
exit 1
59+
fi

test/assert-value-is-empty.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
4+
name=''
5+
value=''
6+
7+
for arg in "$@"; do
8+
case $arg in
9+
--name)
10+
name=$2
11+
shift # Remove argument --name from `$@`
12+
shift # Remove argument value from `$@`
13+
;;
14+
--value)
15+
value=$2
16+
shift # Remove argument --expected from `$@`
17+
shift # Remove argument value from `$@`
18+
;;
19+
esac
20+
done
21+
22+
echo "
23+
Asserting $name is empty
24+
$name value: '$value'"
25+
26+
if [ -z "$value" ]
27+
then
28+
echo "$name is empty which is expected."
29+
else
30+
echo "$name is not empty which is not expected."
31+
exit 1
32+
fi

test/assert-values-match.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
name=''
4+
expectedValue=''
5+
actualValue=''
6+
7+
for arg in "$@"; do
8+
case $arg in
9+
--name)
10+
name=$2
11+
shift # Remove argument --name from `$@`
12+
shift # Remove argument value from `$@`
13+
;;
14+
--expected)
15+
expectedValue=$2
16+
shift # Remove argument --expected from `$@`
17+
shift # Remove argument value from `$@`
18+
;;
19+
--actual)
20+
actualValue=$2
21+
shift # Remove argument --actual from `$@`
22+
shift # Remove argument value from `$@`
23+
;;
24+
25+
esac
26+
done
27+
28+
echo "
29+
Asserting $name values match
30+
Expected $name: '$expectedValue'
31+
Actual $name: '$actualValue'"
32+
33+
if [ "$expectedValue" != "$actualValue" ]; then
34+
echo "The expected $name does not match the actual $name."
35+
exit 1
36+
else
37+
echo "The expected and actual $name values match."
38+
fi

0 commit comments

Comments
 (0)