Skip to content

Commit

Permalink
pkg/indexer: add bcp indexer name (#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-urbaniak authored Jul 5, 2024
1 parent 89c7cb6 commit 5696410
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/indexer/atlasbackupcompliancepolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
AtlasProjectByBackupCompliancePolicyIndex = ""
AtlasProjectByBackupCompliancePolicyIndex = "atlasproject.spec.backupCompliancePolicyRef"
)

type AtlasProjectByBackupCompliancePolicyIndexer struct {
Expand Down
45 changes: 45 additions & 0 deletions pkg/indexer/indexer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package indexer

import (
"context"
"fmt"
"testing"

"k8s.io/apimachinery/pkg/util/sets"

"go.uber.org/zap/zaptest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

type managerMock struct {
manager.Manager
client.FieldIndexer

fields sets.Set[string]
}

func (m *managerMock) GetFieldIndexer() client.FieldIndexer {
return m
}

func (m *managerMock) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error {
if field == "" {
return fmt.Errorf("error adding indexer for type %T: field is empty", obj)
}

if m.fields.Has(field) {
return fmt.Errorf("error indexing field %q: field is already registered", field)
}

m.fields.Insert(field)

return nil
}

func TestRegisterAll(t *testing.T) {
err := RegisterAll(context.Background(), &managerMock{fields: sets.New[string]()}, zaptest.NewLogger(t))
if err != nil {
t.Error(err)
}
}

0 comments on commit 5696410

Please sign in to comment.