add makefile tests and travis config

This commit is contained in:
Robin Appelman 2018-04-17 12:36:16 +02:00
commit c0337e55d9
6 changed files with 90 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
/test
/target
**/*.rs.bk

9
.travis.yml Normal file
View file

@ -0,0 +1,9 @@
sudo: required
services:
- docker
- redis-server
install:
- docker pull ekidd/rust-musl-builder:latest
script:
- "./travis-build.sh notify-redis ${TRAVIS_OS_NAME}"
- "./test.sh ./notify-redis-${TRAVIS_OS_NAME}"

8
Dockerfile Normal file
View file

@ -0,0 +1,8 @@
FROM ekidd/rust-musl-builder
# We need to add the source code to the image because `rust-musl-builder`
# assumes a UID of 1000, but TravisCI has switched to 2000.
ADD . ./
RUN sudo chown -R rust:rust .
CMD cargo build --release

9
Makefile Normal file
View file

@ -0,0 +1,9 @@
all: target/x86_64-unknown-linux-musl/release/notify-redis
target/x86_64-unknown-linux-musl/release/notify-redis: Cargo.toml src/main.rs
docker run --rm -it -v "$(CURDIR):/home/rust/src" ekidd/rust-musl-builder cargo build --release
.PHONY: test
test: target/x86_64-unknown-linux-musl/release/notify-redis
./test.sh

56
test.sh Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
function assert_notify {
actual="$(redis-cli rpop notify)"
if [ "$actual" != "$1" ]
then
echo "'$actual' not equal to expected '$1'"
killall $(basename $bin)
exit 1
fi
}
mkdir -p test
rm test/*
redis-cli del notify
bin=$1;
: ${bin:="target/x86_64-unknown-linux-musl/release/notify-redis"}
echo "running tests with $bin"
$bin "$PWD/test" redis://localhost notify &
sleep 1
echo foo > test/foo.txt
sleep 2
assert_notify "write|$(pwd)/test/foo.txt"
assert_notify ''
mv test/foo.txt test/bar.txt
sleep 2
assert_notify "rename|$(pwd)/test/foo.txt|$(pwd)/test/bar.txt"
assert_notify ""
rm test/bar.txt
echo asd > test/bar.txt
sleep 2
assert_notify "write|$(pwd)/test/bar.txt"
assert_notify ""
rm test/bar.txt
sleep 2
echo asd > test/bar.txt
sleep 2
assert_notify "remove|$(pwd)/test/bar.txt"
assert_notify "write|$(pwd)/test/bar.txt"
assert_notify ""
killall $(basename $bin)

7
travis-build.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
echo "Building static binaries using ekidd/rust-musl-builder"
docker build -t build-"$1"-image .
docker run -it --name build-"$1" build-"$1"-image
docker cp build-"$1":/home/rust/src/target/x86_64-unknown-linux-musl/release/"$1" "$1-$2"
docker rm build-"$1"
docker rmi build-"$1"-image