This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest
executable file
·124 lines (104 loc) · 2.74 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#/usr/bin/env bash
set -eu
function build {
s2i build --rm --incremental --loglevel=1 . accursoft/ghc test
}
function remove {
docker rm -f test >/dev/null
}
function begin {
echo
echo " * Testing $1 ..."
}
function run {
begin "$1"
build
docker run --name test -d -p 8080:8080 -u 1001 test >/dev/null
sleep 0.1
}
function fail {
echo " * $1 FAILED"
exit 1
}
function check {
run "$1"
curl -sS localhost:8080 | grep -q $2 || fail "$1"
remove
}
function check_build {
begin "$1"
build |& tee ../build.log
grep -q "$2" ../build.log || fail "$1"
}
#create app
mkdir server
cp test-server/* server
cd server
mkdir -p .s2i/markers .s2i/hooks
check "create app" "Welcome"
#cabal flags
cp Main.hs test.hs
sed -i 's/Welcome/Greetings/' test.hs
echo "Flag A" >>server.cabal
sed -i 's/main-is: *Main.hs/if flag(a) {main-is:Main.hs} else {main-is:test.hs}/' server.cabal
echo "b" >.s2i/markers/cabal_flags
check "enable flags" "Welcome"
echo "-a" >>.s2i/markers/cabal_flags
check "unset flag" "Greetings"
rm .s2i/markers/cabal_flags
#run_tests
touch .s2i/markers/run_tests
echo "main = return ()" >test.hs
echo "test-suite test
type:exitcode-stdio-1.0
main-is:test.hs
build-depends:groups" >>server.cabal
#check that test dependencies are installed
check "run_tests" "Welcome"
rm .s2i/markers/run_tests
#pre_build hook
echo "sed -i 's/Welcome/Greetings/' Main.hs" >.s2i/hooks/pre_build
chmod +x .s2i/hooks/pre_build
check "pre_build hook" "Greetings"
rm .s2i/hooks/pre_build
#preserve installed packages
sed -i 's/base/base,groups/' server.cabal
check_build "use previously installed package" "server"
grep -q "groups2" ../build.log && fail "package groups from earlier build was not reused"
#sequential build
touch .s2i/markers/sequential
check_build "sequential build" "Compiling"
rm .s2i/markers/sequential
#cabal_update
touch .s2i/markers/cabal_update
check_build "cabal_update" "Downloading the latest package list"
rm .s2i/markers/cabal_update
#logs
touch .s2i/markers/logs
check_build "logs" "Compiling"
rm .s2i/markers/logs
#user security
echo "touch /home/build/tamper" >.s2i/hooks/pre_run
chmod +x .s2i/hooks/pre_run
run "user security"
docker logs test |& grep -iq " Permission denied" || fail "user security"
remove
#pre_run hook
echo "echo Greetings >/tmp/response" >.s2i/hooks/pre_run
sed -i '
s/responseLBS/responseFile/
s|"Welcome"|"/tmp/response"\n Nothing|
' Main.hs
chmod +x .s2i/hooks/pre_run
check "pre_run hook" "Greetings"
rm .s2i/hooks/pre_run
echo
echo " * PASSED"
echo
#clear up
cd ..
rm -r server build.log
docker rmi test >/dev/null
docker inspect -f '{{index .ContainerConfig.Labels "io.k8s.display-name"}}
{{index .ContainerConfig.Labels "io.k8s.description"}}
{{index .ContainerConfig.Labels "io.openshift.tags"}}' accursoft/ghc