mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Use alpine images to make tests take less time (#629)
* Use retry func while trying to ping SQL datastore
- implements retry func specifically for SQL datastore ping
- fmt fixes
- using sqlx.Db.PingContext instead of sqlx.Db.Ping
- propogate context to SQL datastore
* Use alpine images to make tests take less time
* use PG alpine
* use Minio alpine
* no official alpine distro for MySQL, uhhh :(
* install swagger tool instead of docker image
* use retry func to confirm that datastore is okay before running tests
* Store swagger tool at Fn during CI time
somehow it's a problem to put binary to ${GOPATH}/bin
* Adjust swagger tool reference path
* Revert minio image
* Use amd64/alpine-based swagger tool image for API spec validation
* Cleanup
This commit is contained in:
committed by
Reed Allman
parent
c9ab6b9729
commit
4bb0744853
1
.gitignore
vendored
1
.gitignore
vendored
@@ -32,4 +32,3 @@ fnlb/fnlb
|
||||
/fnserver
|
||||
*iml
|
||||
target/
|
||||
fn-api-tests.test
|
||||
|
||||
6
Makefile
6
Makefile
@@ -46,16 +46,14 @@ img-error:
|
||||
docker pull fnproject/error
|
||||
img-hello:
|
||||
docker pull fnproject/hello
|
||||
img-swagger:
|
||||
docker pull quay.io/goswagger/swagger
|
||||
img-mysql:
|
||||
docker pull mysql
|
||||
img-postgres:
|
||||
docker pull postgres
|
||||
docker pull postgres:9.3-alpine
|
||||
img-minio:
|
||||
docker pull minio/minio
|
||||
|
||||
pull-images: img-sleeper img-error img-hello img-swagger img-mysql img-postgres img-minio
|
||||
pull-images: img-sleeper img-error img-hello img-mysql img-postgres img-minio
|
||||
|
||||
test-datastore:
|
||||
cd api/datastore && go test -v ./...
|
||||
|
||||
23
api_test.sh
23
api_test.sh
@@ -1,24 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -exo pipefail
|
||||
|
||||
function host {
|
||||
case ${DOCKER_LOCATION:-localhost} in
|
||||
localhost)
|
||||
echo "localhost"
|
||||
;;
|
||||
docker_ip)
|
||||
if [[ ! -z ${DOCKER_HOST} ]]
|
||||
then
|
||||
DOCKER_IP=`echo ${DOCKER_HOST} | awk -F/ '{print $3}'| awk -F: '{print $1}'`
|
||||
fi
|
||||
source ./helpers.sh
|
||||
|
||||
echo ${DOCKER_IP}
|
||||
;;
|
||||
container_ip)
|
||||
echo "$(docker inspect -f '{{.NetworkSettings.IPAddress}}' ${1})"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
remove_containers
|
||||
|
||||
case "$1" in
|
||||
"sqlite3" )
|
||||
@@ -40,7 +25,7 @@ case "$1" in
|
||||
"postgres" )
|
||||
DB_CONTAINER="func-postgres-test"
|
||||
docker rm -fv ${DB_CONTAINER} || echo No prev test db container
|
||||
docker run --name ${DB_CONTAINER} -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres
|
||||
docker run --name ${DB_CONTAINER} -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres:9.3-alpine
|
||||
POSTGRES_HOST=`host ${DB_CONTAINER}`
|
||||
POSTGRES_PORT=5432
|
||||
export FN_DB_URL="postgres://postgres:root@${POSTGRES_HOST}:${POSTGRES_PORT}/funcs?sslmode=disable"
|
||||
@@ -67,3 +52,5 @@ esac
|
||||
#pwd
|
||||
#./fn-api-tests.test -test.v -test.parallel ${2:-1} ./...; cd ../../
|
||||
cd test/fn-api-tests && FN_API_URL="http://localhost:8080" FN_DB_URL=${FN_DB_URL} go test -v -parallel ${2:-1} ./...; cd ../../
|
||||
|
||||
remove_containers
|
||||
27
helpers.sh
Normal file
27
helpers.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
set -exo pipefail
|
||||
|
||||
function host {
|
||||
case ${DOCKER_LOCATION:-localhost} in
|
||||
localhost)
|
||||
echo "localhost"
|
||||
;;
|
||||
docker_ip)
|
||||
if [[ ! -z ${DOCKER_HOST} ]]
|
||||
then
|
||||
DOCKER_IP=`echo ${DOCKER_HOST} | awk -F/ '{print $3}'| awk -F: '{print $1}'`
|
||||
fi
|
||||
|
||||
echo ${DOCKER_IP}
|
||||
;;
|
||||
container_ip)
|
||||
echo "$(docker inspect -f '{{.NetworkSettings.IPAddress}}' ${1})"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function remove_containers {
|
||||
docker rm -fv func-postgres-test 2>/dev/null || true
|
||||
docker rm -fv func-mysql-test 2>/dev/null || true
|
||||
docker rm -fv func-minio-test 2>/dev/null || true
|
||||
}
|
||||
29
test.sh
29
test.sh
@@ -2,34 +2,12 @@
|
||||
# Top level test script to start all other tests
|
||||
set -exuo pipefail
|
||||
|
||||
function host {
|
||||
case ${DOCKER_LOCATION:-localhost} in
|
||||
localhost)
|
||||
echo "localhost"
|
||||
;;
|
||||
docker_ip)
|
||||
if [[ ! -z ${DOCKER_HOST} ]]
|
||||
then
|
||||
DOCKER_IP=`echo ${DOCKER_HOST} | awk -F/ '{print $3}'| awk -F: '{print $1}'`
|
||||
fi
|
||||
|
||||
echo ${DOCKER_IP}
|
||||
;;
|
||||
container_ip)
|
||||
echo "$(docker inspect -f '{{.NetworkSettings.IPAddress}}' ${1})"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function remove_containers {
|
||||
docker rm -fv func-postgres-test 2>/dev/null || true
|
||||
docker rm -fv func-mysql-test 2>/dev/null || true
|
||||
docker rm -fv func-minio-test 2>/dev/null || true
|
||||
}
|
||||
source ./helpers.sh
|
||||
|
||||
remove_containers
|
||||
|
||||
docker run --name func-postgres-test -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres
|
||||
docker run --name func-postgres-test -e "POSTGRES_DB=funcs" -e "POSTGRES_PASSWORD=root" -p 5432:5432 -d postgres:9.3-alpine
|
||||
docker run --name func-mysql-test -p 3306:3306 -e MYSQL_DATABASE=funcs -e MYSQL_ROOT_PASSWORD=root -d mysql
|
||||
docker run -d -p 9000:9000 --name func-minio-test -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=password" minio/minio server /data
|
||||
|
||||
@@ -51,5 +29,4 @@ go vet $(go list ./... | grep -v vendor)
|
||||
|
||||
remove_containers
|
||||
|
||||
docker run -v `pwd`:/go/src/github.com/fnproject/fn --rm quay.io/goswagger/swagger validate /go/src/github.com/fnproject/fn/docs/swagger.yml
|
||||
|
||||
docker run -v `pwd`:/go/src/github.com/fnproject/fn --rm fnproject/swagger:0.0.1 /go/src/github.com/fnproject/fn/docs/swagger.yml
|
||||
|
||||
BIN
test/fn-api-tests/fn-api-tests.test
Executable file
BIN
test/fn-api-tests/fn-api-tests.test
Executable file
Binary file not shown.
Reference in New Issue
Block a user