提交 a96b370e 作者: Łukasz Magiera

files2.0: Fix coreapi.unixfs.Add tests

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 ce952a56
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"math" "math"
"os"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
...@@ -297,10 +298,19 @@ func TestAdd(t *testing.T) { ...@@ -297,10 +298,19 @@ func TestAdd(t *testing.T) {
data: func() files.File { data: func() files.File {
return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil) return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)
}, },
wrap: "foo",
expect: wrapped("foo"), expect: wrapped("foo"),
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)}, opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
}, },
{ {
name: "addNotWrappedDirFile",
path: hello,
data: func() files.File {
return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)
},
wrap: "foo",
},
{
name: "stdinWrapped", name: "stdinWrapped",
path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU", path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU",
data: func() files.File { data: func() files.File {
...@@ -317,7 +327,12 @@ func TestAdd(t *testing.T) { ...@@ -317,7 +327,12 @@ func TestAdd(t *testing.T) {
name: "stdinNamed", name: "stdinNamed",
path: "/ipfs/QmQ6cGBmb3ZbdrQW1MRm1RJnYnaxCqfssz7CrTa9NEhQyS", path: "/ipfs/QmQ6cGBmb3ZbdrQW1MRm1RJnYnaxCqfssz7CrTa9NEhQyS",
data: func() files.File { data: func() files.File {
return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil) rf, err := files.NewReaderPathFile(os.Stdin.Name(), ioutil.NopCloser(strings.NewReader(helloStr)), nil)
if err != nil {
panic(err)
}
return rf
}, },
expect: func(files.File) files.File { expect: func(files.File) files.File {
return files.NewSliceFile([]files.FileEntry{ return files.NewSliceFile([]files.FileEntry{
...@@ -330,7 +345,7 @@ func TestAdd(t *testing.T) { ...@@ -330,7 +345,7 @@ func TestAdd(t *testing.T) {
name: "twoLevelDirWrapped", name: "twoLevelDirWrapped",
data: twoLevelDir(), data: twoLevelDir(),
wrap: "t", wrap: "t",
expect: wrapped(""), expect: wrapped("t"),
path: "/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg", path: "/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg",
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)}, opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
}, },
...@@ -338,7 +353,7 @@ func TestAdd(t *testing.T) { ...@@ -338,7 +353,7 @@ func TestAdd(t *testing.T) {
name: "twoLevelInlineHash", name: "twoLevelInlineHash",
data: twoLevelDir(), data: twoLevelDir(),
wrap: "t", wrap: "t",
expect: wrapped(""), expect: wrapped("t"),
path: "/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi", path: "/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi",
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.Inline(true), options.Unixfs.RawLeaves(true), options.Unixfs.Hash(mh.SHA3)}, opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.Inline(true), options.Unixfs.RawLeaves(true), options.Unixfs.Hash(mh.SHA3)},
}, },
...@@ -428,7 +443,7 @@ func TestAdd(t *testing.T) { ...@@ -428,7 +443,7 @@ func TestAdd(t *testing.T) {
{Name: "", Bytes: 1000000}, {Name: "", Bytes: 1000000},
{Name: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Hash: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Size: "1000256"}, {Name: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Hash: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Size: "1000256"},
}, },
wrap: "t", wrap: "",
opts: []options.UnixfsAddOption{options.Unixfs.Progress(true)}, opts: []options.UnixfsAddOption{options.Unixfs.Progress(true)},
}, },
} }
...@@ -525,7 +540,7 @@ func TestAdd(t *testing.T) { ...@@ -525,7 +540,7 @@ func TestAdd(t *testing.T) {
} }
if origName != gotName { if origName != gotName {
t.Fatal("file name mismatch") t.Errorf("file name mismatch, orig='%s', got='%s'", origName, gotName)
} }
if !orig.IsDirectory() { if !orig.IsDirectory() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论