diff --git a/internal/pkg/catalogd/fetcher/fetcher.go b/internal/pkg/catalogd/fetcher/fetcher.go index 0e751c5..6233315 100644 --- a/internal/pkg/catalogd/fetcher/fetcher.go +++ b/internal/pkg/catalogd/fetcher/fetcher.go @@ -43,7 +43,7 @@ func (c *Fetcher) FetchCatalogs(ctx context.Context, filters ...CatalogFilterFun for _, catalog := range catalogList.Items { filteredOut := false for _, filter := range filters { - if !filter(&catalog) { + if !filter(catalog.DeepCopy()) { filteredOut = true } } diff --git a/internal/pkg/catalogd/fetcher/fetcher_test.go b/internal/pkg/catalogd/fetcher/fetcher_test.go index 7ac3a14..e62caee 100644 --- a/internal/pkg/catalogd/fetcher/fetcher_test.go +++ b/internal/pkg/catalogd/fetcher/fetcher_test.go @@ -137,10 +137,13 @@ func TestFetcher(t *testing.T) { } for _, tt := range tests { + fetch := tt.fetcher + filters := tt.filters + expectedCatalogs := tt.expectedCatalogs t.Run(tt.name, func(t *testing.T) { - catalogs, err := tt.fetcher.FetchCatalogs(context.Background(), tt.filters...) + catalogs, err := fetch.FetchCatalogs(context.Background(), filters...) require.NoError(t, err) - diff := cmp.Diff(tt.expectedCatalogs, catalogs, cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion")) + diff := cmp.Diff(expectedCatalogs, catalogs, cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion")) require.Equal(t, diff, "") }) } diff --git a/internal/pkg/catalogd/streamer/streamer_test.go b/internal/pkg/catalogd/streamer/streamer_test.go index f931a6b..33c0679 100644 --- a/internal/pkg/catalogd/streamer/streamer_test.go +++ b/internal/pkg/catalogd/streamer/streamer_test.go @@ -81,9 +81,13 @@ func TestStreamer(t *testing.T) { } for _, tt := range tests { + stream := tt.streamer + catalog := tt.catalog + expectError := tt.expectError + expectedContent := tt.expectedContent t.Run(tt.name, func(t *testing.T) { - rc, err := tt.streamer.StreamCatalogContents(context.Background(), tt.catalog) - if tt.expectError { + rc, err := stream.StreamCatalogContents(context.Background(), catalog) + if expectError { require.Error(t, err) return } @@ -93,7 +97,7 @@ func TestStreamer(t *testing.T) { }) content, err := io.ReadAll(rc) require.NoError(t, err) - require.Equal(t, tt.expectedContent, string(content)) + require.Equal(t, expectedContent, string(content)) }) } } diff --git a/internal/pkg/experimental/action/catalog_inspect.go b/internal/pkg/experimental/action/catalog_inspect.go index e5b571d..d01b367 100644 --- a/internal/pkg/experimental/action/catalog_inspect.go +++ b/internal/pkg/experimental/action/catalog_inspect.go @@ -115,6 +115,7 @@ func (i *CatalogInspect) Run(ctx context.Context, inspectOpts CatalogInspectOpti metas := []Meta{} for _, catalog := range catalogs { + catalogName := catalog.Name rc, err := stream.StreamCatalogContents(ctx, catalog) if err != nil { return nil, fmt.Errorf("streaming FBC for catalog %q: %w", catalog.Name, err) @@ -143,7 +144,7 @@ func (i *CatalogInspect) Run(ctx context.Context, inspectOpts CatalogInspectOpti Name: meta.Name, Blob: meta.Blob, }, - Catalog: catalog.Name, + Catalog: catalogName, } metas = append(metas, metaEntry) diff --git a/internal/pkg/experimental/action/catalog_list.go b/internal/pkg/experimental/action/catalog_list.go index f85ffa5..c2e7a2a 100644 --- a/internal/pkg/experimental/action/catalog_list.go +++ b/internal/pkg/experimental/action/catalog_list.go @@ -117,6 +117,7 @@ func (i *CatalogList) Run(ctx context.Context, listOpts CatalogListOptions) ([]M metas := []Meta{} for _, catalog := range catalogs { + catalogName := catalog.Name rc, err := stream.StreamCatalogContents(ctx, catalog) if err != nil { return nil, fmt.Errorf("streaming FBC for catalog %q: %w", catalog.Name, err) @@ -145,7 +146,7 @@ func (i *CatalogList) Run(ctx context.Context, listOpts CatalogListOptions) ([]M Name: meta.Name, Blob: meta.Blob, }, - Catalog: catalog.Name, + Catalog: catalogName, } metas = append(metas, metaEntry) diff --git a/internal/pkg/experimental/action/catalog_search.go b/internal/pkg/experimental/action/catalog_search.go index e5ada2c..d03ad96 100644 --- a/internal/pkg/experimental/action/catalog_search.go +++ b/internal/pkg/experimental/action/catalog_search.go @@ -107,6 +107,7 @@ func (i *CatalogSearch) Run(ctx context.Context, searchOpts CatalogSearchOptions metas := []Meta{} for _, catalog := range catalogs { + catalogName := catalog.Name rc, err := stream.StreamCatalogContents(ctx, catalog) if err != nil { return nil, fmt.Errorf("streaming FBC for catalog %q: %w", catalog.Name, err) @@ -135,7 +136,7 @@ func (i *CatalogSearch) Run(ctx context.Context, searchOpts CatalogSearchOptions Name: meta.Name, Blob: meta.Blob, }, - Catalog: catalog.Name, + Catalog: catalogName, } metas = append(metas, metaEntry)