2
2
3
3
# Directory of the integration test
4
4
HERE=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
5
- # Root directory of the repository
6
- DIST=$( cd " $HERE " /..; pwd)
7
5
: " ${IMAGE:= rustserverless/ lambda-rust} "
8
6
9
7
source " ${HERE} " /bashtest.sh
@@ -12,12 +10,12 @@ source "${HERE}"/bashtest.sh
12
10
package_bin () {
13
11
rm -rf target/lambda/release > /dev/null 2>&1
14
12
docker run --rm \
15
- -u $( id -u) : $( id -g) \
13
+ -u " $( id -u) " : " $( id -g) " \
16
14
-e BIN=" $1 " \
17
15
-v " ${PWD} " :/code \
18
16
-v " ${HOME} " /.cargo/registry:/cargo/registry \
19
17
-v " ${HOME} " /.cargo/git:/cargo/git \
20
- ${IMAGE} && \
18
+ " ${IMAGE} " && \
21
19
ls target/lambda/release/" ${1} " .zip > /dev/null 2>&1 &&
22
20
ls target/lambda/release/output/" ${1} " /bootstrap 2>&1 &&
23
21
ls target/lambda/release/output/" ${1} " /bootstrap.debug 2>&1
@@ -27,11 +25,11 @@ package_bin() {
27
25
package_all () {
28
26
rm -rf target/lambda/release > /dev/null 2>&1
29
27
docker run --rm \
30
- -u $( id -u) : $( id -g) \
28
+ -u " $( id -u) " : " $( id -g) " \
31
29
-v " ${PWD} " :/code \
32
30
-v " ${HOME} " /.cargo/registry:/cargo/registry \
33
31
-v " ${HOME} " /.cargo/git:/cargo/git \
34
- ${IMAGE} && \
32
+ " ${IMAGE} " && \
35
33
ls target/lambda/release/" ${1} " .zip > /dev/null 2>&1 &&
36
34
ls target/lambda/release/output/" ${1} " /bootstrap 2>&1 &&
37
35
ls target/lambda/release/output/" ${1} " /bootstrap.debug 2>&1
@@ -41,13 +39,13 @@ package_all() {
41
39
compile_without_packaging () {
42
40
rm -rf target/lambda/release > /dev/null 2>&1
43
41
docker run --rm \
44
- -u $( id -u) : $( id -g) \
42
+ -u " $( id -u) " : " $( id -g) " \
45
43
-e PACKAGE=false \
46
44
-v " ${PWD} " :/code \
47
45
-v " ${HOME} " /.cargo/registry:/cargo/registry \
48
46
-v " ${HOME} " /.cargo/git:/cargo/git \
49
- ${IMAGE} &&
50
- ! (ls target/lambda/release/" ${1} " .zip > /dev/null 2>&1 ) &&
47
+ " ${IMAGE} " &&
48
+ ! (ls target/lambda/release/" ${1} " .zip > /dev/null 2>&1 ) &&
51
49
ls target/lambda/release/output/" ${1} " /bootstrap 2>&1 &&
52
50
ls target/lambda/release/output/" ${1} " /bootstrap.debug 2>&1
53
51
}
@@ -56,19 +54,82 @@ compile_without_packaging() {
56
54
package_all_dev_profile () {
57
55
rm -rf target/lambda/debug > /dev/null 2>&1
58
56
docker run --rm \
59
- -u $( id -u) : $( id -g) \
57
+ -u " $( id -u) " : " $( id -g) " \
60
58
-e PROFILE=dev \
61
59
-v " ${PWD} " :/code \
62
60
-v " ${HOME} " /.cargo/registry:/cargo/registry \
63
61
-v " ${HOME} " /.cargo/git:/cargo/git \
64
- ${IMAGE} && \
62
+ " ${IMAGE} " && \
65
63
ls target/lambda/debug/" ${1} " .zip > /dev/null 2>&1 &&
66
64
ls target/lambda/release/output/" ${1} " /bootstrap 2>&1 &&
67
65
ls target/lambda/release/output/" ${1} " /bootstrap.debug 2>&1
68
66
}
69
67
68
+ verify_packaged_application () {
69
+ LAMBDA_RUNTIME_DIR=" /var/runtime"
70
+ LAMBDA_TASK_DIR=" /var/task"
71
+ HOOKS=" test-func-with-hooks"
72
+ TRY=1
73
+ MAX_TRY=10
74
+ TRIES_EXCEEDED=10
75
+ SLEEP=1
76
+ PACKAGE=" ${1} "
77
+ PROJECT=" ${2} "
78
+ TSFRACTION=$( date +%M%S)
79
+
80
+ clean_up () {
81
+ docker container stop lamb > /dev/null 2>&1
82
+ rm -f bootstrap > /dev/null 2>&1
83
+ rm -f output.log > /dev/null 2>&1
84
+ }
85
+
86
+ clean_up
87
+ rm -f test-out.log > /dev/null 2>&1
88
+
89
+ unzip -o \
90
+ target/lambda/release/" ${PACKAGE} " .zip
91
+
92
+ if [ " $PROJECT " = " ${HOOKS} " ]; then
93
+ docker build -t mylambda:" ${TSFRACTION} " -f- . << EOF
94
+ FROM public.ecr.aws/lambda/provided:al2
95
+ COPY bootstrap ${LAMBDA_RUNTIME_DIR}
96
+ COPY output.log ${LAMBDA_TASK_DIR}
97
+ CMD [ "function.handler" ]
98
+ EOF
99
+ else
100
+ docker build -t mylambda:" ${TSFRACTION} " -f- . << EOF
101
+ FROM public.ecr.aws/lambda/provided:al2
102
+ COPY bootstrap ${LAMBDA_RUNTIME_DIR}
103
+ CMD [ "function.handler" ]
104
+ EOF
105
+ fi
106
+ # rm -f bootstrap > /dev/null 2>&1
107
+ docker run \
108
+ --name lamb \
109
+ --rm \
110
+ -p 9000:8080 \
111
+ -d mylambda:" ${TSFRACTION} "
112
+
113
+ until curl -X POST \
114
+ -H " Content-Type: application/json" \
115
+ -d " @test-event.json" \
116
+ " http://localhost:9000/2015-03-31/functions/function/invocations" | \
117
+ grep -v RequestId | \
118
+ grep -v ' ^\W*$' > test-out.log; do
119
+ >&2 echo " waiting for service to spin up"
120
+ sleep ${SLEEP}
121
+ if [ ${TRY} = ${MAX_TRY} ]; then
122
+ exit ${TRIES_EXCEEDED}
123
+ else
124
+ TRY=$(( TRY + 1 ))
125
+ fi
126
+ done
127
+
128
+ clean_up
129
+ }
130
+
70
131
for project in test-func test-multi-func test-func-with-hooks; do
71
- cd " ${HERE} " /" ${project} "
132
+ cd " ${HERE} " /" ${project} " || exit 2
72
133
echo " 👩🔬 Running tests for $project with image $IMAGE "
73
134
74
135
if [[ " $project " == test-multi-func ]]; then
@@ -86,19 +147,8 @@ for project in test-func test-multi-func test-func-with-hooks; do
86
147
87
148
assert " it packages all bins" package_all " ${bin_name} "
88
149
89
- # verify packaged artifact by invoking it using the lambdaci "provided.al2" docker image
90
- rm -f output.log > /dev/null 2>&1
91
- rm -f test-out.log > /dev/null 2>&1
92
- rm -rf /tmp/lambda > /dev/null 2>&1
93
- unzip -o \
94
- target/lambda/release/" ${bin_name} " .zip \
95
- -d /tmp/lambda > /dev/null 2>&1 && \
96
- docker run \
97
- -i -e DOCKER_LAMBDA_USE_STDIN=1 \
98
- --rm \
99
- -v /tmp/lambda:/var/task \
100
- lambci/lambda:provided.al2 < test-event.json | grep -v RequestId | grep -v ' ^\W*$' > test-out.log
101
-
150
+ # verify packaged artifact by invoking it using the aws lambda "provided.al2" docker image
151
+ verify_packaged_application " ${bin_name} " " ${project} "
102
152
assert " when invoked, it produces expected output" diff expected-output.json test-out.log
103
153
done
104
154
0 commit comments