Skip to content

Commit

Permalink
Merge pull request #74 from hellofresh/patch/simplify-testing-workflow
Browse files Browse the repository at this point in the history
Use the same services for local and ci testing
  • Loading branch information
vgarvardt committed May 23, 2022
2 parents 00b91d7 + 3f0abc0 commit e676461
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 257 deletions.
154 changes: 37 additions & 117 deletions .github/workflows/testing.yml
Expand Up @@ -13,130 +13,50 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out code
uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.17
- uses: golangci/golangci-lint-action@v3

test:
name: Test
runs-on: ubuntu-latest
needs: [ lint ]
timeout-minutes: 10
strategy:
matrix:
go-version: [ 1.17, 1.18 ]

services:
pg-pq:
image: postgres:9.6-alpine
ports:
- "5432"
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
pg-pgx4:
image: postgres:9.6-alpine
ports:
- "5432"
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
rabbit:
image: rabbitmq:3.6-management-alpine
ports:
- "5672"
- "15672"
options: >-
--health-cmd "rabbitmqctl status"
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:3.2-alpine
ports:
- "6379"
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
mongo:
image: mongo:3
ports:
- "27017"
options: >-
--health-cmd "mongo localhost:27017/test --quiet --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql:5.7
ports:
- "3306"
env:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD"
--health-interval 10s
--health-timeout 5s
--health-retries 5
http:
image: pierreprinetti/apimock:latest
ports:
- "8080"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install docker-compose v2
shell: bash
env:
HOST: ":8080"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release -R docker/compose download -p docker-compose-linux-x86_64
mv -f docker-compose-linux-x86_64 docker-compose
sudo mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v2
sudo install docker-compose /usr/local/bin/
docker-compose --version
memcached:
image: memcached:1.6.9-alpine
ports:
- "11211"

influxdb:
image: influxdb:1.8-alpine
ports:
- "8086"
env:
DOCKER_INFLUXDB_INIT_USERNAME: test
DOCKER_INFLUXDB_INIT_PASSWORD: test
DOCKER_INFLUXDB_INIT_ORG: test
DOCKER_INFLUXDB_INIT_BUCKET: test
- run: task test

tets-summary:
name: Test
needs: test
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Set up Go
uses: actions/setup-go@v2
- name: Check out code
uses: actions/checkout@v2
- name: Run tests
if: success()
run: go test -cover ./... -coverprofile=coverage.txt -covermode=atomic
env:
HEALTH_GO_PG_PQ_DSN: postgres://test:test@localhost:${{ job.services.pg-pq.ports[5432] }}/test?sslmode=disable
HEALTH_GO_PG_PGX4_DSN: postgres://test:test@localhost:${{ job.services.pg-pgx4.ports[5432] }}/test?sslmode=disable
HEALTH_GO_MQ_DSN: amqp://guest:guest@localhost:${{ job.services.rabbit.ports[5672] }}/
HEALTH_GO_MQ_URL: http://guest:guest@localhost:${{ job.services.rabbit.ports[15672] }}/
HEALTH_GO_RD_DSN: redis://localhost:${{ job.services.redis.ports[6379] }}/
HEALTH_GO_MG_DSN: mongodb://localhost:${{ job.services.mongo.ports[27017] }}/
HEALTH_GO_MS_DSN: test:test@tcp(localhost:${{ job.services.mysql.ports[3306] }})/test?charset=utf8
HEALTH_GO_HTTP_URL: http://localhost:${{ job.services.http.ports[8080] }}/status
HEALTH_GO_INFLUXDB_URL: http://localhost:${{ job.services.influxdb.ports[8086] }}
HEALTH_GO_MD_DSN: memcached://localhost:${{ job.services.memcached.ports[11211] }}/
- run: echo "All good!"
3 changes: 2 additions & 1 deletion .golangci.yml
@@ -1,11 +1,12 @@
---
# See https://golangci-lint.run/usage/configuration/#config-file for more information
run:
timeout: 5m
linters:
disable-all: true
enable:
- gofmt
- golint
- revive
- goimports
fast: false
linters-settings:
Expand Down
24 changes: 0 additions & 24 deletions Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
@@ -1,4 +1,5 @@
# health-go

[![Go Report Card](https://goreportcard.com/badge/github.com/hellofresh/health-go)](https://goreportcard.com/report/github.com/hellofresh/health-go)
[![Go Doc](https://godoc.org/github.com/hellofresh/health-go?status.svg)](https://godoc.org/github.com/hellofresh/health-go)

Expand All @@ -12,6 +13,7 @@
* MySQL
* gRPC
* Memcached
* InfluxDB

## Usage

Expand Down
63 changes: 63 additions & 0 deletions Taskfile.yaml
@@ -0,0 +1,63 @@
---
version: '3'

env:
CGO_ENABLED: 0

tasks:
test:
summary: Run tests
cmds:
- task: test-deps-up
- task: test-run
- task: test-deps-down

test-deps-up:
summary: Starts test dependencies
preconditions:
- sh: docker-compose version --short | grep '^2'
msg: 'docker-compose v2 is expected to be installed'
cmds:
- cmd: docker-compose up --detach --wait

test-deps-down:
summary: Stops test dependencies
cmds:
- cmd: docker-compose down -v

test-run:
summary: Runs tests, must have dependencies running in the docker-compose
cmds:
- cmd: go test -timeout 2m -cover -coverprofile=coverage.txt -covermode=atomic ./...
vars:
PG_PQ_HOST:
sh: docker-compose port pg-pq 5432
PG_PGX4_HOST:
sh: docker-compose port pg-pgx4 5432
RABBIT_HOST_AMQP:
sh: docker-compose port rabbit 5672
RABBIT_HOST_HTTP:
sh: docker-compose port rabbit 15672
REDIS_HOST:
sh: docker-compose port redis 6379
MONGO_HOST:
sh: docker-compose port mongo 27017
MYSQL_HOST:
sh: docker-compose port mysql 3306
HTTP_HOST:
sh: docker-compose port http 8080
MEMCACHED_HOST:
sh: docker-compose port memcached 11211
INFLUX_HOST:
sh: docker-compose port influxdb 8086
env:
HEALTH_GO_PG_PQ_DSN: 'postgres://test:test@{{.PG_PQ_HOST}}/test?sslmode=disable'
HEALTH_GO_PG_PGX4_DSN: 'postgres://test:test@{{.PG_PGX4_HOST}}/test?sslmode=disable'
HEALTH_GO_MQ_DSN: 'amqp://guest:guest@{{.RABBIT_HOST_AMQP}}/'
HEALTH_GO_MQ_URL: 'http://guest:guest@{{.RABBIT_HOST_HTTP}}/'
HEALTH_GO_RD_DSN: 'redis://{{.REDIS_HOST}}/'
HEALTH_GO_MG_DSN: 'mongodb://{{.MONGO_HOST}}/'
HEALTH_GO_MS_DSN: 'test:test@tcp({{.MYSQL_HOST}})/test?charset=utf8'
HEALTH_GO_HTTP_URL: 'http://{{.HTTP_HOST}}/status'
HEALTH_GO_MD_DSN: 'memcached://localhost:{{.MEMCACHED_HOST}}/'
HEALTH_GO_INFLUXDB_URL: 'http://{{.INFLUX_HOST}}'
File renamed without changes.
File renamed without changes.
24 changes: 17 additions & 7 deletions docker-compose.yml
@@ -1,28 +1,33 @@
---
version: '3'
services:

pg-pq:
image: postgres:9.6-alpine
image: postgres:10
ports:
- "5432"
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
tmpfs:
- /var/lib/postgresql/data
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
timeout: 5s
retries: 5

pg-pgx4:
image: postgres:9.6-alpine
image: postgres:10
ports:
- "5432"
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
tmpfs:
- /var/lib/postgresql/data
healthcheck:
test: [ "CMD", "pg_isready" ]
interval: 10s
Expand Down Expand Up @@ -54,23 +59,28 @@ services:
image: mongo:3
ports:
- "27017"
tmpfs:
- /var/lib/mongodb
- /data/db/
healthcheck:
test: "mongo localhost:27017/test --quiet --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'"
interval: 10s
timeout: 5s
retries: 5

mysql:
# uncomment to use on ARM chip
# platform: linux/x86_64
image: mysql:5.7
# uncomment to use on ARM chip
# platform: linux/x86_64
image: mysql:8
ports:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
tmpfs:
- /var/lib/mysql
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
interval: 10s
Expand All @@ -90,8 +100,8 @@ services:
HOST: ":8080"

influxdb:
# uncomment to use on ARM chip
# platform: linux/x86_64
# uncomment to use on ARM chip
# platform: linux/x86_64
image: influxdb:1.8-alpine
ports:
- "8086"
Expand Down

0 comments on commit e676461

Please sign in to comment.