Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated unit test files with logr.Discard #3083

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/gateway/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"path/filepath"
"testing"

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

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

ic := initializeConfig{
fileManager: fakeFileMgr,
logger: zap.New(),
logger: logr.Discard(),
copy: copyFiles{
destDirName: "destDir",
srcFileNames: []string{"src1", "src2"},
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestInitialize_OSS_Error(t *testing.T) {

ic := initializeConfig{
fileManager: fakeFileMgr,
logger: zap.New(),
logger: logr.Discard(),
copy: copyFiles{
destDirName: "destDir",
srcFileNames: []string{"src1", "src2"},
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestInitialize_Plus(t *testing.T) {

ic := initializeConfig{
fileManager: fakeFileMgr,
logger: zap.New(),
logger: logr.Discard(),
collector: fakeCollector,
fileGenerator: fakeGenerator,
copy: copyFiles{
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/controller/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
"testing"

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gcustom"
gtypes "github.com/onsi/gomega/types"
Expand All @@ -14,7 +15,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
v1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/apis/v1beta1"

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

return fakes{
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package events
import (
"testing"

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

func TestEventLoop_SwapBatches(t *testing.T) {
t.Parallel()
g := NewWithT(t)
eventLoop := NewEventLoop(nil, zap.New(), nil, nil)
eventLoop := NewEventLoop(nil, logr.Discard(), nil, nil)

eventLoop.currentBatch = EventBatch{
"event0",
Expand Down
3 changes: 1 addition & 2 deletions internal/framework/events/loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

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

eventLoop = events.NewEventLoop(eventCh, zap.New(), fakeHandler, fakePreparer)
eventLoop = events.NewEventLoop(eventCh, logr.Discard(), fakeHandler, fakePreparer)

errorCh = make(chan error)
})
Expand Down
6 changes: 3 additions & 3 deletions internal/framework/runnables/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
"time"

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

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

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

cfg := CronJobConfig{
Worker: func(_ context.Context) {},
Logger: zap.New(),
Logger: logr.Discard(),
Period: 1 * time.Millisecond, // 1ms is much smaller than timeout so the CronJob should run a few times
ReadyCh: readyChannel,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package status
import (
"context"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
v1 "sigs.k8s.io/gateway-api/apis/v1"
)

Expand Down Expand Up @@ -46,7 +46,7 @@ var _ = Describe("LeaderAwareGroupUpdater", func() {
)

BeforeAll(func() {
updater = NewLeaderAwareGroupUpdater(NewUpdater(k8sClient, zap.New()))
updater = NewLeaderAwareGroupUpdater(NewUpdater(k8sClient, logr.Discard()))

for _, name := range allGCNames {
gc := createGC(name)
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/status/updater_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"testing"

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
v1 "sigs.k8s.io/gateway-api/apis/v1"

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

Expand Down
4 changes: 2 additions & 2 deletions internal/framework/status/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package status
import (
"context"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
v1 "sigs.k8s.io/gateway-api/apis/v1"

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

BeforeAll(func() {
updater = NewUpdater(k8sClient, zap.New())
updater = NewUpdater(k8sClient, logr.Discard())

for _, name := range gcNames {
gc := createGC(name)
Expand Down
26 changes: 13 additions & 13 deletions internal/mode/provisioner/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
v1 "k8s.io/api/apps/v1"
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -12,7 +13,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -60,7 +60,7 @@ var _ = Describe("handler", func() {
return fakeTime
}

statusUpdater = status.NewUpdater(k8sclient, zap.New())
statusUpdater = status.NewUpdater(k8sclient, logr.Discard())

// Add GatewayClass CRD to the cluster
crd = &metav1.PartialObjectMetadata{
Expand Down Expand Up @@ -114,7 +114,7 @@ var _ = Describe("handler", func() {
Resource: crd,
},
}
handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)

// Ensure GatewayClass is accepted

Expand Down Expand Up @@ -152,7 +152,7 @@ var _ = Describe("handler", func() {
},
}

handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)

depNsName := types.NamespacedName{
Namespace: "nginx-gateway",
Expand Down Expand Up @@ -187,7 +187,7 @@ var _ = Describe("handler", func() {
},
}

handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)

updatedGC := &gatewayv1.GatewayClass{}

Expand Down Expand Up @@ -249,7 +249,7 @@ var _ = Describe("handler", func() {
}

handle := func() {
handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
}

Expect(handle).Should(Panic())
Expand Down Expand Up @@ -310,7 +310,7 @@ var _ = Describe("handler", func() {
},
}

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

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

handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)

deps := &v1.DeploymentList{}

Expand Down Expand Up @@ -359,7 +359,7 @@ var _ = Describe("handler", func() {
},
}

handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)

deps := &v1.DeploymentList{}
err := k8sclient.List(context.Background(), deps)
Expand Down Expand Up @@ -392,7 +392,7 @@ var _ = Describe("handler", func() {
},
}

handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)

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

handle := func() {
handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
}

Expect(handle).Should(Panic())
Expand Down Expand Up @@ -524,7 +524,7 @@ var _ = Describe("handler", func() {
}

handle := func() {
handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
}

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

handle := func() {
handler.HandleEventBatch(context.Background(), zap.New(), batch)
handler.HandleEventBatch(context.Background(), logr.Discard(), batch)
}

Expect(handle).Should(Panic())
Expand Down
4 changes: 2 additions & 2 deletions internal/mode/static/config_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"testing"

"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

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

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

tests := []struct {
Expand Down
Loading