mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
Make a change to visitor to allow it to accept an error, like Go's path walker
This commit is contained in:
@@ -162,7 +162,10 @@ type testVisitor struct {
|
||||
Infos []*Info
|
||||
}
|
||||
|
||||
func (v *testVisitor) Handle(info *Info) error {
|
||||
func (v *testVisitor) Handle(info *Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Infos = append(v.Infos, info)
|
||||
return v.InjectErr
|
||||
}
|
||||
@@ -649,7 +652,7 @@ func TestContinueOnErrorVisitor(t *testing.T) {
|
||||
Do()
|
||||
count := 0
|
||||
testErr := fmt.Errorf("test error")
|
||||
err := req.Visit(func(_ *Info) error {
|
||||
err := req.Visit(func(_ *Info, _ error) error {
|
||||
count++
|
||||
if count > 1 {
|
||||
return testErr
|
||||
@@ -872,40 +875,6 @@ func TestLatest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoreStreamErrors(t *testing.T) {
|
||||
pods, svc := testData()
|
||||
|
||||
r, w := io.Pipe()
|
||||
go func() {
|
||||
defer w.Close()
|
||||
w.Write([]byte(`{}`))
|
||||
w.Write([]byte(runtime.EncodeOrDie(latest.Codec, &pods.Items[0])))
|
||||
}()
|
||||
|
||||
r2, w2 := io.Pipe()
|
||||
go func() {
|
||||
defer w2.Close()
|
||||
w2.Write([]byte(`{}`))
|
||||
w2.Write([]byte(runtime.EncodeOrDie(latest.Codec, &svc.Items[0])))
|
||||
}()
|
||||
|
||||
b := NewBuilder(latest.RESTMapper, api.Scheme, fakeClient()).
|
||||
ContinueOnError(). // TODO: order seems bad, but allows clients to determine what they want...
|
||||
Stream(r, "1").Stream(r2, "2")
|
||||
|
||||
test := &testVisitor{}
|
||||
singular := false
|
||||
|
||||
err := b.Do().IntoSingular(&singular).Visit(test.Handle)
|
||||
if err != nil || singular || len(test.Infos) != 2 {
|
||||
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
|
||||
}
|
||||
|
||||
if !api.Semantic.DeepDerivative([]runtime.Object{&pods.Items[0], &svc.Items[0]}, test.Objects()) {
|
||||
t.Errorf("unexpected visited objects: %#v", test.Objects())
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiveMultipleErrors(t *testing.T) {
|
||||
pods, svc := testData()
|
||||
|
||||
@@ -931,7 +900,7 @@ func TestReceiveMultipleErrors(t *testing.T) {
|
||||
singular := false
|
||||
|
||||
err := b.Do().IntoSingular(&singular).Visit(test.Handle)
|
||||
if err == nil || singular || len(test.Infos) != 0 {
|
||||
if err == nil || singular || len(test.Infos) != 2 {
|
||||
t.Fatalf("unexpected response: %v %t %#v", err, singular, test.Infos)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user