first run at integ test using docker-compose

pull/3/head
josebarn 8 years ago
parent e2ca326b66
commit b138870433

@ -16,6 +16,13 @@ pipeline:
commands:
- go test ./api
run-tests-in-compose:
image: michalpodeszwa/docker-compose:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- ./script/drone-run-tests.sh api-tests
publish:
image: plugins/docker
repo: josebarn/hello-world

@ -1 +1 @@
eyJhbGciOiJIUzI1NiJ9.IyBOT1RFOiBSZWZlciBkcm9uZSBHbyBleGFtcGxlIGh0dHA6Ly9yZWFkbWUuZHJvbmUuaW8vMC41L3VzYWdlL2dvbGFuZy1leGFtcGxlLwp3b3Jrc3BhY2U6CiAgYmFzZTogL2dvCiAgcGF0aDogc3JjL2dpdGh1Yi5jb20vam9zZWJhcm4vZHJvbmUtd2l0aC1nbwoKcGlwZWxpbmU6CiAgYnVpbGQ6CiAgICBpbWFnZTogJHtJTUFHRX0KICAgIGNvbW1hbmRzOgogICAgICAtIGdvIGdldCAuLy4uLgogICAgICAtIGdvIGJ1aWxkCiAgICBkZWJ1ZzogdHJ1ZQoKICB1bml0LXRlc3Q6CiAgICBpbWFnZTogJHtJTUFHRX0KICAgIGNvbW1hbmRzOgogICAgICAtIGdvIHRlc3QgLi9hcGkKCiAgcHVibGlzaDoKICAgIGltYWdlOiBwbHVnaW5zL2RvY2tlcgogICAgcmVwbzogam9zZWJhcm4vaGVsbG8td29ybGQKICAgIHRhZ3M6IFsgMS4wLjAsIDEuMCwgbGF0ZXN0IF0KICAgIGRvY2tlcmZpbGU6IC4vZG9ja2VyL0RvY2tlcmZpbGUKICAgIHNlY3JldHM6IFsgRE9DS0VSX1VTRVJOQU1FLCBET0NLRVJfUEFTU1dPUkQgXQojICAgIGRlYnVnOiB0cnVlCgptYXRyaXg6CiAgSU1BR0U6CiAgICAtIGdvbGFuZzpsYXRlc3QK.v8PewiBInrZGDzyMopv7N-zaQZ5NVPoF9UsIumRXhBo
eyJhbGciOiJIUzI1NiJ9.IyBOT1RFOiBSZW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 func addMiddleware(mux *chi.Mux) {
func addRoutes(mux *chi.Mux) {
// Add a simple resource
mux.Mount("/app", AppResource{}.Routes())
mux.Mount("/api/id", AppResource{}.Routes())
// Live a healthy life!
mux.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("yolo"))

@ -17,7 +17,7 @@ func TestGetRoute(t *testing.T) {
ts := httptest.NewServer(r)
defer ts.Close()
rx := Response{}
_, resp := testRequest(t, ts, "GET", "/app/1", nil)
_, resp := testRequest(t, ts, "GET", "/api/id/1", nil)
err := json.Unmarshal([]byte(resp), &rx)
if err != nil {
t.Fatalf("Response incorrect form ", resp)

@ -0,0 +1,21 @@
version: '2'
services:
app:
build:
context: .
dockerfile: ./docker/Dockerfile
ports:
- "8080:8080"
sut:
build:
context: .
dockerfile: ./docker/Dockerfile.test
links:
- "app:target"
depends_on:
- app
environment:
SUT_TARGET: app

@ -1,19 +0,0 @@
version: '2'
services:
app:
container_name: "hello"
depends_on:
- db
build:
context: .
dockerfile: ./docker/Dockerfile
ports:
- "3000:3000"
networks:
- testnet
networks:
testnet:
driver: bridge

@ -0,0 +1,13 @@
sleep 5
ping -c 5 target
curl -X POST target:8080/api/id/1
if curl -X POST target:8080/api/id/1 | grep -q '{"op":"POST","id":1}'; then
echo "Tests passed!"
exit 0
else
echo "Tests failed!"
exit 1
fi

@ -0,0 +1,13 @@
#!/bin/sh
# remove old containers
docker-compose -p ci --file docker-compose.test.yml rm -f
# run tests
docker-compose -p ci --file docker-compose.test.yml up --build
echo "Inspecting exited containers:"
docker-compose -p ci --file docker-compose.test.yml ps
docker-compose -p ci --file docker-compose.test.yml ps -q | xargs docker inspect -f '{{ .State.ExitCode }}' | while read code; do
if [ "$code" != "0" ]; then
exit $code
fi
done
Loading…
Cancel
Save