mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00
files2.0: fix AddPosInfo test
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -176,7 +177,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
bs := &testBlockstore{GCBlockstore: node.Blockstore, expectedPath: "/tmp/foo.txt", t: t}
|
bs := &testBlockstore{GCBlockstore: node.Blockstore, expectedPath: filepath.Join(os.TempDir(), "foo.txt"), t: t}
|
||||||
bserv := blockservice.New(bs, node.Exchange)
|
bserv := blockservice.New(bs, node.Exchange)
|
||||||
dserv := dag.NewDAGService(bserv)
|
dserv := dag.NewDAGService(bserv)
|
||||||
adder, err := NewAdder(context.Background(), node.Pinning, bs, dserv)
|
adder, err := NewAdder(context.Background(), node.Pinning, bs, dserv)
|
||||||
@ -193,7 +194,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
|
|||||||
rand.New(rand.NewSource(2)).Read(data) // Rand.Read never returns an error
|
rand.New(rand.NewSource(2)).Read(data) // Rand.Read never returns an error
|
||||||
fileData := ioutil.NopCloser(bytes.NewBuffer(data))
|
fileData := ioutil.NopCloser(bytes.NewBuffer(data))
|
||||||
fileInfo := dummyFileInfo{"foo.txt", int64(len(data)), time.Now()}
|
fileInfo := dummyFileInfo{"foo.txt", int64(len(data)), time.Now()}
|
||||||
file := files.NewReaderFile(fileData, &fileInfo)
|
file, _ := files.NewReaderPathFile(filepath.Join(os.TempDir(), "foo.txt"), fileData, &fileInfo)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(adder.Out)
|
defer close(adder.Out)
|
||||||
@ -212,7 +213,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
|
|||||||
nonOffZero = 19
|
nonOffZero = 19
|
||||||
}
|
}
|
||||||
if bs.countAtOffsetZero != exp {
|
if bs.countAtOffsetZero != exp {
|
||||||
t.Fatalf("expected %d blocks with an offset at zero (one root and one leafh), got %d", exp, bs.countAtOffsetZero)
|
t.Fatalf("expected %d blocks with an offset at zero (one root and one leaf), got %d", exp, bs.countAtOffsetZero)
|
||||||
}
|
}
|
||||||
if bs.countAtOffsetNonZero != nonOffZero {
|
if bs.countAtOffsetNonZero != nonOffZero {
|
||||||
// note: the exact number will depend on the size and the sharding algo. used
|
// note: the exact number will depend on the size and the sharding algo. used
|
||||||
|
Reference in New Issue
Block a user