package console import ( "context" "os" "os/exec" "testing" ) // TestMain doubles as the GeoIP verifier child: the console re-runs its own // binary to verify an untrusted database (geoipverify.go), and in tests that // binary is this one. func TestMain(m *testing.M) { if os.Getenv("CONSOLE_TEST_GEOIP_VERIFY_CHILD") == "1" { for i, a := range os.Args { if a == "--" { os.Exit(RunGeoipVerify(os.Args[i+1:], os.Stdout)) } } os.Exit(2) } geoipVerifyExec = func(ctx context.Context, args ...string) *exec.Cmd { cmd := exec.CommandContext(ctx, os.Args[0], append([]string{"-test.run=^$", "--"}, args...)...) cmd.Env = append(os.Environ(), "CONSOLE_TEST_GEOIP_VERIFY_CHILD=1") return cmd } os.Exit(m.Run()) }