| 605 | } |
| 606 | |
| 607 | func TestErrors(t *testing.T) { |
| 608 | t.Parallel() |
| 609 | ctx := context.Background() |
| 610 | |
| 611 | err1 := errors.New("error1") |
| 612 | err2 := errors.New("error2") |
| 613 | |
| 614 | for _, tc := range []struct { |
| 615 | name string |
| 616 | stages []pipe.Stage |
| 617 | expectedErr error |
| 618 | }{ |
| 619 | { |
| 620 | name: "no-error", |
| 621 | stages: []pipe.Stage{ |
| 622 | pipe.Function("noop1", genErr(nil)), |
| 623 | pipe.Function("noop2", genErr(nil)), |
| 624 | pipe.Function("noop3", genErr(nil)), |
| 625 | }, |
| 626 | expectedErr: nil, |
| 627 | }, |
| 628 | { |
| 629 | name: "lonely-error", |
| 630 | stages: []pipe.Stage{ |
| 631 | pipe.Function("err1", genErr(err1)), |
| 632 | }, |
| 633 | expectedErr: err1, |
| 634 | }, |
| 635 | { |
| 636 | name: "error", |
| 637 | stages: []pipe.Stage{ |
| 638 | pipe.Function("noop1", genErr(nil)), |
| 639 | pipe.Function("err1", genErr(err1)), |
| 640 | pipe.Function("noop2", genErr(nil)), |
| 641 | }, |
| 642 | expectedErr: err1, |
| 643 | }, |
| 644 | { |
| 645 | name: "two-consecutive-errors", |
| 646 | stages: []pipe.Stage{ |
| 647 | pipe.Function("noop1", genErr(nil)), |
| 648 | pipe.Function("err1", genErr(err1)), |
| 649 | pipe.Function("err2", genErr(err2)), |
| 650 | pipe.Function("noop2", genErr(nil)), |
| 651 | }, |
| 652 | expectedErr: err1, |
| 653 | }, |
| 654 | { |
| 655 | name: "pipe-then-error", |
| 656 | stages: []pipe.Stage{ |
| 657 | pipe.Function("noop1", genErr(nil)), |
| 658 | pipe.Function("pipe-error", genErr(io.ErrClosedPipe)), |
| 659 | pipe.Function("err1", genErr(err1)), |
| 660 | pipe.Function("noop2", genErr(nil)), |
| 661 | }, |
| 662 | expectedErr: err1, |
| 663 | }, |
| 664 | { |