mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Adds visitor test for traversal errors
This commit is contained in:
parent
58e7d16fb7
commit
05c45b5cfc
@ -375,7 +375,6 @@ func (v ContinueOnErrorVisitor) Visit(fn VisitorFunc) error {
|
|||||||
// that interface - into multiple Infos. Returns nil in the case of no errors.
|
// that interface - into multiple Infos. Returns nil in the case of no errors.
|
||||||
// When an error is hit on sub items (for instance, if a List contains an object that does
|
// When an error is hit on sub items (for instance, if a List contains an object that does
|
||||||
// not have a registered client or resource), returns an aggregate error.
|
// not have a registered client or resource), returns an aggregate error.
|
||||||
|
|
||||||
type FlattenListVisitor struct {
|
type FlattenListVisitor struct {
|
||||||
visitor Visitor
|
visitor Visitor
|
||||||
typer runtime.ObjectTyper
|
typer runtime.ObjectTyper
|
||||||
@ -428,7 +427,6 @@ func (v FlattenListVisitor) Visit(fn VisitorFunc) error {
|
|||||||
errs := []error{}
|
errs := []error{}
|
||||||
for i := range items {
|
for i := range items {
|
||||||
item, err := v.mapper.infoForObject(items[i], v.typer, preferredGVKs)
|
item, err := v.mapper.infoForObject(items[i], v.typer, preferredGVKs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
continue
|
continue
|
||||||
|
@ -18,9 +18,11 @@ package resource
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -180,3 +182,18 @@ func TestFlattenListVisitor(t *testing.T) {
|
|||||||
t.Fatal(spew.Sdump(test.Infos))
|
t.Fatal(spew.Sdump(test.Infos))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFlattenListVisitorWithVisitorError(t *testing.T) {
|
||||||
|
b := newDefaultBuilder().
|
||||||
|
FilenameParam(false, &FilenameOptions{Recursive: false, Filenames: []string{"../../artifacts/deeply-nested.yaml"}}).
|
||||||
|
Flatten()
|
||||||
|
|
||||||
|
test := &testVisitor{InjectErr: errors.New("visitor error")}
|
||||||
|
err := b.Do().Visit(test.Handle)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "visitor error") {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(test.Infos) != 6 {
|
||||||
|
t.Fatal(spew.Sdump(test.Infos))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user