提交 19ca1a81 作者: Łukasz Magiera 提交者: Steven Allen

Unixfs.Add nocopy test

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 649fd1f4
...@@ -101,6 +101,34 @@ func (tp *provider) TestAdd(t *testing.T) { ...@@ -101,6 +101,34 @@ func (tp *provider) TestAdd(t *testing.T) {
return coreiface.IpfsPath(c) return coreiface.IpfsPath(c)
} }
rf, err := ioutil.TempFile(os.TempDir(), "unixfs-add-real")
if err != nil {
t.Fatal(err)
}
rfp := rf.Name()
if _, err := rf.Write([]byte(helloStr)); err != nil {
t.Fatal(err)
}
stat, err := rf.Stat()
if err != nil {
t.Fatal(err)
}
if err := rf.Close(); err != nil {
t.Fatal(err)
}
defer os.Remove(rfp)
realFile := func() files.Node {
n, err := files.NewReaderPathFile(rfp, ioutil.NopCloser(strings.NewReader(helloStr)), stat)
if err != nil {
t.Fatal(err)
}
return n
}
cases := []struct { cases := []struct {
name string name string
data func() files.Node data func() files.Node
...@@ -323,6 +351,20 @@ func (tp *provider) TestAdd(t *testing.T) { ...@@ -323,6 +351,20 @@ func (tp *provider) TestAdd(t *testing.T) {
path: "/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp", path: "/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp",
opts: []options.UnixfsAddOption{options.Unixfs.Hidden(false)}, opts: []options.UnixfsAddOption{options.Unixfs.Hidden(false)},
}, },
// NoCopy
{
name: "simpleNoCopy",
data: realFile,
path: "/ipfs/zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd",
opts: []options.UnixfsAddOption{options.Unixfs.Nocopy(true)},
},
{
name: "noCopyNoRaw",
data: realFile,
path: "/ipfs/zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd",
opts: []options.UnixfsAddOption{options.Unixfs.Nocopy(true), options.Unixfs.RawLeaves(false)},
err: "nocopy option requires '--raw-leaves' to be enabled as well",
},
// Events / Progress // Events / Progress
{ {
name: "simpleAddEvent", name: "simpleAddEvent",
......
...@@ -4,9 +4,13 @@ import ( ...@@ -4,9 +4,13 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"github.com/ipfs/go-ipfs/core/coreapi/interface/tests" "os"
"path/filepath"
"testing" "testing"
"github.com/ipfs/go-ipfs/core/coreapi/interface/tests"
"github.com/ipfs/go-ipfs/filestore"
"github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi" "github.com/ipfs/go-ipfs/core/coreapi"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface" coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
...@@ -64,11 +68,14 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ...@@ -64,11 +68,14 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
c := config.Config{} c := config.Config{}
c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)} c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
c.Identity = ident c.Identity = ident
c.Experimental.FilestoreEnabled = true
ds := datastore.NewMapDatastore()
r := &repo.Mock{ r := &repo.Mock{
C: c, C: c,
D: syncds.MutexWrap(datastore.NewMapDatastore()), D: syncds.MutexWrap(ds),
K: keystore.NewMemKeystore(), K: keystore.NewMemKeystore(),
F: filestore.NewFileManager(ds, filepath.Dir(os.TempDir())),
} }
node, err := core.NewNode(ctx, &core.BuildCfg{ node, err := core.NewNode(ctx, &core.BuildCfg{
......
...@@ -17,6 +17,7 @@ type Mock struct { ...@@ -17,6 +17,7 @@ type Mock struct {
C config.Config C config.Config
D Datastore D Datastore
K keystore.Keystore K keystore.Keystore
F *filestore.FileManager
} }
func (m *Mock) Config() (*config.Config, error) { func (m *Mock) Config() (*config.Config, error) {
...@@ -54,4 +55,4 @@ func (m *Mock) SwarmKey() ([]byte, error) { ...@@ -54,4 +55,4 @@ func (m *Mock) SwarmKey() ([]byte, error) {
return nil, nil return nil, nil
} }
func (m *Mock) FileManager() *filestore.FileManager { return nil } func (m *Mock) FileManager() *filestore.FileManager { return m.F }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论