@cryptotaxi247 / kubo / commits / 19ca1a819

Unixfs.Add nocopy test

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

Łukasz Magiera committed Jan 14, 2019 at 21:01 UTC 19ca1a819f9744a67a2e9be59ab5fd31511ef1d2
3 files changed +53 -3
core/coreapi/interface/tests/unixfs.go
+42
@@ -101,6 +101,34 @@ func (tp *provider) TestAdd(t *testing.T) {
101 return coreiface.IpfsPath(c)
102 }
103
104 + rf, err := ioutil.TempFile(os.TempDir(), "unixfs-add-real")
105 + if err != nil {
106 + t.Fatal(err)
107 + }
108 + rfp := rf.Name()
109 +
110 + if _, err := rf.Write([]byte(helloStr)); err != nil {
111 + t.Fatal(err)
112 + }
113 +
114 + stat, err := rf.Stat()
115 + if err != nil {
116 + t.Fatal(err)
117 + }
118 +
119 + if err := rf.Close(); err != nil {
120 + t.Fatal(err)
121 + }
122 + defer os.Remove(rfp)
123 +
124 + realFile := func() files.Node {
125 + n, err := files.NewReaderPathFile(rfp, ioutil.NopCloser(strings.NewReader(helloStr)), stat)
126 + if err != nil {
127 + t.Fatal(err)
128 + }
129 + return n
130 + }
131 +
132 cases := []struct {
133 name string
134 data func() files.Node
@@ -323,6 +351,20 @@ func (tp *provider) TestAdd(t *testing.T) {
351 path: "/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp",
352 opts: []options.UnixfsAddOption{options.Unixfs.Hidden(false)},
353 },
354 + // NoCopy
355 + {
356 + name: "simpleNoCopy",
357 + data: realFile,
358 + path: "/ipfs/zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd",
359 + opts: []options.UnixfsAddOption{options.Unixfs.Nocopy(true)},
360 + },
361 + {
362 + name: "noCopyNoRaw",
363 + data: realFile,
364 + path: "/ipfs/zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd",
365 + opts: []options.UnixfsAddOption{options.Unixfs.Nocopy(true), options.Unixfs.RawLeaves(false)},
366 + err: "nocopy option requires '--raw-leaves' to be enabled as well",
367 + },
368 // Events / Progress
369 {
370 name: "simpleAddEvent",
core/coreapi/test/api_test.go
+9 -2
@@ -4,9 +4,13 @@ import (
4 "context"
5 "encoding/base64"
6 "fmt"
7 - "github.com/ipfs/go-ipfs/core/coreapi/interface/tests"
7 + "os"
8 + "path/filepath"
9 "testing"
10
11 + "github.com/ipfs/go-ipfs/core/coreapi/interface/tests"
12 + "github.com/ipfs/go-ipfs/filestore"
13 +
14 "github.com/ipfs/go-ipfs/core"
15 "github.com/ipfs/go-ipfs/core/coreapi"
16 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
@@ -64,11 +68,14 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
68 c := config.Config{}
69 c.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.%d.1/tcp/4001", i)}
70 c.Identity = ident
71 + c.Experimental.FilestoreEnabled = true
72
73 + ds := datastore.NewMapDatastore()
74 r := &repo.Mock{
75 C: c,
70 - D: syncds.MutexWrap(datastore.NewMapDatastore()),
76 + D: syncds.MutexWrap(ds),
77 K: keystore.NewMemKeystore(),
78 + F: filestore.NewFileManager(ds, filepath.Dir(os.TempDir())),
79 }
80
81 node, err := core.NewNode(ctx, &core.BuildCfg{
repo/mock.go
+2 -1
@@ -17,6 +17,7 @@ type Mock struct {
17 C config.Config
18 D Datastore
19 K keystore.Keystore
20 + F *filestore.FileManager
21 }
22
23 func (m *Mock) Config() (*config.Config, error) {
@@ -54,4 +55,4 @@ func (m *Mock) SwarmKey() ([]byte, error) {
55 return nil, nil
56 }
57
57 -func (m *Mock) FileManager() *filestore.FileManager { return nil }
58 +func (m *Mock) FileManager() *filestore.FileManager { return m.F }