From cd7e4aed8c2832db2e15342f1855d2c736f4832c Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Wed, 1 May 2024 20:32:58 +0530 Subject: [PATCH] Fix GolangCI issues causing test failures This fixes some of the golangci issues which are causing test failures after upgrading tests to go1.22 --- pkg/adapter/adapter.go | 4 ++-- pkg/interceptors/github/github_test.go | 4 ++-- pkg/interceptors/interceptors_test.go | 4 ++-- pkg/interceptors/webhook/webhook_test.go | 2 +- pkg/reconciler/clusterinterceptor/controller.go | 4 ++-- pkg/reconciler/eventlistener/controller.go | 2 +- pkg/reconciler/interceptor/controller.go | 4 ++-- test/controller.go | 2 +- test/gate.go | 2 +- test/init_test.go | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/adapter/adapter.go b/pkg/adapter/adapter.go index 59b3bef7b..0496ff831 100644 --- a/pkg/adapter/adapter.go +++ b/pkg/adapter/adapter.go @@ -248,7 +248,7 @@ func (s *sinker) Start(ctx context.Context) error { // For handling Liveness Probe // TODO(dibyom): Livness, metrics etc. should be on a separate port - mux.HandleFunc("/live", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/live", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(200) fmt.Fprint(w, "ok") }) @@ -276,7 +276,7 @@ func (s *sinker) Start(ctx context.Context) error { } func New(sinkArgs sink.Args, sinkClients sink.Clients, recorder *sink.Recorder) adapter.AdapterConstructor { - return func(ctx context.Context, processed adapter.EnvConfigAccessor, ceClient cloudevents.Client) adapter.Adapter { + return func(ctx context.Context, processed adapter.EnvConfigAccessor, _ cloudevents.Client) adapter.Adapter { env := processed.(*envConfig) logger := logging.FromContext(ctx) diff --git a/pkg/interceptors/github/github_test.go b/pkg/interceptors/github/github_test.go index 37af0caad..6fcdd4e6a 100644 --- a/pkg/interceptors/github/github_test.go +++ b/pkg/interceptors/github/github_test.go @@ -631,7 +631,7 @@ func TestInterceptor_ExecuteTrigger_Changed_Files_Pull_Request(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) { writer.Write([]byte(tt.githubServerReply)) })) ctx, _ := test.SetupFakeContext(t) @@ -913,7 +913,7 @@ func TestInterceptor_ExecuteTrigger_Changed_Files_Push(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) { writer.Write([]byte(tt.githubServerReply)) })) ctx, _ := test.SetupFakeContext(t) diff --git a/pkg/interceptors/interceptors_test.go b/pkg/interceptors/interceptors_test.go index 7edff348b..2fe0ca660 100644 --- a/pkg/interceptors/interceptors_test.go +++ b/pkg/interceptors/interceptors_test.go @@ -289,7 +289,7 @@ func TestResolveToURL(t *testing.T) { want string }{{ name: "ClusterInterceptor has status.address.url", - getter: func(n string) (*v1alpha1.ClusterInterceptor, error) { + getter: func(_ string) (*v1alpha1.ClusterInterceptor, error) { return &v1alpha1.ClusterInterceptor{ Status: v1alpha1.ClusterInterceptorStatus{ AddressStatus: duckv1.AddressStatus{ @@ -338,7 +338,7 @@ func TestResolveToURL(t *testing.T) { } t.Run("interceptor has no URL", func(t *testing.T) { - fakeGetter := func(name string) (*v1alpha1.ClusterInterceptor, error) { + fakeGetter := func(_ string) (*v1alpha1.ClusterInterceptor, error) { return &v1alpha1.ClusterInterceptor{ Spec: v1alpha1.ClusterInterceptorSpec{ ClientConfig: v1alpha1.ClientConfig{ diff --git a/pkg/interceptors/webhook/webhook_test.go b/pkg/interceptors/webhook/webhook_test.go index 2c16aa89b..049a94177 100644 --- a/pkg/interceptors/webhook/webhook_test.go +++ b/pkg/interceptors/webhook/webhook_test.go @@ -116,7 +116,7 @@ func TestWebHookInterceptor_NotOK(t *testing.T) { }) // Create test server - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusAccepted) })) defer ts.Close() diff --git a/pkg/reconciler/clusterinterceptor/controller.go b/pkg/reconciler/clusterinterceptor/controller.go index 9e681e70c..31ea9892c 100644 --- a/pkg/reconciler/clusterinterceptor/controller.go +++ b/pkg/reconciler/clusterinterceptor/controller.go @@ -27,11 +27,11 @@ import ( ) func NewController() func(context.Context, configmap.Watcher) *controller.Impl { - return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + return func(ctx context.Context, _ configmap.Watcher) *controller.Impl { clusterInterceptorInformer := clusterinterceptorinformer.Get(ctx) reconciler := &Reconciler{} - impl := clusterinterceptorreconciler.NewImpl(ctx, reconciler, func(impl *controller.Impl) controller.Options { + impl := clusterinterceptorreconciler.NewImpl(ctx, reconciler, func(_ *controller.Impl) controller.Options { return controller.Options{ AgentName: ControllerName, } diff --git a/pkg/reconciler/eventlistener/controller.go b/pkg/reconciler/eventlistener/controller.go index 142edfd01..eab3e0bd0 100644 --- a/pkg/reconciler/eventlistener/controller.go +++ b/pkg/reconciler/eventlistener/controller.go @@ -62,7 +62,7 @@ func NewController(config resources.Config) func(context.Context, configmap.Watc Metrics: metrics.Get(ctx), } - impl := eventlistenerreconciler.NewImpl(ctx, reconciler, func(impl *controller.Impl) controller.Options { + impl := eventlistenerreconciler.NewImpl(ctx, reconciler, func(_ *controller.Impl) controller.Options { configStore := cfg.NewStore(logger.Named("config-store")) configStore.WatchConfigs(cmw) return controller.Options{ diff --git a/pkg/reconciler/interceptor/controller.go b/pkg/reconciler/interceptor/controller.go index 8dfc4b46a..07575ead8 100644 --- a/pkg/reconciler/interceptor/controller.go +++ b/pkg/reconciler/interceptor/controller.go @@ -27,11 +27,11 @@ import ( ) func NewController() func(context.Context, configmap.Watcher) *controller.Impl { - return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { + return func(ctx context.Context, _ configmap.Watcher) *controller.Impl { interceptorInformer := interceptorinformer.Get(ctx) reconciler := &Reconciler{} - impl := interceptorreconciler.NewImpl(ctx, reconciler, func(impl *controller.Impl) controller.Options { + impl := interceptorreconciler.NewImpl(ctx, reconciler, func(_ *controller.Impl) controller.Options { return controller.Options{ AgentName: ControllerName, } diff --git a/test/controller.go b/test/controller.go index 231ea2296..c95082f35 100644 --- a/test/controller.go +++ b/test/controller.go @@ -102,7 +102,7 @@ type Assets struct { func init() { // Register a separate fake dynamic client with out schemes. - injection.Fake.RegisterClient(func(ctx context.Context, cfg *rest.Config) context.Context { + injection.Fake.RegisterClient(func(ctx context.Context, _ *rest.Config) context.Context { scheme := runtime.NewScheme() err := servingv1.AddToScheme(scheme) if err != nil { diff --git a/test/gate.go b/test/gate.go index bb7e121dd..58707480d 100644 --- a/test/gate.go +++ b/test/gate.go @@ -29,7 +29,7 @@ func FeatureFlagsToContext(ctx context.Context, flags map[string]string) (contex // the feature-flag configmap. // nolint:unused,deadcode func requireGate(name, value string) func(context.Context, *testing.T, *clients, string) { - return func(ctx context.Context, t *testing.T, c *clients, namespace string) { + return func(ctx context.Context, t *testing.T, c *clients, _ string) { featureFlagsCM, err := c.KubeClient.CoreV1().ConfigMaps(system.Namespace()).Get(ctx, config.GetFeatureFlagsConfigName(), metav1.GetOptions{}) if err != nil { t.Fatalf("Failed to get ConfigMap `%s`: %s", config.GetFeatureFlagsConfigName(), err) diff --git a/test/init_test.go b/test/init_test.go index 13f6a19d8..527568320 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -162,7 +162,7 @@ func verifyDefaultServiceAccountExists(t *testing.T, namespace string, kubeClien func getCRDYaml(cs *clients, ns string) ([]byte, error) { var output []byte - printOrAdd := func(kind, name string, i interface{}) { + printOrAdd := func(_, _ string, i interface{}) { bs, err := json.Marshal(i) if err != nil { return