diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0f746ec..10da6c7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -2,7 +2,7 @@ name: Go on: push: - branches: [ "main", "feat/ci"] + branches: [ "main" ] pull_request: branches: [ "main", "develop/pass" ] @@ -14,9 +14,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.22' - - name: Test + - name: Unit Test run: make unit-tests + + - name: e2e Test + run: make ci-e2e diff --git a/Makefile b/Makefile index dae4dd5..9d25036 100644 --- a/Makefile +++ b/Makefile @@ -15,23 +15,28 @@ migration: ## create database migrations file migration-up: ## apply all available migrations docker compose run -u ${USERID}:${USERID} --rm api migrate up - +.PHONY: up up: ## run all applications in stack docker compose build docker compose up -d - +.PHONY: unit-tests unit-tests: ## run unit tests without e2e-tests directory.. go test -race -count=1 `go list ./... | grep -v e2e-tests` +.PHONY: ci-e2e +ci-e2e: up + go run ./e2e-tests/scripts/wait-ready/main.go -addr=':80;:8081;:8082' + @$(MAKE) tests-e2e +.PHONY: tests-e2e tests-e2e: ## run end to end tests ## There is some race condition when running tests as go test -count=1 ./tests/... Come back at some point and fix it - go test ./tests/browser_extension/... -count=1 - go test ./tests/icons/... -count=1 - go test ./tests/mobile/... -count=1 - go test ./tests/support/... -count=1 - go test ./tests/system/... -count=1 + go test ./e2e-tests/browser_extension/... -count=1 + go test ./e2e-tests/icons/... -count=1 + go test ./e2e-tests/mobile/... -count=1 + go test ./e2e-tests/support/... -count=1 + go test ./e2e-tests/system/... -count=1 vendor-licenses: ## report vendor licenses diff --git a/e2e-tests/scripts/wait-ready/main.go b/e2e-tests/scripts/wait-ready/main.go new file mode 100644 index 0000000..52107cc --- /dev/null +++ b/e2e-tests/scripts/wait-ready/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "flag" + "log" + "net" + "strings" + "time" +) + +func main() { + addrFlag := flag.String("addr", ":80;:8081;:8082", "list of addresses to check sep by ;") + flag.Parse() + + addresses := strings.Split(*addrFlag, ";") + if len(addresses) < 1 { + log.Fatal("-addr value not provided") + } + for _, address := range addresses { + running := waitForApp(address, 30*time.Second) + if !running { + log.Fatal("App not running on addr: ", address) + } + } +} + +// waitForApp returns true if app is listening on provided address. +// If it cannot connect up to specified timeout, it returns false. +func waitForApp(address string, timeout time.Duration) bool { + done := make(chan struct{}) + + go func() { + for { + _, err := net.DialTimeout("tcp", address, time.Second) + if err != nil { + time.Sleep(time.Second) + continue + } + close(done) + return + } + }() + timeoutCh := time.After(timeout) + select { + case <-done: + return true + case <-timeoutCh: + return false + } +}