(t testutil.TB, opts ...TestOption)
| 84 | } |
| 85 | |
| 86 | func BeforeTest(t testutil.TB, opts ...TestOption) { |
| 87 | t.Helper() |
| 88 | options := newTestOptions(opts...) |
| 89 | |
| 90 | if insideTestContext { |
| 91 | t.Fatal("already in test context. BeforeTest was likely already called") |
| 92 | } |
| 93 | |
| 94 | if options.skipInShort { |
| 95 | testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests") |
| 96 | } |
| 97 | |
| 98 | if options.goLeakDetection { |
| 99 | testutil.RegisterLeakDetection(t) |
| 100 | } |
| 101 | |
| 102 | if options.failpoint != nil && len(options.failpoint.name) != 0 { |
| 103 | if len(gofail.List()) == 0 { |
| 104 | t.Skip("please run 'make gofail-enable' before running the test") |
| 105 | } |
| 106 | require.NoError(t, gofail.Enable(options.failpoint.name, options.failpoint.payload)) |
| 107 | t.Cleanup(func() { |
| 108 | require.NoError(t, gofail.Disable(options.failpoint.name)) |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | previousWD, err := os.Getwd() |
| 113 | if err != nil { |
| 114 | t.Fatal(err) |
| 115 | } |
| 116 | previousInsideTestContext := insideTestContext |
| 117 | |
| 118 | // Integration tests should verify written state as much as possible. |
| 119 | revertFunc := verify.EnableAllVerifications() |
| 120 | |
| 121 | // Registering cleanup early, such it will get executed even if the helper fails. |
| 122 | t.Cleanup(func() { |
| 123 | grpcLogger.Reset() |
| 124 | insideTestContext = previousInsideTestContext |
| 125 | os.Chdir(previousWD) |
| 126 | revertFunc() |
| 127 | }) |
| 128 | |
| 129 | grpcLogger.Set(zapgrpc.NewLogger(zaptest.NewLogger(t).Named("grpc"))) |
| 130 | insideTestContext = true |
| 131 | |
| 132 | os.Chdir(t.TempDir()) |
| 133 | } |
| 134 | |
| 135 | func assertInTestContext(t testutil.TB) { |
| 136 | if !insideTestContext { |
no test coverage detected
searching dependent graphs…