Skip to content

Commit 02d5647

Browse files
authored
Merge pull request softprops#43 from softprops/ci-integration-tests
Ci integration tests
2 parents 121939a + c483376 commit 02d5647

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

tests/bashtest.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TESTS=0
1010
FAILED=0
1111

1212
# Verify that a command succeeds
13-
function assert_success() {
13+
assert() {
1414
MESSAGE="$1"
1515
shift
1616
COMMAND="$@"
@@ -26,7 +26,7 @@ function assert_success() {
2626
fi
2727
}
2828

29-
function end_tests() {
29+
end_tests() {
3030
if ((FAILED > 0))
3131
then
3232
echo

tests/test-multi-func/test-out.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"foo":"bar"}

tests/test.sh

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,77 @@
11
#!/usr/bin/env bash
22

33
# Directory of the integration test
4-
HERE=$(dirname $0)
4+
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
55
# Root directory of the repository
6-
DIST=$(cd $HERE/..; echo $PWD)
6+
DIST=$(cd "$HERE"/..; pwd)
77

8-
source ${HERE}/bashtest.sh
8+
source "${HERE}"/bashtest.sh
99

1010
# test packaing with a single binary
11-
function package_bin() {
11+
package_bin() {
1212
rm -rf target/lambda/release > /dev/null 2>&1
1313
docker run --rm \
1414
-e BIN="$1" \
15-
-v ${PWD}:/code \
16-
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
17-
-v ${HOME}/.cargo/git:/root/.cargo/git \
15+
-v "${PWD}":/code \
16+
-v "${HOME}"/.cargo/registry:/root/.cargo/registry \
17+
-v "${HOME}"/.cargo/git:/root/.cargo/git \
1818
softprops/lambda-rust && \
19-
ls target/lambda/release/bootstrap.zip > /dev/null 2>&1
19+
ls target/lambda/release/"$1".zip > /dev/null 2>&1
2020
}
2121

2222
# test packaging all binaries
23-
function package_all() {
23+
package_all() {
2424
rm -rf target/lambda/release > /dev/null 2>&1
2525
docker run --rm \
26-
-v ${PWD}:/code \
27-
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
28-
-v ${HOME}/.cargo/git:/root/.cargo/git \
26+
-v "${PWD}":/code \
27+
-v "${HOME}"/.cargo/registry:/root/.cargo/registry \
28+
-v "${HOME}"/.cargo/git:/root/.cargo/git \
2929
softprops/lambda-rust && \
30-
ls target/lambda/release/bootstrap.zip > /dev/null 2>&1
30+
ls target/lambda/release/"${1}".zip > /dev/null 2>&1
3131
}
3232

3333
# test packaging with PROFILE=dev
34-
function package_all_dev_profile() {
34+
package_all_dev_profile() {
3535
rm -rf target/lambda/debug > /dev/null 2>&1
3636
docker run --rm \
3737
-e PROFILE=dev \
38-
-v ${PWD}:/code \
39-
-v ${HOME}/.cargo/registry:/root/.cargo/registry \
40-
-v ${HOME}/.cargo/git:/root/.cargo/git \
38+
-v "${PWD}":/code \
39+
-v "${HOME}"/.cargo/registry:/root/.cargo/registry \
40+
-v "${HOME}"/.cargo/git:/root/.cargo/git \
4141
softprops/lambda-rust && \
42-
ls target/lambda/debug/bootstrap.zip > /dev/null 2>&1
42+
ls target/lambda/debug/"${1}".zip > /dev/null 2>&1
4343
}
4444

4545
for project in test-func test-multi-func; do
46-
cd ${HERE}/${project}
46+
cd "${HERE}"/"${project}"
47+
echo "👩‍🔬 Running tests for $project"
48+
49+
if [[ "$project" == test-func ]]; then
50+
bin_name=bootstrap
51+
else
52+
bin_name=test-func
53+
fi
4754

4855
# package tests
49-
assert_success "it packages single bin" package_bin bootstrap
56+
assert "it packages single bins" package_bin "${bin_name}"
5057

51-
assert_success "it packages all bins with dev profile" package_all_dev_profile
58+
assert "it packages all bins with dev profile" package_all_dev_profile "${bin_name}"
5259

53-
assert_success "it packages all bins" package_all
60+
assert "it packages all bins" package_all "${bin_name}"
5461

5562
# verify packaged artifact by invoking it using the lambdaci "provided" docker image
5663
rm test-out.log > /dev/null 2>&1
5764
rm -rf /tmp/lambda > /dev/null 2>&1
5865
unzip -o \
59-
target/lambda/release/bootstrap.zip \
66+
target/lambda/release/"${bin_name}".zip \
6067
-d /tmp/lambda > /dev/null 2>&1 && \
6168
docker run \
6269
-i -e DOCKER_LAMBDA_USE_STDIN=1 \
6370
--rm \
6471
-v /tmp/lambda:/var/task \
6572
lambci/lambda:provided < test-event.json | grep -v RequestId | grep -v '^\W*$' > test-out.log
6673

67-
assert_success "when invoked, it produces expected output" diff test-event.json test-out.log
74+
assert "when invoked, it produces expected output" diff test-event.json test-out.log
6875
done
6976

7077
end_tests

0 commit comments

Comments
 (0)