From 1ddc94c2e58a1ce8b9ba329c0b8f450421c40651 Mon Sep 17 00:00:00 2001 From: panamafrancis Date: Thu, 18 Dec 2014 11:39:32 +0000 Subject: [PATCH] Fixed crash in iterator Clone(), added test --- graph/gaedatastore/iterator.go | 5 ++++- graph/gaedatastore/quadstore_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/graph/gaedatastore/iterator.go b/graph/gaedatastore/iterator.go index 1586be8..29900fd 100644 --- a/graph/gaedatastore/iterator.go +++ b/graph/gaedatastore/iterator.go @@ -190,7 +190,10 @@ func (it *Iterator) Clone() graph.Iterator { m.tags.CopyFrom(it) return m } - m := NewIterator(it.qs, it.kind, it.dir, it.hash) + + // Create a token, the tokens kind is ignored in creation of the iterator + t := &Token{nodeKind, it.hash} + m := NewIterator(it.qs, it.kind, it.dir, t) m.tags.CopyFrom(it) return m } diff --git a/graph/gaedatastore/quadstore_test.go b/graph/gaedatastore/quadstore_test.go index b32f6a2..ae3d6be 100644 --- a/graph/gaedatastore/quadstore_test.go +++ b/graph/gaedatastore/quadstore_test.go @@ -254,6 +254,16 @@ func TestIterators(t *testing.T) { if !it.Contains(token) { t.Error("Contains failed") } + + // Test cloning an iterator + var it2 graph.Iterator + it2 = it.Clone() + x := it2.Describe() + y := it.Describe() + + if x.Name != y.Name { + t.Errorf("Iterator Clone was not successful got: %v, expected: %v", x.Name, y.Name) + } } func TestIteratorsAndNextResultOrderA(t *testing.T) {