From 3a34ab97f6a382f1b28c3cfb49b3725c60b33956 Mon Sep 17 00:00:00 2001 From: Antonio Jesus Navarro Perez Date: Thu, 23 Feb 2017 11:54:13 +0100 Subject: plumbing/storer: referenceIterator now returns the error if any --- plumbing/storer/reference.go | 2 +- plumbing/storer/reference_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plumbing/storer/reference.go b/plumbing/storer/reference.go index 692fe88..6c2de0d 100644 --- a/plumbing/storer/reference.go +++ b/plumbing/storer/reference.go @@ -70,7 +70,7 @@ func (iter *ReferenceSliceIter) ForEach(cb func(*plumbing.Reference) error) erro return nil } - return nil + return err } } diff --git a/plumbing/storer/reference_test.go b/plumbing/storer/reference_test.go index f698820..ff7bd68 100644 --- a/plumbing/storer/reference_test.go +++ b/plumbing/storer/reference_test.go @@ -1,6 +1,7 @@ package storer import ( + "errors" "io" . "gopkg.in/check.v1" @@ -48,6 +49,29 @@ func (s *ReferenceSuite) TestReferenceSliceIterForEach(c *C) { c.Assert(count, Equals, 2) } +func (s *ReferenceSuite) TestReferenceSliceIterForEachError(c *C) { + slice := []*plumbing.Reference{ + plumbing.NewReferenceFromStrings("foo", "foo"), + plumbing.NewReferenceFromStrings("bar", "bar"), + } + + i := NewReferenceSliceIter(slice) + var count int + exampleErr := errors.New("SOME ERROR") + err := i.ForEach(func(r *plumbing.Reference) error { + c.Assert(r == slice[count], Equals, true) + count++ + if count == 2 { + return exampleErr + } + + return nil + }) + + c.Assert(err, Equals, exampleErr) + c.Assert(count, Equals, 2) +} + func (s *ReferenceSuite) TestReferenceSliceIterForEachStop(c *C) { slice := []*plumbing.Reference{ plumbing.NewReferenceFromStrings("foo", "foo"), -- cgit