@cryptotaxi247 / kubo / commits / 48d537bab

coreapi: fix seek test on http impl

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

Łukasz Magiera committed Feb 5, 2019 at 20:20 UTC 48d537babe200d611051a0a3ff208007324e84fa
1 file changed +18 -7
core/coreapi/interface/tests/unixfs.go
+18 -7
@@ -3,6 +3,7 @@ package tests
3 import (
4 "bytes"
5 "context"
6 + "encoding/hex"
7 "fmt"
8 "io"
9 "io/ioutil"
@@ -754,9 +755,13 @@ func (tp *provider) TestLs(t *testing.T) {
755 t.Error(err)
756 }
757
757 - link := (<-links).Link
758 - if link.Size != 23 {
759 - t.Fatalf("expected size = 23, got %d", link.Size)
758 + linkRes := <-links
759 + if linkRes.Err != nil {
760 + t.Fatal(linkRes.Err)
761 + }
762 + link := linkRes.Link
763 + if linkRes.Size != 15 {
764 + t.Fatalf("expected size = 15, got %d", link.Size)
765 }
766 if link.Name != "name-of-file" {
767 t.Fatalf("expected name = name-of-file, got %s", link.Name)
@@ -764,8 +769,11 @@ func (tp *provider) TestLs(t *testing.T) {
769 if link.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
770 t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", link.Cid)
771 }
767 - if _, ok := <-links; ok {
772 + if l, ok := <-links; ok {
773 t.Errorf("didn't expect a second link")
774 + if l.Err != nil {
775 + t.Error(l.Err)
776 + }
777 }
778 }
779
@@ -967,7 +975,7 @@ func (tp *provider) TestGetSeek(t *testing.T) {
975 }
976
977 orig := make([]byte, dataSize)
970 - if _, err := f.Read(orig); err != nil {
978 + if _, err := io.ReadFull(f, orig); err != nil {
979 t.Fatal(err)
980 }
981 f.Close()
@@ -1005,9 +1013,9 @@ func (tp *provider) TestGetSeek(t *testing.T) {
1013 if err != nil {
1014 t.Fatalf("orig: %s", err)
1015 }
1008 - r, err := f.Read(buf)
1016 + r, err := io.ReadFull(f, buf)
1017 switch {
1010 - case shouldEof && err != nil && err != io.EOF:
1018 + case shouldEof && err != nil && err != io.ErrUnexpectedEOF:
1019 fallthrough
1020 case !shouldEof && err != nil:
1021 t.Fatalf("f: %s", err)
@@ -1029,6 +1037,8 @@ func (tp *provider) TestGetSeek(t *testing.T) {
1037 t.Fatal("read different amount of data than bytes.Reader")
1038 }
1039 if !bytes.Equal(buf, origBuf) {
1040 + fmt.Fprintf(os.Stderr, "original:\n%s\n", hex.Dump(origBuf))
1041 + fmt.Fprintf(os.Stderr, "got:\n%s\n", hex.Dump(buf))
1042 t.Fatal("data didn't match")
1043 }
1044 })
@@ -1039,6 +1049,7 @@ func (tp *provider) TestGetSeek(t *testing.T) {
1049 test(500, io.SeekCurrent, 10, 10, false)
1050 test(350, io.SeekStart, 100, 100, false)
1051 test(-123, io.SeekCurrent, 100, 100, false)
1052 + test(0, io.SeekStart, int(dataSize), dataSize, false)
1053 test(dataSize-50, io.SeekStart, 100, 50, true)
1054 test(-5, io.SeekEnd, 100, 5, true)
1055 }