Skip to content

Commit 77aa21a

Browse files
committed
fix: init logger for test suite
1 parent 213d416 commit 77aa21a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.testcoverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ exclude:
66
- common/config/config.go
77
- mocks
88
# the following files should be excluded from coverage later
9-
- listener/apischema/*
10-
- listener/controller/*
9+
# - listener/apischema/*
10+
# - listener/controller/*

tests/gateway_test/suite_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import (
1818
"github.com/stretchr/testify/suite"
1919
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2020
"k8s.io/client-go/rest"
21+
ctrl "sigs.k8s.io/controller-runtime"
2122
"sigs.k8s.io/controller-runtime/pkg/client"
2223
"sigs.k8s.io/controller-runtime/pkg/envtest"
2324
"sigs.k8s.io/controller-runtime/pkg/kcp"
25+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2426

2527
"github.com/openmfp/account-operator/api/v1alpha1"
2628
appConfig "github.com/openmfp/kubernetes-graphql-gateway/common/config"
@@ -29,6 +31,14 @@ import (
2931
"github.com/openmfp/kubernetes-graphql-gateway/gateway/schema"
3032
)
3133

34+
// Initialize the logger for the test suite
35+
// This is necessary to avoid the "[controller-runtime] log.SetLogger(...) was never called" error
36+
// when running the tests
37+
func TestMain(m *testing.M) {
38+
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
39+
os.Exit(m.Run())
40+
}
41+
3242
type CommonTestSuite struct {
3343
suite.Suite
3444
testEnv *envtest.Environment

0 commit comments

Comments
 (0)