Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add create mock test or ODLMoperator
Signed-off-by: YuChen <[email protected]>
  • Loading branch information
YuChen committed Nov 28, 2024
commit 6c7c574d5595233e48ef4d71d1a6bf61535bd6a3
15 changes: 15 additions & 0 deletions controllers/operator/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func TestGetFirstAvailableSemverChannelFromCatalog(t *testing.T) {
type MockReader struct {
PackageManifestList *operatorsv1.PackageManifestList
CatalogSourceList *olmv1alpha1.CatalogSourceList
CreatedObjects map[string]client.Object
}

func (m *MockReader) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error {
Expand All @@ -248,6 +249,20 @@ func (m *MockReader) List(ctx context.Context, list client.ObjectList, opts ...c
return nil
}

func (m *MockReader) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
if m.CreatedObjects == nil {
m.CreatedObjects = make(map[string]client.Object)
}

// Generate a unique key based on the object's name and namespace
key := fmt.Sprintf("%s/%s", obj.GetNamespace(), obj.GetName())

// Store the object in the map
m.CreatedObjects[key] = obj

return nil
}

func TestGetCatalogSourceAndChannelFromPackage(t *testing.T) {
ctx := context.TODO()

Expand Down