tests: add symlink target test
(also, fix some error versus fatal nits) This commit was moved from ipfs/interface-go-ipfs-core@5c6a751986f6d5fe1174819442fcd5f60e0a6f7d This commit was moved from ipfs/boxo@4be6e60dbea5e9dd8cf37d1f7a5b038e2a18dbf7
Steven Allen committed
Mar 5, 2019 at 09:37 UTC
cc2b187d07091d649f29f129bcd57078cbec9aba
1 file changed
+28
-7
core/coreiface/tests/unixfs.go
+28
-7
@@ -737,22 +737,23 @@ func (tp *provider) TestLs(t *testing.T) {
737
defer cancel()
738
api, err := tp.makeAPI(ctx)
739
if err != nil {
740
- t.Error(err)
740
+ t.Fatal(err)
741
}
742
743
r := strings.NewReader("content-of-file")
744
p, err := api.Unixfs().Add(ctx, files.NewMapDirectory(map[string]files.Node{
745
"0": files.NewMapDirectory(map[string]files.Node{
746
- "name-of-file": files.NewReaderFile(r),
746
+ "name-of-file": files.NewReaderFile(r),
747
+ "name-of-symlink": files.NewLinkFile("/foo/bar", nil),
748
}),
749
}))
750
if err != nil {
750
- t.Error(err)
751
+ t.Fatal(err)
752
}
753
754
entries, err := api.Unixfs().Ls(ctx, p)
755
if err != nil {
755
- t.Error(err)
756
+ t.Fatal(err)
757
}
758
759
entry := <-entries
@@ -760,13 +761,33 @@ func (tp *provider) TestLs(t *testing.T) {
761
t.Fatal(entry.Err)
762
}
763
if entry.Size != 15 {
763
- t.Fatalf("expected size = 15, got %d", entry.Size)
764
+ t.Errorf("expected size = 15, got %d", entry.Size)
765
}
766
if entry.Name != "name-of-file" {
766
- t.Fatalf("expected name = name-of-file, got %s", entry.Name)
767
+ t.Errorf("expected name = name-of-file, got %s", entry.Name)
768
+ }
769
+ if entry.Type != coreiface.TFile {
770
+ t.Errorf("wrong type %s", entry.Type)
771
}
772
if entry.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
769
- t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", entry.Cid)
773
+ t.Errorf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", entry.Cid)
774
+ }
775
+ entry = <-entries
776
+ if entry.Err != nil {
777
+ t.Fatal(entry.Err)
778
+ }
779
+ if entry.Type != coreiface.TSymlink {
780
+ t.Errorf("wrong type %s", entry.Type)
781
+ }
782
+ if entry.Name != "name-of-symlink" {
783
+ t.Errorf("expected name = name-of-symlink, got %s", entry.Name)
784
+ }
785
+ if entry.Target.String() != "/foo/bar" {
786
+ t.Errorf("expected symlink target to be /foo/bar, got %s", entry.Target)
787
+ }
788
+
789
+ if int(entry.Size) != len(entry.Target.String()) {
790
+ t.Errorf("expected size = %d, got %d", len(entry.Target.String()), entry.Size)
791
}
792
if l, ok := <-entries; ok {
793
t.Errorf("didn't expect a second link")