Skip to content

Commit

Permalink
files2.0: Fix coreapi.unixfs.Add tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Oct 26, 2018
1 parent eff0aff commit 881340d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions core/coreapi/unixfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"math"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -297,9 +298,18 @@ func TestAdd(t *testing.T) {
data: func() files.File {
return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)
},
wrap: "foo",
expect: wrapped("foo"),
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",
path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU",
Expand All @@ -317,7 +327,12 @@ func TestAdd(t *testing.T) {
name: "stdinNamed",
path: "/ipfs/QmQ6cGBmb3ZbdrQW1MRm1RJnYnaxCqfssz7CrTa9NEhQyS",
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 {
return files.NewSliceFile([]files.FileEntry{
Expand All @@ -330,15 +345,15 @@ func TestAdd(t *testing.T) {
name: "twoLevelDirWrapped",
data: twoLevelDir(),
wrap: "t",
expect: wrapped(""),
expect: wrapped("t"),
path: "/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg",
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
},
{
name: "twoLevelInlineHash",
data: twoLevelDir(),
wrap: "t",
expect: wrapped(""),
expect: wrapped("t"),
path: "/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi",
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.Inline(true), options.Unixfs.RawLeaves(true), options.Unixfs.Hash(mh.SHA3)},
},
Expand Down Expand Up @@ -428,7 +443,7 @@ func TestAdd(t *testing.T) {
{Name: "", Bytes: 1000000},
{Name: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Hash: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Size: "1000256"},
},
wrap: "t",
wrap: "",
opts: []options.UnixfsAddOption{options.Unixfs.Progress(true)},
},
}
Expand Down Expand Up @@ -525,7 +540,7 @@ func TestAdd(t *testing.T) {
}

if origName != gotName {
t.Fatal("file name mismatch")
t.Errorf("file name mismatch, orig='%s', got='%s'", origName, gotName)
}

if !orig.IsDirectory() {
Expand Down

0 comments on commit 881340d

Please sign in to comment.