Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 18a6ab0

Browse files
committed
test: fix data race between multiple unit test that use envtest
1 parent aa467be commit 18a6ab0

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

test/helpers/environment.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ var TestEnv *TestEnvironment
1919

2020
// Initialize the test environment. BeforeSuite will be only executed if this package is loaded by the test.
2121
var _ = BeforeSuite(func(ctx SpecContext) {
22+
By("Initialize loggers for testing")
23+
// Uninitialized logger spits stacktrace as warning during test execution
24+
logger := textlogger.NewLogger(textlogger.NewConfig())
25+
// use klog as the internal logger for this envtest environment.
26+
log.SetLogger(logger)
27+
// additionally force all of the controllers to use the Ginkgo logger.
28+
ctrl.SetLogger(logger)
29+
klog.InitFlags(nil)
30+
// add logger for ginkgo
31+
klog.SetOutput(GinkgoWriter)
32+
2233
By("Starting test environment")
2334
testEnvConfig := NewTestEnvironmentConfiguration()
2435
var err error
@@ -36,15 +47,3 @@ var _ = BeforeSuite(func(ctx SpecContext) {
3647
var _ = AfterSuite(func(ctx context.Context) {
3748
Expect(TestEnv.Stop()).To(Succeed())
3849
})
39-
40-
//nolint:gochecknoinits //needed for test initialization
41-
func init() {
42-
klog.InitFlags(nil)
43-
logger := textlogger.NewLogger(textlogger.NewConfig())
44-
// use klog as the internal logger for this envtest environment.
45-
log.SetLogger(logger)
46-
// additionally force all of the controllers to use the Ginkgo logger.
47-
ctrl.SetLogger(logger)
48-
// add logger for ginkgo
49-
klog.SetOutput(GinkgoWriter)
50-
}

0 commit comments

Comments
 (0)