forked from rust-serverless/lambda-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
路105 lines (88 loc) 路 2.59 KB
/
Copy pathtest.sh
File metadata and controls
executable file
路105 lines (88 loc) 路 2.59 KB
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
#!/bin/bash
# decor
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
# test state
TESTS=0
FAILED=0
# Verify that a command succeeds
function assert_success() {
MESSAGE="$1"
shift
COMMAND="$@"
((++TESTS))
if $COMMAND
then
echo -e "馃憤 ${GREEN} $MESSAGE: success${NC}"
else
echo -e "馃憥 ${RED} ${MESSAGE}: fail${NC}"
((++FAILED))
fi
}
function end_tests() {
if ((FAILED > 0))
then
echo
echo -e "馃拃 ${RED} Ran ${TESTS} tests, ${FAILED} failed.${NC}"
exit $FAILED
else
echo
echo -e "馃憣 ${GREEN} ${TESTS} tests passed.${NC}"
exit 0
fi
}
# Directory of the integration test
HERE=$(dirname $0)
# Root directory of the repository
DIST=$(cd $HERE/..; echo $PWD)
cd ${HERE}/test-func
# test packaing with a single binary
function package_bin() {
rm -rf target/lambda/release > /dev/null 2>&1
docker run --rm \
-e BIN="$1" \
-v ${PWD}:/code \
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
-v ${HOME}/.cargo/git:/root/.cargo/git \
softprops/lambda-rust && \
ls target/lambda/release/bootstrap.zip > /dev/null 2>&1
}
# test packaging all binaries
function package_all() {
rm -rf target/lambda/release > /dev/null 2>&1
docker run --rm \
-v ${PWD}:/code \
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
-v ${HOME}/.cargo/git:/root/.cargo/git \
softprops/lambda-rust && \
ls target/lambda/release/bootstrap.zip > /dev/null 2>&1
}
# test packaging with PROFILE=dev
function package_all_dev_profile() {
rm -rf target/lambda/debug > /dev/null 2>&1
docker run --rm \
-e PROFILE=dev \
-v ${PWD}:/code \
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
-v ${HOME}/.cargo/git:/root/.cargo/git \
softprops/lambda-rust && \
ls target/lambda/debug/bootstrap.zip > /dev/null 2>&1
}
# package tests
assert_success "it packages single bin" package_bin bootstrap
assert_success "it packages all bins with dev profile" package_all_dev_profile
assert_success "it packages all bins" package_all
# verify packaged artifact by invoking it using the lambdaci "provided" docker image
rm test-out.log > /dev/null 2>&1
rm -rf /tmp/lambda > /dev/null 2>&1
unzip -o \
target/lambda/release/bootstrap.zip \
-d /tmp/lambda > /dev/null 2>&1 && \
docker run \
-i -e DOCKER_LAMBDA_USE_STDIN=1 \
--rm \
-v /tmp/lambda:/var/task \
lambci/lambda:provided < test-event.json | grep -v RequestId | grep -v '^\W*$' > test-out.log
assert_success "when invoked, it produces expected output" diff test-event.json test-out.log
end_tests