Skip to content

Commit

Permalink
chore: run e2e tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
antosdaniel committed Sep 23, 2023
1 parent 4d355a5 commit 4cfb1be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ jobs:
with:
go-version: '1.21'

- name: Build
run: go build -v ./...
- name: Build server
run: docker build -f ./app_to_test/server/Dockerfile -t expense_tracker/server:latest .

- name: Test
- name: Build migrate
run: docker build -t expense_tracker/migrate:latest ./app_to_test/db

- name: Tests
run: go test -v ./...

- name: E2E Tests
run: |
# Allows docker containers to call host machine
sudo sysctl -w net.ipv4.conf.docker0.route_localnet=1
sudo iptables -t nat -I PREROUTING -i docker0 -d 172.17.0.1 -p all -j DNAT --to 127.0.0.1
sudo iptables -t filter -I INPUT -i docker0 -d 127.0.0.1 -p all -j ACCEPT
# Run only e2e tests
PKGS=$(git grep --files-with-matches "//go:build e2e_tests" -- "*.go" | xargs dirname | sed 's,^,./,g' | sort -u)
go test -tags=e2e_tests $PKGS
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ of your application work as expected. These could also be named smoke tests.
```shell
docker compose up
```

## Run tests

Run unit tests:

```shell
go test ./...
```

Run e2e tests:

```shell
PKGS=$(git grep --files-with-matches "//go:build e2e_tests" -- "*.go" | xargs dirname | sed 's,^,./,g' | sort -u)
go test -tags=e2e_tests $PKGS
```
5 changes: 4 additions & 1 deletion test_e2e/docker-compose-for-e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: "3.9"

services:
server:
image: "expense_tracker/server:latest"
Expand All @@ -13,6 +14,8 @@ services:
condition: service_healthy
networks:
- default
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
# Once again, we use a random port to avoid conflicts.
- "8000"
Expand Down Expand Up @@ -41,4 +44,4 @@ services:
condition: service_healthy

networks:
default:
default:

0 comments on commit 4cfb1be

Please sign in to comment.