Skip to content

Commit 12d1bdb

Browse files
authored
updated unit test files with logr.Discard (#3083)
1 parent dfbfc1f commit 12d1bdb

17 files changed

+86
-87
lines changed

cmd/gateway/initialize_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"path/filepath"
99
"testing"
1010

11+
"github.com/go-logr/logr"
1112
. "github.com/onsi/gomega"
12-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1313

1414
"github.com/nginx/nginx-gateway-fabric/internal/framework/helpers"
1515
"github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing/licensingfakes"
@@ -27,7 +27,7 @@ func TestInitialize_OSS(t *testing.T) {
2727

2828
ic := initializeConfig{
2929
fileManager: fakeFileMgr,
30-
logger: zap.New(),
30+
logger: logr.Discard(),
3131
copy: copyFiles{
3232
destDirName: "destDir",
3333
srcFileNames: []string{"src1", "src2"},
@@ -55,7 +55,7 @@ func TestInitialize_OSS_Error(t *testing.T) {
5555

5656
ic := initializeConfig{
5757
fileManager: fakeFileMgr,
58-
logger: zap.New(),
58+
logger: logr.Discard(),
5959
copy: copyFiles{
6060
destDirName: "destDir",
6161
srcFileNames: []string{"src1", "src2"},
@@ -111,7 +111,7 @@ func TestInitialize_Plus(t *testing.T) {
111111

112112
ic := initializeConfig{
113113
fileManager: fakeFileMgr,
114-
logger: zap.New(),
114+
logger: logr.Discard(),
115115
collector: fakeCollector,
116116
fileGenerator: fakeGenerator,
117117
copy: copyFiles{

internal/framework/controller/register_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"reflect"
77
"testing"
88

9+
"github.com/go-logr/logr"
910
. "github.com/onsi/gomega"
1011
"github.com/onsi/gomega/gcustom"
1112
gtypes "github.com/onsi/gomega/types"
@@ -14,7 +15,6 @@ import (
1415
"k8s.io/apimachinery/pkg/types"
1516
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1617
"sigs.k8s.io/controller-runtime/pkg/client/fake"
17-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1818
v1 "sigs.k8s.io/gateway-api/apis/v1"
1919
"sigs.k8s.io/gateway-api/apis/v1beta1"
2020

@@ -43,7 +43,7 @@ func TestRegister(t *testing.T) {
4343
mgr := &controllerfakes.FakeManager{}
4444
mgr.GetClientReturns(fake.NewClientBuilder().Build())
4545
mgr.GetSchemeReturns(scheme)
46-
mgr.GetLoggerReturns(zap.New())
46+
mgr.GetLoggerReturns(logr.Discard())
4747
mgr.GetFieldIndexerReturns(indexer)
4848

4949
return fakes{

internal/framework/events/events_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package events
33
import (
44
"testing"
55

6+
"github.com/go-logr/logr"
67
. "github.com/onsi/gomega"
7-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
88
)
99

1010
func TestEventLoop_SwapBatches(t *testing.T) {
1111
t.Parallel()
1212
g := NewWithT(t)
13-
eventLoop := NewEventLoop(nil, zap.New(), nil, nil)
13+
eventLoop := NewEventLoop(nil, logr.Discard(), nil, nil)
1414

1515
eventLoop.currentBatch = EventBatch{
1616
"event0",

internal/framework/events/loop_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/go-logr/logr"
99
. "github.com/onsi/ginkgo/v2"
1010
. "github.com/onsi/gomega"
11-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1211

1312
"github.com/nginx/nginx-gateway-fabric/internal/framework/events"
1413
"github.com/nginx/nginx-gateway-fabric/internal/framework/events/eventsfakes"
@@ -28,7 +27,7 @@ var _ = Describe("EventLoop", func() {
2827
eventCh = make(chan interface{})
2928
fakePreparer = &eventsfakes.FakeFirstEventBatchPreparer{}
3029

31-
eventLoop = events.NewEventLoop(eventCh, zap.New(), fakeHandler, fakePreparer)
30+
eventLoop = events.NewEventLoop(eventCh, logr.Discard(), fakeHandler, fakePreparer)
3231

3332
errorCh = make(chan error)
3433
})

internal/framework/runnables/cronjob_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/go-logr/logr"
89
. "github.com/onsi/gomega"
9-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1010
)
1111

1212
func TestCronJob(t *testing.T) {
@@ -26,7 +26,7 @@ func TestCronJob(t *testing.T) {
2626

2727
cfg := CronJobConfig{
2828
Worker: worker,
29-
Logger: zap.New(),
29+
Logger: logr.Discard(),
3030
Period: 1 * time.Millisecond, // 1ms is much smaller than timeout so the CronJob should run a few times
3131
ReadyCh: readyChannel,
3232
}
@@ -58,7 +58,7 @@ func TestCronJob_ContextCanceled(t *testing.T) {
5858

5959
cfg := CronJobConfig{
6060
Worker: func(_ context.Context) {},
61-
Logger: zap.New(),
61+
Logger: logr.Discard(),
6262
Period: 1 * time.Millisecond, // 1ms is much smaller than timeout so the CronJob should run a few times
6363
ReadyCh: readyChannel,
6464
}

internal/framework/status/leader_aware_group_updater_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package status
33
import (
44
"context"
55

6+
"github.com/go-logr/logr"
67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
89
"k8s.io/apimachinery/pkg/runtime"
910
"k8s.io/apimachinery/pkg/types"
1011
"sigs.k8s.io/controller-runtime/pkg/client"
1112
"sigs.k8s.io/controller-runtime/pkg/client/fake"
12-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1313
v1 "sigs.k8s.io/gateway-api/apis/v1"
1414
)
1515

@@ -46,7 +46,7 @@ var _ = Describe("LeaderAwareGroupUpdater", func() {
4646
)
4747

4848
BeforeAll(func() {
49-
updater = NewLeaderAwareGroupUpdater(NewUpdater(k8sClient, zap.New()))
49+
updater = NewLeaderAwareGroupUpdater(NewUpdater(k8sClient, logr.Discard()))
5050

5151
for _, name := range allGCNames {
5252
gc := createGC(name)

internal/framework/status/updater_retry_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"errors"
66
"testing"
77

8+
"github.com/go-logr/logr"
89
. "github.com/onsi/gomega"
910
apierrors "k8s.io/apimachinery/pkg/api/errors"
1011
"k8s.io/apimachinery/pkg/runtime/schema"
1112
"k8s.io/apimachinery/pkg/types"
1213
"sigs.k8s.io/controller-runtime/pkg/client"
13-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1414
v1 "sigs.k8s.io/gateway-api/apis/v1"
1515

1616
"github.com/nginx/nginx-gateway-fabric/internal/framework/controller/controllerfakes"
@@ -86,7 +86,7 @@ func TestNewRetryUpdateFunc(t *testing.T) {
8686
fakeStatusUpdater,
8787
types.NamespacedName{},
8888
&v1.GatewayClass{},
89-
zap.New(),
89+
logr.Discard(),
9090
func(client.Object) bool { return test.statusSetterReturns },
9191
)
9292

internal/framework/status/updater_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package status
33
import (
44
"context"
55

6+
"github.com/go-logr/logr"
67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
"k8s.io/apimachinery/pkg/runtime"
1011
"k8s.io/apimachinery/pkg/types"
1112
"sigs.k8s.io/controller-runtime/pkg/client"
1213
"sigs.k8s.io/controller-runtime/pkg/client/fake"
13-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1414
v1 "sigs.k8s.io/gateway-api/apis/v1"
1515

1616
"github.com/nginx/nginx-gateway-fabric/internal/framework/helpers"
@@ -116,7 +116,7 @@ var _ = Describe("Updater", func() {
116116
)
117117

118118
BeforeAll(func() {
119-
updater = NewUpdater(k8sClient, zap.New())
119+
updater = NewUpdater(k8sClient, logr.Discard())
120120

121121
for _, name := range gcNames {
122122
gc := createGC(name)

internal/mode/provisioner/handler_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/go-logr/logr"
78
. "github.com/onsi/ginkgo/v2"
89
v1 "k8s.io/api/apps/v1"
910
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -12,7 +13,6 @@ import (
1213
"k8s.io/apimachinery/pkg/types"
1314
"sigs.k8s.io/controller-runtime/pkg/client"
1415
"sigs.k8s.io/controller-runtime/pkg/client/fake"
15-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1616
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
1717

1818
. "github.com/onsi/gomega"
@@ -60,7 +60,7 @@ var _ = Describe("handler", func() {
6060
return fakeTime
6161
}
6262

63-
statusUpdater = status.NewUpdater(k8sclient, zap.New())
63+
statusUpdater = status.NewUpdater(k8sclient, logr.Discard())
6464

6565
// Add GatewayClass CRD to the cluster
6666
crd = &metav1.PartialObjectMetadata{
@@ -114,7 +114,7 @@ var _ = Describe("handler", func() {
114114
Resource: crd,
115115
},
116116
}
117-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
117+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
118118

119119
// Ensure GatewayClass is accepted
120120

@@ -152,7 +152,7 @@ var _ = Describe("handler", func() {
152152
},
153153
}
154154

155-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
155+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
156156

157157
depNsName := types.NamespacedName{
158158
Namespace: "nginx-gateway",
@@ -187,7 +187,7 @@ var _ = Describe("handler", func() {
187187
},
188188
}
189189

190-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
190+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
191191

192192
updatedGC := &gatewayv1.GatewayClass{}
193193

@@ -249,7 +249,7 @@ var _ = Describe("handler", func() {
249249
}
250250

251251
handle := func() {
252-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
252+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
253253
}
254254

255255
Expect(handle).Should(Panic())
@@ -310,7 +310,7 @@ var _ = Describe("handler", func() {
310310
},
311311
}
312312

313-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
313+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
314314
deps := &v1.DeploymentList{}
315315

316316
err := k8sclient.List(context.Background(), deps)
@@ -330,7 +330,7 @@ var _ = Describe("handler", func() {
330330
},
331331
}
332332

333-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
333+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
334334

335335
deps := &v1.DeploymentList{}
336336

@@ -359,7 +359,7 @@ var _ = Describe("handler", func() {
359359
},
360360
}
361361

362-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
362+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
363363

364364
deps := &v1.DeploymentList{}
365365
err := k8sclient.List(context.Background(), deps)
@@ -392,7 +392,7 @@ var _ = Describe("handler", func() {
392392
},
393393
}
394394

395-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
395+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
396396

397397
unknownGC := &gatewayv1.GatewayClass{}
398398
err = k8sclient.Get(context.Background(), client.ObjectKeyFromObject(newGC), unknownGC)
@@ -456,7 +456,7 @@ var _ = Describe("handler", func() {
456456
batch := []interface{}{e}
457457

458458
handle := func() {
459-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
459+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
460460
}
461461

462462
Expect(handle).Should(Panic())
@@ -524,7 +524,7 @@ var _ = Describe("handler", func() {
524524
}
525525

526526
handle := func() {
527-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
527+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
528528
}
529529

530530
Expect(handle).Should(Panic())
@@ -545,7 +545,7 @@ var _ = Describe("handler", func() {
545545
}
546546

547547
handle := func() {
548-
handler.HandleEventBatch(context.Background(), zap.New(), batch)
548+
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
549549
}
550550

551551
Expect(handle).Should(Panic())

internal/mode/static/config_updater_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"fmt"
66
"testing"
77

8+
"github.com/go-logr/logr"
89
. "github.com/onsi/gomega"
910
"k8s.io/apimachinery/pkg/types"
1011
"k8s.io/client-go/tools/record"
11-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1212

1313
ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
1414
"github.com/nginx/nginx-gateway-fabric/internal/framework/helpers"
@@ -33,7 +33,7 @@ func TestUpdateControlPlane(t *testing.T) {
3333
},
3434
}
3535

36-
logger := zap.New()
36+
logger := logr.Discard()
3737
nsname := types.NamespacedName{Namespace: "test", Name: "test"}
3838

3939
tests := []struct {

0 commit comments

Comments
 (0)