| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/testenv" |
| 9 | |
| 10 | "go.uber.org/goleak" |
| 11 | ) |
| 12 | |
| 13 | func TestMain(m *testing.M) { |
| 14 | cleanupUserState, err := testenv.IsolateUserState() |
| 15 | if err != nil { |
| 16 | panic(err) |
| 17 | } |
| 18 | if os.Getenv("REASONIX_CREDENTIALS_STORE") == "" { |
| 19 | _ = os.Setenv("REASONIX_CREDENTIALS_STORE", "file") |
| 20 | } |
| 21 | goleak.VerifyTestMain(m, goleak.Cleanup(func(exitCode int) { |
| 22 | // A controller test that never closes its session service keeps the |
| 23 | // writer lease, which only Windows reports as a t.TempDir failure. |
| 24 | if leak := testenv.VerifyNoLeakedFileLocks(); leak != nil { |
| 25 | fmt.Fprintln(os.Stderr, leak) |
| 26 | if exitCode == 0 { |
| 27 | exitCode = 1 |
| 28 | } |
| 29 | } |
| 30 | cleanupUserState() |
| 31 | os.Exit(exitCode) |
| 32 | })) |
| 33 | } |
| 34 |