Skip to content

Commit

Permalink
Expose WithError in FakeResourceFinder for tests
Browse files Browse the repository at this point in the history
Kubernetes-commit: f35d8a459520e1046be9a7b563306714cdf82953
  • Loading branch information
soltysh authored and k8s-publishing-bot committed Jul 8, 2024
1 parent f3a0798 commit 5e5ff2a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/genericclioptions/builder_flags_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,40 @@ import (
)

// NewSimpleFakeResourceFinder builds a super simple ResourceFinder that just iterates over the objects you provided
func NewSimpleFakeResourceFinder(infos ...*resource.Info) ResourceFinder {
return &fakeResourceFinder{
func NewSimpleFakeResourceFinder(infos ...*resource.Info) *FakeResourceFinder {
return &FakeResourceFinder{
Infos: infos,
}
}

type fakeResourceFinder struct {
func (f *FakeResourceFinder) WithError(err error) *FakeResourceFinder {
f.err = err
return f
}

type FakeResourceFinder struct {
Infos []*resource.Info
err error
}

// Do implements the interface
func (f *fakeResourceFinder) Do() resource.Visitor {
func (f *FakeResourceFinder) Do() resource.Visitor {
return &fakeResourceResult{
Infos: f.Infos,
err: f.err,
}
}

type fakeResourceResult struct {
Infos []*resource.Info
err error
}

// Visit just iterates over info
func (r *fakeResourceResult) Visit(fn resource.VisitorFunc) error {
if r.err != nil {
return r.err
}
for _, info := range r.Infos {
err := fn(info, nil)
if err != nil {
Expand Down

0 comments on commit 5e5ff2a

Please sign in to comment.