Fix Err fallout for graph/iterator.And iterator

This commit is contained in:
Andrew Dunham 2015-04-14 17:07:25 -07:00
parent c156fd6b1b
commit 742277e72e
2 changed files with 25 additions and 1 deletions

View file

@ -29,6 +29,7 @@ type And struct {
primaryIt graph.Iterator
checkList []graph.Iterator
result graph.Value
err error
runstats graph.IteratorStats
}
@ -153,9 +154,16 @@ func (it *And) Next() bool {
return graph.NextLogOut(it, curr, true)
}
}
if err := graph.Err(it.primaryIt); err != nil {
it.err = err
}
return graph.NextLogOut(it, nil, false)
}
func (it *And) Err() error {
return it.err
}
func (it *And) Result() graph.Value {
return it.result
}

View file

@ -15,6 +15,7 @@
package iterator
import (
"errors"
"testing"
"github.com/google/cayley/graph"
@ -138,5 +139,20 @@ func TestAllIterators(t *testing.T) {
if and.Next() {
t.Error("Too many values")
}
}
func TestAndIteratorErr(t *testing.T) {
retErr := errors.New("unique")
allErr := newTestIterator(false, retErr)
and := NewAnd()
and.AddSubIterator(allErr)
and.AddSubIterator(NewInt64(1, 5))
if and.Next() != false {
t.Errorf("And iterator did not pass through initial 'false'")
}
if and.Err() != retErr {
t.Errorf("And iterator did not pass through underlying Err")
}
}