Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreapi: fix seek test on http impl #5971

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions core/coreapi/interface/tests/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"bytes"
"context"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -754,18 +755,25 @@ func (tp *provider) TestLs(t *testing.T) {
t.Error(err)
}

link := (<-links).Link
if link.Size != 23 {
t.Fatalf("expected size = 23, got %d", link.Size)
linkRes := <-links
if linkRes.Err != nil {
t.Fatal(linkRes.Err)
}
link := linkRes.Link
if linkRes.Size != 15 {
t.Fatalf("expected size = 15, got %d", link.Size)
}
if link.Name != "name-of-file" {
t.Fatalf("expected name = name-of-file, got %s", link.Name)
}
if link.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", link.Cid)
}
if _, ok := <-links; ok {
if l, ok := <-links; ok {
t.Errorf("didn't expect a second link")
if l.Err != nil {
t.Error(l.Err)
}
}
}

Expand Down Expand Up @@ -967,7 +975,7 @@ func (tp *provider) TestGetSeek(t *testing.T) {
}

orig := make([]byte, dataSize)
if _, err := f.Read(orig); err != nil {
if _, err := io.ReadFull(f, orig); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need this because http reader reads data in 4k chunks

t.Fatal(err)
}
f.Close()
Expand Down Expand Up @@ -1005,9 +1013,9 @@ func (tp *provider) TestGetSeek(t *testing.T) {
if err != nil {
t.Fatalf("orig: %s", err)
}
r, err := f.Read(buf)
r, err := io.ReadFull(f, buf)
switch {
case shouldEof && err != nil && err != io.EOF:
case shouldEof && err != nil && err != io.ErrUnexpectedEOF:
fallthrough
case !shouldEof && err != nil:
t.Fatalf("f: %s", err)
Expand All @@ -1029,6 +1037,8 @@ func (tp *provider) TestGetSeek(t *testing.T) {
t.Fatal("read different amount of data than bytes.Reader")
}
if !bytes.Equal(buf, origBuf) {
fmt.Fprintf(os.Stderr, "original:\n%s\n", hex.Dump(origBuf))
fmt.Fprintf(os.Stderr, "got:\n%s\n", hex.Dump(buf))
t.Fatal("data didn't match")
}
})
Expand All @@ -1039,6 +1049,7 @@ func (tp *provider) TestGetSeek(t *testing.T) {
test(500, io.SeekCurrent, 10, 10, false)
test(350, io.SeekStart, 100, 100, false)
test(-123, io.SeekCurrent, 100, 100, false)
test(0, io.SeekStart, int(dataSize), dataSize, false)
test(dataSize-50, io.SeekStart, 100, 50, true)
test(-5, io.SeekEnd, 100, 5, true)
}