e2e tests

This commit is contained in:
Tobiasz Heller 2024-03-07 18:28:03 +01:00
parent da1eaddeb1
commit bd43abede5
3 changed files with 68 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}
}