coreapi: use chan for returning results in Unixfs.Ls

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>


This commit was moved from ipfs/interface-go-ipfs-core@93175e9900

This commit was moved from ipfs/boxo@3afaf889d4
This commit is contained in:
Łukasz Magiera 2019-02-01 19:48:43 +01:00
parent 8f0b53d1f7
commit aeb9cdfae0
2 changed files with 11 additions and 9 deletions

View File

@ -754,18 +754,20 @@ func (tp *provider) TestLs(t *testing.T) {
t.Error(err)
}
if len(links) != 1 {
t.Fatalf("expected 1 link, got %d", len(links))
link := <- links
if link.Size != 23 {
t.Fatalf("expected size = 23, got %d", link.Size)
}
if links[0].Size != 23 {
t.Fatalf("expected size = 23, got %d", links[0].Size)
if link.Name != "name-of-file" {
t.Fatalf("expected name = name-of-file, got %s", link.Name)
}
if links[0].Name != "name-of-file" {
t.Fatalf("expected name = name-of-file, got %s", links[0].Name)
if link.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", link.Cid)
}
if links[0].Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", links[0].Cid)
if _, ok := <-links; ok {
t.Errorf("didn't expect a second link")
}
}
func (tp *provider) TestEntriesExpired(t *testing.T) {

View File

@ -31,5 +31,5 @@ type UnixfsAPI interface {
Get(context.Context, Path) (files.Node, error)
// Ls returns the list of links in a directory
Ls(context.Context, Path) ([]*ipld.Link, error)
Ls(context.Context, Path) (<-chan *ipld.Link, error)
}