@cryptotaxi247 / kubo / commits / 70d0f13c9

unixfs/mod: add test to `Truncate` to the same size

License: MIT Signed-off-by: Lucas Molas <schomatis@gmail.com>

Lucas Molas committed Jul 18, 2018 at 11:07 UTC 70d0f13c9caa6ce618f7260fde84bbba9d50173c
1 file changed +38
unixfs/mod/dagmodifier_test.go
+38
@@ -406,6 +406,44 @@ func testDagTruncate(t *testing.T, opts testu.NodeOpts) {
406 }
407 }
408
409 +// TestDagTruncateSameSize tests that a DAG truncated
410 +// to the same size (i.e., doing nothing) doesn't modify
411 +// the DAG (its hash).
412 +func TestDagTruncateSameSize(t *testing.T) {
413 + runAllSubtests(t, testDagTruncateSameSize)
414 +}
415 +func testDagTruncateSameSize(t *testing.T, opts testu.NodeOpts) {
416 + dserv := testu.GetDAGServ()
417 + _, n := testu.GetRandomNode(t, dserv, 50000, opts)
418 + ctx, cancel := context.WithCancel(context.Background())
419 + defer cancel()
420 +
421 + dagmod, err := NewDagModifier(ctx, n, dserv, testu.SizeSplitterGen(512))
422 + if err != nil {
423 + t.Fatal(err)
424 + }
425 + // Copied from `TestDagTruncate`.
426 +
427 + size, err := dagmod.Size()
428 + if err != nil {
429 + t.Fatal(err)
430 + }
431 +
432 + err = dagmod.Truncate(size)
433 + if err != nil {
434 + t.Fatal(err)
435 + }
436 +
437 + modifiedNode, err := dagmod.GetNode()
438 + if err != nil {
439 + t.Fatal(err)
440 + }
441 +
442 + if modifiedNode.Cid().Equals(n.Cid()) == false {
443 + t.Fatal("the node has been modified!")
444 + }
445 +}
446 +
447 func TestSparseWrite(t *testing.T) {
448 runAllSubtests(t, testSparseWrite)
449 }