Unixfs.Add nocopy test

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera 2019-01-14 21:01:39 +01:00 committed by Steven Allen
parent 649fd1f4d6
commit 19ca1a819f
3 changed files with 53 additions and 3 deletions

View File

@ -101,6 +101,34 @@ func (tp *provider) TestAdd(t *testing.T) {
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 {
name string
data func() files.Node
@ -323,6 +351,20 @@ func (tp *provider) TestAdd(t *testing.T) {
path: "/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp",
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
{
name: "simpleAddEvent",

View File

@ -4,9 +4,13 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/ipfs/go-ipfs/core/coreapi/interface/tests"
"os"
"path/filepath"
"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/coreapi"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
@ -64,11 +68,14 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
c := config.Config{}
c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
c.Identity = ident
c.Experimental.FilestoreEnabled = true
ds := datastore.NewMapDatastore()
r := &repo.Mock{
C: c,
D: syncds.MutexWrap(datastore.NewMapDatastore()),
D: syncds.MutexWrap(ds),
K: keystore.NewMemKeystore(),
F: filestore.NewFileManager(ds, filepath.Dir(os.TempDir())),
}
node, err := core.NewNode(ctx, &core.BuildCfg{

View File

@ -17,6 +17,7 @@ type Mock struct {
C config.Config
D Datastore
K keystore.Keystore
F *filestore.FileManager
}
func (m *Mock) Config() (*config.Config, error) {
@ -54,4 +55,4 @@ func (m *Mock) SwarmKey() ([]byte, error) {
return nil, nil
}
func (m *Mock) FileManager() *filestore.FileManager { return nil }
func (m *Mock) FileManager() *filestore.FileManager { return m.F }