@cryptotaxi247 / kubo / commits / a96b370ee

files2.0: Fix coreapi.unixfs.Add tests

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

Łukasz Magiera committed Oct 26, 2018 at 16:42 UTC a96b370ee28281a2beeb3365889469fadc96ba52
1 file changed +20 -5
core/coreapi/unixfs_test.go
+20 -5
@@ -8,6 +8,7 @@ import (
8 "io"
9 "io/ioutil"
10 "math"
11 + "os"
12 "strconv"
13 "strings"
14 "sync"
@@ -297,9 +298,18 @@ func TestAdd(t *testing.T) {
298 data: func() files.File {
299 return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)
300 },
301 + wrap: "foo",
302 expect: wrapped("foo"),
303 opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
304 },
305 + {
306 + name: "addNotWrappedDirFile",
307 + path: hello,
308 + data: func() files.File {
309 + return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)
310 + },
311 + wrap: "foo",
312 + },
313 {
314 name: "stdinWrapped",
315 path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU",
@@ -317,7 +327,12 @@ func TestAdd(t *testing.T) {
327 name: "stdinNamed",
328 path: "/ipfs/QmQ6cGBmb3ZbdrQW1MRm1RJnYnaxCqfssz7CrTa9NEhQyS",
329 data: func() files.File {
320 - return files.NewReaderFile(ioutil.NopCloser(strings.NewReader(helloStr)), nil)
330 + rf, err := files.NewReaderPathFile(os.Stdin.Name(), ioutil.NopCloser(strings.NewReader(helloStr)), nil)
331 + if err != nil {
332 + panic(err)
333 + }
334 +
335 + return rf
336 },
337 expect: func(files.File) files.File {
338 return files.NewSliceFile([]files.FileEntry{
@@ -330,7 +345,7 @@ func TestAdd(t *testing.T) {
345 name: "twoLevelDirWrapped",
346 data: twoLevelDir(),
347 wrap: "t",
333 - expect: wrapped(""),
348 + expect: wrapped("t"),
349 path: "/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg",
350 opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
351 },
@@ -338,7 +353,7 @@ func TestAdd(t *testing.T) {
353 name: "twoLevelInlineHash",
354 data: twoLevelDir(),
355 wrap: "t",
341 - expect: wrapped(""),
356 + expect: wrapped("t"),
357 path: "/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi",
358 opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.Inline(true), options.Unixfs.RawLeaves(true), options.Unixfs.Hash(mh.SHA3)},
359 },
@@ -428,7 +443,7 @@ func TestAdd(t *testing.T) {
443 {Name: "", Bytes: 1000000},
444 {Name: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Hash: "QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD", Size: "1000256"},
445 },
431 - wrap: "t",
446 + wrap: "",
447 opts: []options.UnixfsAddOption{options.Unixfs.Progress(true)},
448 },
449 }
@@ -525,7 +540,7 @@ func TestAdd(t *testing.T) {
540 }
541
542 if origName != gotName {
528 - t.Fatal("file name mismatch")
543 + t.Errorf("file name mismatch, orig='%s', got='%s'", origName, gotName)
544 }
545
546 if !orig.IsDirectory() {