Download this file
| 1 | package console |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "os/exec" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestMain doubles as the GeoIP verifier child: the console re-runs its own |
| 11 | // binary to verify an untrusted database (geoipverify.go), and in tests that |
| 12 | // binary is this one. |
| 13 | func TestMain(m *testing.M) { |
| 14 | if os.Getenv("CONSOLE_TEST_GEOIP_VERIFY_CHILD") == "1" { |
| 15 | for i, a := range os.Args { |
| 16 | if a == "--" { |
| 17 | os.Exit(RunGeoipVerify(os.Args[i+1:], os.Stdout)) |
| 18 | } |
| 19 | } |
| 20 | os.Exit(2) |
| 21 | } |
| 22 | geoipVerifyExec = func(ctx context.Context, args ...string) *exec.Cmd { |
| 23 | cmd := exec.CommandContext(ctx, os.Args[0], append([]string{"-test.run=^$", "--"}, args...)...) |
| 24 | cmd.Env = append(os.Environ(), "CONSOLE_TEST_GEOIP_VERIFY_CHILD=1") |
| 25 | return cmd |
| 26 | } |
| 27 | os.Exit(m.Run()) |
| 28 | } |
| 29 | |