chore: run e2e tests in CI #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go | |
on: [push] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: Build server | |
run: docker build -f ./app_to_test/server/Dockerfile -t expense_tracker/server:latest . | |
- 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 |