-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
e2e.sh
executable file
·48 lines (35 loc) · 1.52 KB
/
e2e.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
#!/bin/bash
image="tenjaa/concourse-github-app-token:${GITHUB_SHA}"
appId=74610
privateKey=$(cat test.private-key.pem)
checkEmpty=$(echo '{}' | docker run -i "${image}" /opt/resource/check)
checkReturnGiven=$(echo "{\"version\":{\"date\":\"some-date\"}}" | docker run -i "${image}" /opt/resource/check)
if [[ "$checkEmpty" != "[]" ]]; then
echo "Invalid checkEmpty: ${checkEmpty}"
exit 1
fi
if [[ "$checkReturnGiven" != '[{"date":"some-date"}]' ]]; then
echo "Invalid checkReturnGiven: ${checkReturnGiven}"
exit 1
fi
echo "Testing CHECK successfully done"
outDate=$(echo 'stdin is ignored anyway' | docker run -i "${image}" /opt/resource/out | jq -r '.version.date')
if ! date --iso-8601 -d "${outDate}"; then
echo "Error parsing date: outDate"
exit 1
fi
echo "Testing OUT successfully done"
inRequest="{\"source\":{\"appId\":${appId},\"user\":\"tenjaa\",\"privateKey\":\"${privateKey}\"},\"version\":{\"date\":\"some-date\"}}"
inResponse=$(echo "${inRequest}" | docker run -i "${image}" /opt/resource/in "/")
if [[ "$inResponse" != '{"version":{"date":"some-date"}}' ]]; then
echo "Invalid inResponse: ${inResponse}"
exit 1
fi
containerId=$(docker ps -a -q -l)
docker cp "${containerId}:/token" .
repo=$(curl -s -H "Accept: application/vnd.github.machine-man-preview+json" -H "Authorization: token $(cat token)" "https://api.github.com/installation/repositories" | jq -r '.repositories[0].name')
if [[ "$repo" != 'concourse-github-app-token' ]]; then
echo "Invalid repo: ${repo}"
exit 1
fi
echo "Testing IN successfully done"