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 49f932f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 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
```

0 comments on commit 49f932f

Please sign in to comment.