-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.sh
executable file
·106 lines (94 loc) · 2.07 KB
/
test.sh
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
#!/usr/bin/env bash
# import env vars from the .env in the cwd
if [ -f ".env" ]; then
while IFS= read -r line; do
if [[ "$line" =~ ^\s*#.*$ || -z "$line" ]]; then
continue
fi
key=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
# skip comments
value=$(echo "$value" | sed -e "s/^'//" -e "s/'$//" -e 's/^"//' -e 's/"$//' -e 's/^[ \t]*//;s/[ \t]*$//')
export "$key=$value"
done <".env"
if [ -z "${E2E_SHACKLI}" ]; then
echo
echo "ERROR: a cookie fixture in the env variable \"E2E_SHACKLI\" is required for the E2E suite!"
echo "Install a valid \".env\" with TESTUSR/TESTPW vars set in the project root and run: pnpm generate-cookie"
echo "For more information, see CONTRIBUTING.md..."
echo
exit 1
fi
fi
IMAGE_NAME="chromeshack-e2e"
selinux_status() {
ENFORCING=false
if command -v getenforce &>/dev/null; then
local enforcing_status=$(getenforce)
if [ "$enforcing_status" == "Enforcing" ]; then
ENFORCING=true
fi
fi
}
selinux_status
RELABEL=""
if [[ "$ENFORCING" == true ]]; then
RELABEL=":z"
fi
build() {
docker build -f ./Dockerfile.e2etest -t "$IMAGE_NAME" --build-arg SCOOKIE="$E2E_SHACKLI"
}
run() {
mkdir -p "results/" && rm -rf "results/*"
docker run --rm --replace -it \
--ipc=host --security-opt seccomp=seccomp_profile.json \
-v "./results:/code/results${RELABEL}" \
-p "9323:9323" \
--name "$IMAGE_NAME" "$IMAGE_NAME" \
"${@}"
}
help() {
echo
echo "Usage: $0 [-b] [-r | -s] [-h]"
echo
echo " -b rebuild the image"
echo " -r run the test suite"
echo " -s open a shell inside the image"
echo " -h this message"
echo
exit 1
}
eval set -- "$(getopt -o bhrs -- "$@")"
if [[ $# -eq 1 ]]; then
build
run pnpm test
exit 0
fi
while [[ $# -gt 1 ]]; do
case "$1" in
-b)
build # not mutually exclusive
shift
;;
-r)
run pnpm test
shift
break
;;
-s)
run /bin/bash
shift
break
;;
-h)
help
;;
--)
help
;;
*)
help
;;
esac
done
exit 0