From bb5fd55e21710f35d7ccd2dacbfd4f733c19c9e1 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Tue, 14 Apr 2015 17:17:13 -0700 Subject: [PATCH] Fix Err fallout for graph/iterator.HasA iterator --- graph/iterator/hasa_iterator.go | 8 ++++++++ graph/iterator/hasa_iterator_test.go | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 graph/iterator/hasa_iterator_test.go diff --git a/graph/iterator/hasa_iterator.go b/graph/iterator/hasa_iterator.go index adac2c8..879e031 100644 --- a/graph/iterator/hasa_iterator.go +++ b/graph/iterator/hasa_iterator.go @@ -51,6 +51,7 @@ type HasA struct { dir quad.Direction resultIt graph.Iterator result graph.Value + err error runstats graph.IteratorStats } @@ -202,6 +203,9 @@ func (it *HasA) Next() bool { it.resultIt = &Null{} if !graph.Next(it.primaryIt) { + if err := graph.Err(it.primaryIt); err != nil { + it.err = err + } return graph.NextLogOut(it, 0, false) } tID := it.primaryIt.Result() @@ -210,6 +214,10 @@ func (it *HasA) Next() bool { return graph.NextLogOut(it, val, true) } +func (it *HasA) Err() error { + return it.err +} + func (it *HasA) Result() graph.Value { return it.result } diff --git a/graph/iterator/hasa_iterator_test.go b/graph/iterator/hasa_iterator_test.go new file mode 100644 index 0000000..fbeb228 --- /dev/null +++ b/graph/iterator/hasa_iterator_test.go @@ -0,0 +1,37 @@ +// Copyright 2014 The Cayley Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package iterator + +import ( + "errors" + "testing" + + "github.com/google/cayley/quad" +) + +func TestHasAIteratorErr(t *testing.T) { + retErr := errors.New("unique") + errIt := newTestIterator(false, retErr) + + // TODO(andrew-d): pass a non-nil quadstore + hasa := NewHasA(nil, errIt, quad.Subject) + + if hasa.Next() != false { + t.Errorf("HasA iterator did not pass through initial 'false'") + } + if hasa.Err() != retErr { + t.Errorf("HasA iterator did not pass through underlying Err") + } +}