Files
worker/internal/netaddr/main_test.go
Gleb Tv 2c7a0236da feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
2026-07-13 17:55:14 +03:00

36 строки
880 B
Go

package netaddr
import (
"os"
"path/filepath"
"testing"
"github.com/joho/godotenv"
)
// TestMain loads .env.test before any test runs so DATABASE_* env vars
// are populated in this test binary. The netaddr package is intentionally
// low-level and does not import config/env; this TestMain gives it the
// same environment the rest of the test suite sees without pulling in
// the app-wide env init.
func TestMain(m *testing.M) {
loadEnvIfPresent(".env.test")
os.Exit(m.Run())
}
func loadEnvIfPresent(name string) {
candidates := []string{name}
if cwd := os.Getenv("CWD"); cwd != "" {
candidates = append(candidates, filepath.Join(cwd, name))
}
if dir, err := os.Getwd(); err == nil {
candidates = append(candidates, filepath.Join(dir, name))
}
for _, c := range candidates {
if _, err := os.Stat(c); err == nil {
_ = godotenv.Load(c)
return
}
}
}