The dev-tagged Connect() in db_dev.go hardcoded localhost:5432 in the DSN instead of reading the POSTGRES_HOST env var. Since CI tests run with -tags "test,dev", db_dev.go is compiled and the POSTGRES_HOST=postgres env var was silently ignored, causing db package tests to try connecting to 127.0.0.1:5432 where no PostgreSQL is listening (service container is only reachable via Docker DNS hostname postgres). Also remove the -a flag from the workflow now that caching is no longer suspected of causing issues.
This commit is contained in:
@@ -60,7 +60,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Test (all packages)
|
- name: Test (all packages)
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
run: go test -a -tags "test,dev" -count=1 -v -timeout 120s ./handlers/... ./auth/... ./mw/... ./internal/... ./db/...
|
run: go test -tags "test,dev" -count=1 -v -timeout 120s ./handlers/... ./auth/... ./mw/... ./internal/... ./db/...
|
||||||
env:
|
env:
|
||||||
POSTGRES_HOST: postgres
|
POSTGRES_HOST: postgres
|
||||||
PGUSER: myuser
|
PGUSER: myuser
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ var Conn *PoolProxy
|
|||||||
func Connect() error {
|
func Connect() error {
|
||||||
// Connect to Postgres inside Docker network
|
// Connect to Postgres inside Docker network
|
||||||
dsn := fmt.Sprintf(
|
dsn := fmt.Sprintf(
|
||||||
"postgres://%s:%s@localhost:5432/%s?sslmode=disable&require_auth=scram-sha-256",
|
"postgres://%s:%s@%s:5432/%s?sslmode=disable&require_auth=scram-sha-256",
|
||||||
getEnv("POSTGRES_USER"),
|
getEnv("POSTGRES_USER"),
|
||||||
getEnv("POSTGRES_PASSWORD"),
|
getEnv("POSTGRES_PASSWORD"),
|
||||||
|
getEnv("POSTGRES_HOST"),
|
||||||
getEnv("POSTGRES_DB"),
|
getEnv("POSTGRES_DB"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user