Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions pkg/cache/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
}
}

func (c *clusterCache) getResourceUpdatedHandlers() []OnResourceUpdatedHandler {

Check warning on line 285 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiR&open=AZrqUnd0uv_LmxkIRmiR&pullRequest=794
c.handlersLock.Lock()
defer c.handlersLock.Unlock()
var handlers []OnResourceUpdatedHandler
Expand All @@ -306,7 +306,7 @@
}
}

func (c *clusterCache) getEventHandlers() []OnEventHandler {

Check warning on line 309 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiS&open=AZrqUnd0uv_LmxkIRmiS&pullRequest=794
c.handlersLock.Lock()
defer c.handlersLock.Unlock()
handlers := make([]OnEventHandler, 0, len(c.eventHandlers))
Expand All @@ -330,7 +330,7 @@
}
}

func (c *clusterCache) getProcessEventsHandlers() []OnProcessEventsHandler {

Check warning on line 333 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiT&open=AZrqUnd0uv_LmxkIRmiT&pullRequest=794
c.handlersLock.Lock()
defer c.handlersLock.Unlock()
handlers := make([]OnProcessEventsHandler, 0, len(c.processEventsHandlers))
Expand All @@ -341,7 +341,7 @@
}

// GetServerVersion returns observed cluster version
func (c *clusterCache) GetServerVersion() string {

Check warning on line 344 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiU&open=AZrqUnd0uv_LmxkIRmiU&pullRequest=794
return c.serverVersion
}

Expand All @@ -355,13 +355,13 @@
}

// GetOpenAPISchema returns open API schema of supported API resources
func (c *clusterCache) GetOpenAPISchema() openapi.Resources {

Check warning on line 358 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiW&open=AZrqUnd0uv_LmxkIRmiW&pullRequest=794
return c.openAPISchema
}

// GetGVKParser returns a parser able to build a TypedValue used in
// structured merge diffs.
func (c *clusterCache) GetGVKParser() *managedfields.GvkParser {

Check warning on line 364 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiX&open=AZrqUnd0uv_LmxkIRmiX&pullRequest=794
return c.gvkParser
}

Expand Down Expand Up @@ -578,7 +578,7 @@

// listResources creates list pager and enforces number of concurrent list requests
// The callback should not wait on any locks that may be held by other callers.
func (c *clusterCache) listResources(ctx context.Context, resClient dynamic.ResourceInterface, callback func(*pager.ListPager) error) (string, error) {

Check failure on line 581 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmid&open=AZrqUnd0uv_LmxkIRmid&pullRequest=794
if err := c.listSemaphore.Acquire(ctx, 1); err != nil {
return "", fmt.Errorf("failed to acquire list semaphore: %w", err)
}
Expand Down Expand Up @@ -606,6 +606,10 @@
retryCount++
c.log.Info(fmt.Sprintf("Error while listing resources: %v (try %d/%d)", ierr, retryCount, c.listRetryLimit))
}
// Ensure res is never nil even when there's an error
if res == nil {
res = &unstructured.UnstructuredList{}
}
//nolint:wrapcheck // wrap outside the retry
return ierr
}
Expand All @@ -630,7 +634,7 @@
return listPager.EachListItem(ctx, metav1.ListOptions{}, func(obj runtime.Object) error {
if un, ok := obj.(*unstructured.Unstructured); !ok {
return fmt.Errorf("object %s/%s has an unexpected type", un.GroupVersionKind().String(), un.GetName())
} else {

Check failure on line 637 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'else' clause; the code should continue after the error check.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmia&open=AZrqUnd0uv_LmxkIRmia&pullRequest=794
items = append(items, c.newResource(un))
}
return nil
Expand Down Expand Up @@ -938,7 +942,7 @@
return listPager.EachListItem(context.Background(), metav1.ListOptions{}, func(obj runtime.Object) error {
if un, ok := obj.(*unstructured.Unstructured); !ok {
return fmt.Errorf("object %s/%s has an unexpected type", un.GroupVersionKind().String(), un.GetName())
} else {

Check failure on line 945 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'else' clause; the code should continue after the error check.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmib&open=AZrqUnd0uv_LmxkIRmib&pullRequest=794
newRes := c.newResource(un)
lock.Lock()
c.setNode(newRes)
Expand Down Expand Up @@ -1335,7 +1339,7 @@
}
}

func (c *clusterCache) onNodeUpdated(oldRes *Resource, newRes *Resource) {

Check warning on line 1342 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Group together these consecutive parameters of the same type.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmic&open=AZrqUnd0uv_LmxkIRmic&pullRequest=794
c.setNode(newRes)
for _, h := range c.getResourceUpdatedHandlers() {
h(newRes, oldRes, c.nsIndex[newRes.Ref.Namespace])
Expand Down Expand Up @@ -1372,7 +1376,7 @@
}

// GetClusterInfo returns cluster cache statistics
func (c *clusterCache) GetClusterInfo() ClusterInfo {

Check warning on line 1379 in pkg/cache/cluster.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the 'Get' prefix from this function name.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnd0uv_LmxkIRmiZ&open=AZrqUnd0uv_LmxkIRmiZ&pullRequest=794
c.lock.RLock()
defer c.lock.RUnlock()
c.syncStatus.lock.Lock()
Expand Down
109 changes: 109 additions & 0 deletions pkg/cache/cluster_nil_fix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cache

import (
"context"
"errors"
"testing"

"golang.org/x/sync/semaphore"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/pager"
"k8s.io/klog/v2/textlogger"
)

// mockResourceInterface simulates a dynamic resource interface that returns (nil, error)
type mockResourceInterface struct{}

func (m *mockResourceInterface) Create(ctx context.Context, obj *unstructured.Unstructured, options metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error) {

Check failure on line 22 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 22 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'obj' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmif&open=AZrqUnkSuv_LmxkIRmif&pullRequest=794

Check warning on line 22 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmig&open=AZrqUnkSuv_LmxkIRmig&pullRequest=794

Check warning on line 22 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'subresources' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmih&open=AZrqUnkSuv_LmxkIRmih&pullRequest=794

Check warning on line 22 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmie&open=AZrqUnkSuv_LmxkIRmie&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) Update(ctx context.Context, obj *unstructured.Unstructured, options metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error) {

Check failure on line 26 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 26 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmik&open=AZrqUnkSuv_LmxkIRmik&pullRequest=794

Check warning on line 26 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'subresources' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmil&open=AZrqUnkSuv_LmxkIRmil&pullRequest=794

Check warning on line 26 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmii&open=AZrqUnkSuv_LmxkIRmii&pullRequest=794

Check warning on line 26 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'obj' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmij&open=AZrqUnkSuv_LmxkIRmij&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) UpdateStatus(ctx context.Context, obj *unstructured.Unstructured, options metav1.UpdateOptions) (*unstructured.Unstructured, error) {

Check failure on line 30 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 30 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmio&open=AZrqUnkSuv_LmxkIRmio&pullRequest=794

Check warning on line 30 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'obj' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmin&open=AZrqUnkSuv_LmxkIRmin&pullRequest=794

Check warning on line 30 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmim&open=AZrqUnkSuv_LmxkIRmim&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) Delete(ctx context.Context, name string, options metav1.DeleteOptions, subresources ...string) error {

Check failure on line 34 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 34 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'name' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmiq&open=AZrqUnkSuv_LmxkIRmiq&pullRequest=794

Check warning on line 34 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'subresources' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmis&open=AZrqUnkSuv_LmxkIRmis&pullRequest=794

Check warning on line 34 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmip&open=AZrqUnkSuv_LmxkIRmip&pullRequest=794

Check warning on line 34 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmir&open=AZrqUnkSuv_LmxkIRmir&pullRequest=794
return errors.New("not implemented")
}

func (m *mockResourceInterface) DeleteCollection(ctx context.Context, options metav1.DeleteOptions, listOptions metav1.ListOptions) error {

Check failure on line 38 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 38 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmit&open=AZrqUnkSuv_LmxkIRmit&pullRequest=794

Check warning on line 38 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmiu&open=AZrqUnkSuv_LmxkIRmiu&pullRequest=794

Check warning on line 38 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'listOptions' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmiv&open=AZrqUnkSuv_LmxkIRmiv&pullRequest=794
return errors.New("not implemented")
}

func (m *mockResourceInterface) Get(ctx context.Context, name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error) {

Check failure on line 42 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 42 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'subresources' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmiz&open=AZrqUnkSuv_LmxkIRmiz&pullRequest=794

Check warning on line 42 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmiy&open=AZrqUnkSuv_LmxkIRmiy&pullRequest=794

Check warning on line 42 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmiw&open=AZrqUnkSuv_LmxkIRmiw&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) List(ctx context.Context, opts metav1.ListOptions) (*unstructured.UnstructuredList, error) {

Check failure on line 46 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 46 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi0&open=AZrqUnkSuv_LmxkIRmi0&pullRequest=794

Check warning on line 46 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'opts' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi1&open=AZrqUnkSuv_LmxkIRmi1&pullRequest=794
// This simulates the problematic behavior that caused the original panic:
// returning (nil, error) instead of (emptyList, error)
return nil, errors.New("simulated list failure")
}

func (m *mockResourceInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {

Check failure on line 52 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 52 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi2&open=AZrqUnkSuv_LmxkIRmi2&pullRequest=794

Check warning on line 52 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'opts' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi3&open=AZrqUnkSuv_LmxkIRmi3&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, options metav1.PatchOptions, subresources ...string) (*unstructured.Unstructured, error) {

Check failure on line 56 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 56 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'name' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi5&open=AZrqUnkSuv_LmxkIRmi5&pullRequest=794

Check warning on line 56 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi8&open=AZrqUnkSuv_LmxkIRmi8&pullRequest=794

Check warning on line 56 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'pt' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi6&open=AZrqUnkSuv_LmxkIRmi6&pullRequest=794

Check warning on line 56 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'data' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi7&open=AZrqUnkSuv_LmxkIRmi7&pullRequest=794

Check warning on line 56 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'subresources' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi9&open=AZrqUnkSuv_LmxkIRmi9&pullRequest=794

Check warning on line 56 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi4&open=AZrqUnkSuv_LmxkIRmi4&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) Apply(ctx context.Context, name string, obj *unstructured.Unstructured, options metav1.ApplyOptions, subresources ...string) (*unstructured.Unstructured, error) {

Check failure on line 60 in pkg/cache/cluster_nil_fix_test.go

View workflow job for this annotation

GitHub Actions / test

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 60 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'name' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi_&open=AZrqUnkSuv_LmxkIRmi_&pullRequest=794

Check warning on line 60 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'subresources' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmjC&open=AZrqUnkSuv_LmxkIRmjC&pullRequest=794

Check warning on line 60 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'obj' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmjA&open=AZrqUnkSuv_LmxkIRmjA&pullRequest=794

Check warning on line 60 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmjB&open=AZrqUnkSuv_LmxkIRmjB&pullRequest=794

Check warning on line 60 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'ctx' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmi-&open=AZrqUnkSuv_LmxkIRmi-&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) ApplyStatus(ctx context.Context, name string, obj *unstructured.Unstructured, options metav1.ApplyOptions) (*unstructured.Unstructured, error) {

Check warning on line 64 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'obj' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmjF&open=AZrqUnkSuv_LmxkIRmjF&pullRequest=794

Check warning on line 64 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'name' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmjE&open=AZrqUnkSuv_LmxkIRmjE&pullRequest=794

Check warning on line 64 in pkg/cache/cluster_nil_fix_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unused parameter 'options' should be removed.

See more on https://sonarcloud.io/project/issues?id=argoproj_gitops-engine&issues=AZrqUnkSuv_LmxkIRmjG&open=AZrqUnkSuv_LmxkIRmjG&pullRequest=794
return nil, errors.New("not implemented")
}

func (m *mockResourceInterface) Namespace(string) dynamic.ResourceInterface {
return m
}

// TestListResourcesNilPointerFix tests that our fix prevents panic when
// resClient.List() returns (nil, error)
func TestListResourcesNilPointerFix(t *testing.T) {
// Create a cluster cache with proper configuration
cache := &clusterCache{
listSemaphore: semaphore.NewWeighted(1),
listPageSize: 100,
listPageBufferSize: 1,
listRetryLimit: 1,
listRetryUseBackoff: false,
listRetryFunc: ListRetryFuncNever,
log: textlogger.NewLogger(textlogger.NewConfig()),
}

// Use our mock that returns (nil, error)
mockClient := &mockResourceInterface{}

// This should not panic even though mockClient.List() returns (nil, error)
_, err := cache.listResources(context.Background(), mockClient, func(listPager *pager.ListPager) error {
// The fix ensures the pager receives a non-nil UnstructuredList
// preventing panic in GetContinue()
return listPager.EachListItem(context.Background(), metav1.ListOptions{}, func(obj runtime.Object) error {
return nil
})
})

// We expect an error (wrapped), but no panic should occur
if err == nil {
t.Fatal("Expected error from listResources due to simulated failure")
}

// Check that the error is properly wrapped
if err.Error() != "failed to list resources: simulated list failure" {
t.Fatalf("Unexpected error message: %v", err.Error())
}

t.Log("Test passed: no panic occurred despite (nil, error) from resClient.List()")
}