From e7b35d2f4892750659a82f2657277f2af11c193b Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 17 Aug 2020 04:05:58 -0400 Subject: [PATCH] sharness: added ipfs dag stat tests --- core/commands/dag/dag.go | 2 +- test/sharness/t0053-dag.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index c055151b726e..5ec3be8ee1e6 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -776,7 +776,7 @@ Note: This command skips duplicate blocks in reporting both size and the number cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, event *DagStat) error { _, err := fmt.Fprintf( w, - "%v", + "%v\n", event, ) return err diff --git a/test/sharness/t0053-dag.sh b/test/sharness/t0053-dag.sh index de35a58fd1c7..5bcc52b3f048 100755 --- a/test/sharness/t0053-dag.sh +++ b/test/sharness/t0053-dag.sh @@ -268,6 +268,41 @@ test_dag_cmd() { test_cmp resolve_obj_exp resolve_obj && test_cmp resolve_data_exp resolve_data ' + + test_expect_success "dag stat of simple IPLD object" ' + ipfs dag stat $NESTED_HASH > actual_stat_inner_ipld_obj && + echo "Size: 15, NumBlocks: 1" > exp_stat_inner_ipld_obj && + test_cmp exp_stat_inner_ipld_obj actual_stat_inner_ipld_obj && + ipfs dag stat $HASH > actual_stat_ipld_obj && + echo "Size: 61, NumBlocks: 2" > exp_stat_ipld_obj && + test_cmp exp_stat_ipld_obj actual_stat_ipld_obj + ' + + test_expect_success "dag stat of simple UnixFS object" ' + BASIC_UNIXFS=$(echo "1234" | ipfs add --pin=false -q) && + ipfs dag stat $BASIC_UNIXFS > actual_stat_basic_unixfs && + echo "Size: 13, NumBlocks: 1" > exp_stat_basic_unixfs && + test_cmp exp_stat_basic_unixfs actual_stat_basic_unixfs + ' + + # The multiblock file is just 10000 copies of the number 1 + # As most of its data is replicated it should have a small number of blocks + test_expect_success "dag stat of multiblock UnixFS object" ' + MULTIBLOCK_UNIXFS=$(printf "1%.0s" {1..10000000} | ipfs add --pin=false -q) && + ipfs dag stat $MULTIBLOCK_UNIXFS > actual_stat_multiblock_unixfs && + echo "Size: 302582, NumBlocks: 3" > exp_stat_multiblock_unixfs && + test_cmp exp_stat_multiblock_unixfs actual_stat_multiblock_unixfs + ' + + test_expect_success "dag stat of directory of UnixFS objects" ' + mkdir unixfsdir && + echo "1234" > unixfsdir/small.txt + printf "1%.0s" {1..10000000} > unixfsdir/many1s.txt && + DIRECTORY_UNIXFS=$(ipfs add -r --pin=false -Q unixfsdir) && + ipfs dag stat $DIRECTORY_UNIXFS > actual_stat_directory_unixfs && + echo "Size: 302705, NumBlocks: 5" > exp_stat_directory_unixfs && + test_cmp exp_stat_directory_unixfs actual_stat_directory_unixfs + ' } # should work offline