Skip to content

bug(test): main panics under -tags=e2e in loadDotEnv(nil) #112

Description

@chrisnestrud

Summary

The tagged e2e suite cannot start on main. TestMain calls loadDotEnv(nil),
and loadDotEnv calls t.Log on the nil testing.TB when it walks past the
repo root without finding .env.test, so the process panics before any test
runs.

Repro

go test -tags=e2e ./internal/e2e/
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x80 pc=...]

goroutine 1 [running]:
moonbridge/internal/e2e_test.loadDotEnv({0x0, 0x0})
	internal/e2e/e2e_test.go:235
moonbridge/internal/e2e_test.TestMain(...)
	internal/e2e/e2e_test.go:145

Root cause

e2e_test.go:145 passes nil to loadDotEnv, and e2e_test.go:235 calls
t.Log(".env.test not found — relying on OS env vars") unconditionally. Any run
that reaches the repo-root branch panics on the nil TB.

Fix

Guard the log call:

if t != nil {
	t.Log(".env.test not found — relying on OS env vars")
}

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions