CI / Env docs check (push) Failing after 17s
CI / Docker compose check (push) Successful in 1m29s
CI / Secrets scan (push) Successful in 1m33s
CI / Frontend major deps (push) Successful in 1m31s
CI / Go build (push) Successful in 1m33s
CI / Frontend deps check (push) Successful in 1m33s
CI / Frontend build (push) Successful in 1m32s
CI / Nginx config check (push) Successful in 1m33s
CI / go mod tidy (push) Successful in 1m18s
CI / Go vulnerabilities (push) Failing after 0s
CI / Knip (push) Failing after 0s
CI / Frontend a11y check (push) Failing after 0s
CI / Svelte strict check (push) Has been skipped
CI / Frontend QC (audit) (push) Has been skipped
CI / Frontend QC (typecheck) (push) Has been skipped
CI / Frontend QC (lint) (push) Has been skipped
CI / Go vet (prod) (push) Successful in 1m31s
CI / Go vet (dev) (push) Successful in 1m51s
CI / Staticcheck (prod) (push) Successful in 2m27s
CI / Staticcheck (dev) (push) Successful in 2m55s
CI / golangci-lint (push) Successful in 3m13s
CI / Security scan (prod) (push) Successful in 4m8s
CI / Security scan (dev) (push) Successful in 4m15s
CI / Tests (prod) (push) Has been skipped
CI / Tests (dev) (push) Has been skipped
CI / Race (prod) (push) Has been skipped
CI / Race (dev) (push) Has been skipped
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
//go:build dev
|
|
|
|
package dav
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
var Service *BaseService
|
|
|
|
func init() {
|
|
if err := connect(); err != nil {
|
|
// Don't fatal in test mode - tests will use testdb instead
|
|
if os.Getenv("DAV_SKIP_INIT") != "" {
|
|
return
|
|
}
|
|
panic("failed to initialize dev service: " + err.Error())
|
|
}
|
|
}
|
|
|
|
func connect() error {
|
|
dsn := fmt.Sprintf(
|
|
"postgres://%s:%s@localhost:5432/%s?sslmode=disable&timezone=UTC&require_auth=scram-sha-256",
|
|
getEnv("POSTGRES_USER"),
|
|
getEnv("POSTGRES_PASSWORD"),
|
|
getEnv("POSTGRES_DB"),
|
|
)
|
|
pool, err := pgxpool.New(context.Background(), dsn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
Service = newBaseService(pool)
|
|
return testDB(pool)
|
|
}
|
|
|
|
func testDB(pool *pgxpool.Pool) error {
|
|
var n int
|
|
err := pool.QueryRow(context.Background(), "SELECT 1").Scan(&n)
|
|
if err != nil || n != 1 {
|
|
return fmt.Errorf("db test failed: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func getEnv(key string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
// Return empty string instead of fatal error - allows tests to run without prod env vars
|
|
return ""
|
|
}
|