diff --git a/cmd/gateway/commands.go b/cmd/gateway/commands.go index 29c729f436..4d8fb8ce97 100644 --- a/cmd/gateway/commands.go +++ b/cmd/gateway/commands.go @@ -33,7 +33,7 @@ func createRootCommand() *cobra.Command { Use: "gateway", SilenceUsage: true, SilenceErrors: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Help() }, } @@ -100,7 +100,7 @@ func createStaticModeCommand() *cobra.Command { cmd := &cobra.Command{ Use: "static-mode", Short: "Configure NGINX in the scope of a single Gateway resource", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { atom := zap.NewAtomicLevel() logger := ctlrZap.New(ctlrZap.Level(atom)) @@ -301,7 +301,7 @@ func createProvisionerModeCommand() *cobra.Command { Use: "provisioner-mode", Short: "Provision a static-mode NGINX Gateway Fabric Deployment per Gateway resource", Hidden: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { logger := ctlrZap.New() logger.Info( "Starting NGINX Gateway Fabric Provisioner", @@ -348,7 +348,7 @@ func createSleepCommand() *cobra.Command { cmd := &cobra.Command{ Use: "sleep", Short: "Sleep for specified duration and exit", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // It is expected that this command is run from lifecycle hook. // Because logs from hooks are not visible in the container logs, we don't log here at all. time.Sleep(duration) diff --git a/cmd/gateway/commands_test.go b/cmd/gateway/commands_test.go index cbb8f6697e..80396eb888 100644 --- a/cmd/gateway/commands_test.go +++ b/cmd/gateway/commands_test.go @@ -22,7 +22,7 @@ func testFlag(t *testing.T, cmd *cobra.Command, test flagTestCase) { cmd.SetErr(io.Discard) // override RunE to avoid executing the command - cmd.RunE = func(cmd *cobra.Command, args []string) error { + cmd.RunE = func(_ *cobra.Command, _ []string) error { return nil } diff --git a/internal/framework/controller/reconciler_test.go b/internal/framework/controller/reconciler_test.go index af7fe7af7e..d6727aad77 100644 --- a/internal/framework/controller/reconciler_test.go +++ b/internal/framework/controller/reconciler_test.go @@ -59,10 +59,10 @@ var _ = Describe("Reconciler", func() { getReturnsHRForHR := func(hr *v1.HTTPRoute) getFunc { return func( - ctx context.Context, + _ context.Context, nsname types.NamespacedName, object client.Object, - option ...client.GetOption, + _ ...client.GetOption, ) error { Expect(object).To(BeAssignableToTypeOf(&v1.HTTPRoute{})) Expect(nsname).To(Equal(client.ObjectKeyFromObject(hr))) @@ -75,10 +75,10 @@ var _ = Describe("Reconciler", func() { getReturnsNotFoundErrorForHR := func(hr *v1.HTTPRoute) getFunc { return func( - ctx context.Context, + _ context.Context, nsname types.NamespacedName, object client.Object, - option ...client.GetOption, + _ ...client.GetOption, ) error { Expect(object).To(BeAssignableToTypeOf(&v1.HTTPRoute{})) Expect(nsname).To(Equal(client.ObjectKeyFromObject(hr))) diff --git a/internal/framework/controller/register_test.go b/internal/framework/controller/register_test.go index ac4e4c61c9..03f5b7738a 100644 --- a/internal/framework/controller/register_test.go +++ b/internal/framework/controller/register_test.go @@ -17,7 +17,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/log/zap" v1 "sigs.k8s.io/gateway-api/apis/v1" - v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" + "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/controllerfakes" @@ -103,7 +103,7 @@ func TestRegister(t *testing.T) { }, } - nsNameFilter := func(nsname types.NamespacedName) (bool, string) { + nsNameFilter := func(_ types.NamespacedName) (bool, string) { return true, "" } diff --git a/internal/framework/events/first_eventbatch_preparer_test.go b/internal/framework/events/first_eventbatch_preparer_test.go index 67e49f0ddf..8fd79b1b78 100644 --- a/internal/framework/events/first_eventbatch_preparer_test.go +++ b/internal/framework/events/first_eventbatch_preparer_test.go @@ -46,7 +46,7 @@ var _ = Describe("FirstEventBatchPreparer", func() { It("should prepare zero events when resources don't exist", func() { fakeReader.GetCalls( - func(ctx context.Context, name types.NamespacedName, object client.Object, opts ...client.GetOption) error { + func(_ context.Context, name types.NamespacedName, object client.Object, _ ...client.GetOption) error { Expect(name).Should(Equal(types.NamespacedName{Name: gcName})) Expect(object).Should(BeAssignableToTypeOf(&v1.GatewayClass{})) @@ -65,7 +65,7 @@ var _ = Describe("FirstEventBatchPreparer", func() { gatewayClass := v1.GatewayClass{ObjectMeta: metav1.ObjectMeta{Name: gcName}} fakeReader.GetCalls( - func(ctx context.Context, name types.NamespacedName, object client.Object, opts ...client.GetOption) error { + func(_ context.Context, name types.NamespacedName, object client.Object, _ ...client.GetOption) error { Expect(name).Should(Equal(types.NamespacedName{Name: gcName})) Expect(object).Should(BeAssignableToTypeOf(&v1.GatewayClass{})) @@ -76,7 +76,7 @@ var _ = Describe("FirstEventBatchPreparer", func() { httpRoute := v1.HTTPRoute{ObjectMeta: metav1.ObjectMeta{Name: "test"}} - fakeReader.ListCalls(func(ctx context.Context, list client.ObjectList, option ...client.ListOption) error { + fakeReader.ListCalls(func(_ context.Context, list client.ObjectList, option ...client.ListOption) error { Expect(option).To(BeEmpty()) switch typedList := list.(type) { @@ -106,7 +106,7 @@ var _ = Describe("FirstEventBatchPreparer", func() { BeforeEach(func() { fakeReader.GetReturns(apierrors.NewNotFound(schema.GroupResource{}, "test")) fakeReader.ListCalls( - func(ctx context.Context, list client.ObjectList, option ...client.ListOption) error { + func(_ context.Context, list client.ObjectList, _ ...client.ListOption) error { httpRoute := v1.HTTPRoute{ObjectMeta: metav1.ObjectMeta{Name: "test"}} typedList := list.(*v1.HTTPRouteList) typedList.Items = append(typedList.Items, httpRoute) @@ -117,7 +117,7 @@ var _ = Describe("FirstEventBatchPreparer", func() { }) It("should return error if EachListItem passes a wrong object type", func() { - preparer.SetEachListItem(func(obj runtime.Object, fn func(runtime.Object) error) error { + preparer.SetEachListItem(func(_ runtime.Object, fn func(runtime.Object) error) error { return fn(&fakeRuntimeObject{}) }) @@ -129,7 +129,7 @@ var _ = Describe("FirstEventBatchPreparer", func() { It("should return error if EachListItem returns an error", func() { testError := errors.New("test") - preparer.SetEachListItem(func(obj runtime.Object, fn func(runtime.Object) error) error { + preparer.SetEachListItem(func(_ runtime.Object, _ func(runtime.Object) error) error { return testError }) diff --git a/internal/framework/events/loop_test.go b/internal/framework/events/loop_test.go index 19a6f37440..589b1a32dd 100644 --- a/internal/framework/events/loop_test.go +++ b/internal/framework/events/loop_test.go @@ -83,7 +83,7 @@ var _ = Describe("EventLoop", func() { // The func below will pause the handler goroutine while it is processing the batch with e1 until // sentSecondAndThirdEvents is closed. This way we can add e2 and e3 to the current batch in the meantime. - fakeHandler.HandleEventBatchCalls(func(ctx context.Context, logger logr.Logger, batch events.EventBatch) { + fakeHandler.HandleEventBatchCalls(func(_ context.Context, _ logr.Logger, _ events.EventBatch) { close(firstHandleEventBatchCallInProgress) <-sentSecondAndThirdEvents }) diff --git a/internal/framework/runnables/cronjob_test.go b/internal/framework/runnables/cronjob_test.go index 9a3a6bbf72..ca1154c30a 100644 --- a/internal/framework/runnables/cronjob_test.go +++ b/internal/framework/runnables/cronjob_test.go @@ -55,7 +55,7 @@ func TestCronJob_ContextCanceled(t *testing.T) { readyChannel := make(chan struct{}) cfg := CronJobConfig{ - Worker: func(ctx context.Context) {}, + Worker: func(_ context.Context) {}, Logger: zap.New(), Period: 1 * time.Millisecond, // 1ms is much smaller than timeout so the CronJob should run a few times ReadyCh: readyChannel, diff --git a/internal/mode/static/config_updater_test.go b/internal/mode/static/config_updater_test.go index 4380a4af8e..ee44971950 100644 --- a/internal/mode/static/config_updater_test.go +++ b/internal/mode/static/config_updater_test.go @@ -75,7 +75,7 @@ func TestUpdateControlPlane(t *testing.T) { g := NewWithT(t) fakeLogSetter := &staticfakes.FakeLogLevelSetter{ - SetLevelStub: func(s string) error { + SetLevelStub: func(_ string) error { return test.setLevelErr }, } diff --git a/internal/mode/static/nginx/config/servers_test.go b/internal/mode/static/nginx/config/servers_test.go index a78259353e..2040bcfef1 100644 --- a/internal/mode/static/nginx/config/servers_test.go +++ b/internal/mode/static/nginx/config/servers_test.go @@ -987,8 +987,6 @@ func TestCreateServersConflicts(t *testing.T) { } func TestCreateLocationsRootPath(t *testing.T) { - g := NewWithT(t) - hrNsName := types.NamespacedName{Namespace: "test", Name: "route1"} fooGroup := dataplane.BackendGroup{ @@ -1104,6 +1102,8 @@ func TestCreateLocationsRootPath(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { + g := NewWithT(t) + locs := createLocations(test.pathRules, 80) g.Expect(locs).To(Equal(test.expLocations)) }) diff --git a/internal/mode/static/nginx/file/folders_test.go b/internal/mode/static/nginx/file/folders_test.go index 10057be477..9e1e8f518b 100644 --- a/internal/mode/static/nginx/file/folders_test.go +++ b/internal/mode/static/nginx/file/folders_test.go @@ -51,7 +51,7 @@ func TestClearFoldersFails(t *testing.T) { }{ { fileMgr: &filefakes.FakeClearFoldersOSFileManager{ - ReadDirStub: func(dirname string) ([]os.DirEntry, error) { + ReadDirStub: func(_ string) ([]os.DirEntry, error) { return nil, testErr }, }, @@ -59,7 +59,7 @@ func TestClearFoldersFails(t *testing.T) { }, { fileMgr: &filefakes.FakeClearFoldersOSFileManager{ - ReadDirStub: func(dirname string) ([]os.DirEntry, error) { + ReadDirStub: func(_ string) ([]os.DirEntry, error) { return []os.DirEntry{ &filefakes.FakeDirEntry{ NameStub: func() string { @@ -68,7 +68,7 @@ func TestClearFoldersFails(t *testing.T) { }, }, nil }, - RemoveStub: func(name string) error { + RemoveStub: func(_ string) error { return testErr }, }, diff --git a/internal/mode/static/nginx/file/manager_test.go b/internal/mode/static/nginx/file/manager_test.go index 12f51a0f4f..1963090f6b 100644 --- a/internal/mode/static/nginx/file/manager_test.go +++ b/internal/mode/static/nginx/file/manager_test.go @@ -191,7 +191,7 @@ var _ = Describe("EventHandler", func() { Entry( "Remove", &filefakes.FakeOSFileManager{ - RemoveStub: func(s string) error { + RemoveStub: func(_ string) error { return testErr }, }, @@ -199,7 +199,7 @@ var _ = Describe("EventHandler", func() { Entry( "Create", &filefakes.FakeOSFileManager{ - CreateStub: func(s string) (*os.File, error) { + CreateStub: func(_ string) (*os.File, error) { return nil, testErr }, }, @@ -207,7 +207,7 @@ var _ = Describe("EventHandler", func() { Entry( "Chmod", &filefakes.FakeOSFileManager{ - ChmodStub: func(os *os.File, mode os.FileMode) error { + ChmodStub: func(_ *os.File, _ os.FileMode) error { return testErr }, }, @@ -215,7 +215,7 @@ var _ = Describe("EventHandler", func() { Entry( "Write", &filefakes.FakeOSFileManager{ - WriteStub: func(os *os.File, bytes []byte) error { + WriteStub: func(_ *os.File, _ []byte) error { return testErr }, }, diff --git a/internal/mode/static/nginx/runtime/manager.go b/internal/mode/static/nginx/runtime/manager.go index ee20146023..add590a443 100644 --- a/internal/mode/static/nginx/runtime/manager.go +++ b/internal/mode/static/nginx/runtime/manager.go @@ -172,7 +172,7 @@ func findMainProcess( ctx, 500*time.Millisecond, true, /* poll immediately */ - func(ctx context.Context) (bool, error) { + func(_ context.Context) (bool, error) { _, err := checkFile(pidFile) if err == nil { return true, nil diff --git a/internal/mode/static/nginx/runtime/verify.go b/internal/mode/static/nginx/runtime/verify.go index 673b4e1ec5..c88ce2faa4 100644 --- a/internal/mode/static/nginx/runtime/verify.go +++ b/internal/mode/static/nginx/runtime/verify.go @@ -110,7 +110,7 @@ func (c *verifyClient) ensureConfigVersion(ctx context.Context, expectedVersion ctx, 25*time.Millisecond, true, /* poll immediately */ - func(ctx context.Context) (bool, error) { + func(_ context.Context) (bool, error) { version, err := c.getConfigVersion() return version == expectedVersion, err }, @@ -127,7 +127,7 @@ func ensureNewNginxWorkers( ctx, 25*time.Millisecond, true, /* poll immediately */ - func(ctx context.Context) (bool, error) { + func(_ context.Context) (bool, error) { content, err := readFile(childProcFile) if err != nil { return false, err diff --git a/internal/mode/static/state/changed_predicate_test.go b/internal/mode/static/state/changed_predicate_test.go index 15af3f82d0..f82eda158f 100644 --- a/internal/mode/static/state/changed_predicate_test.go +++ b/internal/mode/static/state/changed_predicate_test.go @@ -11,7 +11,7 @@ import ( ) func TestFuncPredicate(t *testing.T) { - alwaysTrueFunc := func(object client.Object, _ types.NamespacedName) bool { return true } + alwaysTrueFunc := func(_ client.Object, _ types.NamespacedName) bool { return true } emptyObject := &v1.Pod{} p := funcPredicate{stateChanged: alwaysTrueFunc} @@ -23,7 +23,7 @@ func TestFuncPredicate(t *testing.T) { } func TestFuncPredicate_Panic(t *testing.T) { - alwaysTrueFunc := func(object client.Object, _ types.NamespacedName) bool { return true } + alwaysTrueFunc := func(_ client.Object, _ types.NamespacedName) bool { return true } p := funcPredicate{stateChanged: alwaysTrueFunc} diff --git a/internal/mode/static/state/dataplane/configuration_test.go b/internal/mode/static/state/dataplane/configuration_test.go index cce6f0e749..f797dd9a66 100644 --- a/internal/mode/static/state/dataplane/configuration_test.go +++ b/internal/mode/static/state/dataplane/configuration_test.go @@ -1994,9 +1994,9 @@ func TestBuildUpstreams(t *testing.T) { fakeResolver := &resolverfakes.FakeServiceResolver{} fakeResolver.ResolveCalls(func( - ctx context.Context, + _ context.Context, svcNsName types.NamespacedName, - servicePort apiv1.ServicePort, + _ apiv1.ServicePort, ) ([]resolver.Endpoint, error) { switch svcNsName.Name { case "bar": diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 54a7cf8539..e30eb13763 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -26,7 +26,7 @@ func createListCallsFunc(nodes []v1.Node) func( list client.ObjectList, option ...client.ListOption, ) error { - return func(ctx context.Context, list client.ObjectList, option ...client.ListOption) error { + return func(_ context.Context, list client.ObjectList, option ...client.ListOption) error { Expect(option).To(BeEmpty()) switch typedList := list.(type) { diff --git a/tests/framework/load.go b/tests/framework/load.go index a6347f720e..db3b84c7ac 100644 --- a/tests/framework/load.go +++ b/tests/framework/load.go @@ -60,7 +60,7 @@ func RunLoadTest(cfg LoadTestConfig) (vegeta.Results, Metrics) { httpClient := http.Client{ Timeout: vegeta.DefaultTimeout, Transport: &http.Transport{ - DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + DialContext: func(ctx context.Context, network, _ string) (net.Conn, error) { return dialer.DialContext(ctx, network, cfg.Proxy) }, TLSClientConfig: &tls.Config{ diff --git a/tests/suite/upgrade_test.go b/tests/suite/upgrade_test.go index da0ce66090..3fa71bcc6d 100644 --- a/tests/suite/upgrade_test.go +++ b/tests/suite/upgrade_test.go @@ -212,7 +212,7 @@ var _ = Describe("Upgrade testing", Label("upgrade"), func() { leaseCtx, 500*time.Millisecond, true, /* poll immediately */ - func(ctx context.Context) (bool, error) { + func(_ context.Context) (bool, error) { Expect(k8sClient.Get(leaseCtx, key, &lease)).To(Succeed()) if lease.Spec.HolderIdentity != nil {