From 0f376b571814e1e14e4e41469a0253cbfcb39dcc Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 28 Mar 2018 14:11:51 -0700 Subject: [PATCH] test duplicate CIDs in getMany License: MIT Signed-off-by: Steven Allen --- merkledag/merkledag_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/merkledag/merkledag_test.go b/merkledag/merkledag_test.go index d67a20aa7..48fe8e8a9 100644 --- a/merkledag/merkledag_test.go +++ b/merkledag/merkledag_test.go @@ -550,6 +550,36 @@ func TestCidRawDoesnNeedData(t *testing.T) { } } +func TestGetManyDuplicate(t *testing.T) { + ctx := context.Background() + + srv := NewDAGService(dstest.Bserv()) + + nd := NodeWithData([]byte("foo")) + if err := srv.Add(ctx, nd); err != nil { + t.Fatal(err) + } + nds := srv.GetMany(ctx, []*cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()}) + out, ok := <-nds + if !ok { + t.Fatal("expecting node foo") + } + if out.Err != nil { + t.Fatal(out.Err) + } + if !out.Node.Cid().Equals(nd.Cid()) { + t.Fatal("got wrong node") + } + out, ok = <-nds + if ok { + if out.Err != nil { + t.Fatal(out.Err) + } else { + t.Fatal("expecting no more nodes") + } + } +} + func TestEnumerateAsyncFailsNotFound(t *testing.T) { ctx := context.Background()