MCPcopy
hub / github.com/etcd-io/etcd / BeforeTest

Function BeforeTest

tests/framework/integration/testing.go:86–133  ·  view source on GitHub ↗
(t testutil.TB, opts ...TestOption)

Source from the content-addressed store, hash-verified

84}
85
86func 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
135func assertInTestContext(t testutil.TB) {
136 if !insideTestContext {

Callers 2

BeforeTestExternalFunction · 0.70
BeforeTestMethod · 0.70

Calls 11

newTestOptionsFunction · 0.85
HelperMethod · 0.65
FatalMethod · 0.65
ListMethod · 0.65
SkipMethod · 0.65
EnableMethod · 0.65
CleanupMethod · 0.65
DisableMethod · 0.65
SetMethod · 0.65
TempDirMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…