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@93175e9900f58425d3868381c3a8668500ac39a9 This commit was moved from ipfs/boxo@3afaf889d4d49000482655a90591acdd3eb16349
Łukasz Magiera committed
Feb 1, 2019 at 19:48 UTC
aeb9cdfae0878d4954ecc2cdc570168449887463
2 files changed
+11
-9
core/coreiface/tests/unixfs.go
+10
-8
@@ -754,18 +754,20 @@ func (tp *provider) TestLs(t *testing.T) {
754
t.Error(err)
755
}
756
757
- if len(links) != 1 {
758
- t.Fatalf("expected 1 link, got %d", len(links))
757
+ link := <- links
758
+ if link.Size != 23 {
759
+ t.Fatalf("expected size = 23, got %d", link.Size)
760
}
760
- if links[0].Size != 23 {
761
- t.Fatalf("expected size = 23, got %d", links[0].Size)
761
+ if link.Name != "name-of-file" {
762
+ t.Fatalf("expected name = name-of-file, got %s", link.Name)
763
}
763
- if links[0].Name != "name-of-file" {
764
- t.Fatalf("expected name = name-of-file, got %s", links[0].Name)
764
+ if link.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
765
+ t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", link.Cid)
766
}
766
- if links[0].Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
767
- t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", links[0].Cid)
767
+ if _, ok := <-links; ok {
768
+ t.Errorf("didn't expect a second link")
769
}
770
+
771
}
772
773
func (tp *provider) TestEntriesExpired(t *testing.T) {
core/coreiface/unixfs.go
+1
-1
@@ -31,5 +31,5 @@ type UnixfsAPI interface {
31
Get(context.Context, Path) (files.Node, error)
32
33
// Ls returns the list of links in a directory
34
- Ls(context.Context, Path) ([]*ipld.Link, error)
34
+ Ls(context.Context, Path) (<-chan *ipld.Link, error)
35
}