github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/pkg/status/testing.go (about) 1 // Copyright 2021 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package status 16 17 import ( 18 "context" 19 20 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 21 "k8s.io/apimachinery/pkg/labels" 22 "sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader/fake" 23 "sigs.k8s.io/controller-runtime/pkg/client" 24 ) 25 26 type fakeClusterReader struct { 27 fake.NoopClusterReader 28 29 getResource *unstructured.Unstructured 30 getErr error 31 32 listResources *unstructured.UnstructuredList 33 listErr error 34 } 35 36 func (f *fakeClusterReader) Get(_ context.Context, _ client.ObjectKey, u *unstructured.Unstructured) error { 37 if f.getResource != nil { 38 u.Object = f.getResource.Object 39 } 40 return f.getErr 41 } 42 43 func (f *fakeClusterReader) ListNamespaceScoped(_ context.Context, list *unstructured.UnstructuredList, _ string, _ labels.Selector) error { 44 if f.listResources != nil { 45 list.Items = f.listResources.Items 46 } 47 return f.listErr 48 }