Skip to content

Commit

Permalink
allow for sub-object resolution in dag get
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Feb 14, 2017
1 parent 9d8a4af commit cb611c8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
path "github.com/ipfs/go-ipfs/path"

cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
ipldcbor "gx/ipfs/QmWcQMNruWC3wphK1L6zEcV4MZBJqfsNKSRFcuo4AsNk4k/go-ipld-cbor"
node "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
ipldcbor "gx/ipfs/QmdaC21UyoyN3t9QdapHZfsaUo3mqVf5p4CEuFaYVFqwap/go-ipld-cbor"
)

var DagCmd = &cmds.Command{
Expand Down
2 changes: 1 addition & 1 deletion merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
ipldcbor "gx/ipfs/QmWcQMNruWC3wphK1L6zEcV4MZBJqfsNKSRFcuo4AsNk4k/go-ipld-cbor"
node "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
ipldcbor "gx/ipfs/QmdaC21UyoyN3t9QdapHZfsaUo3mqVf5p4CEuFaYVFqwap/go-ipld-cbor"
)

var log = logging.Logger("merkledag")
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmWcQMNruWC3wphK1L6zEcV4MZBJqfsNKSRFcuo4AsNk4k",
"hash": "QmdaC21UyoyN3t9QdapHZfsaUo3mqVf5p4CEuFaYVFqwap",
"name": "go-ipld-cbor",
"version": "1.2.0"
"version": "1.2.1"
},
{
"author": "lgierth",
Expand Down
25 changes: 23 additions & 2 deletions test/sharness/t0053-dag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_expect_success "make a few test files" '
'

test_expect_success "make an ipld object in json" '
printf "{\"hello\":\"world\",\"cats\":[{\"/\":\"%s\"},{\"water\":{\"/\":\"%s\"}}],\"magic\":{\"/\":\"%s\"}}" $HASH1 $HASH2 $HASH3 > ipld_object
printf "{\"hello\":\"world\",\"cats\":[{\"/\":\"%s\"},{\"water\":{\"/\":\"%s\"}}],\"magic\":{\"/\":\"%s\"},\"sub\":{\"dict\":\"ionary\",\"beep\":[0,\"bop\"]}}" $HASH1 $HASH2 $HASH3 > ipld_object
'

test_dag_cmd() {
Expand All @@ -31,7 +31,7 @@ test_dag_cmd() {
'

test_expect_success "output looks correct" '
EXPHASH="zdpuAzn7KZcQmKJvpEM1DgHXaybVj7mRP4ZMrkW94taYEuZHp"
EXPHASH="zdpuAsXfkHapxohc8LtsCzYiAsy84ESqKRD8eWuY64tt9r2CE"
test $EXPHASH = $IPLDHASH
'

Expand All @@ -47,6 +47,27 @@ test_dag_cmd() {
test_cmp file3 out3
'

test_expect_success "resolving sub-objects works" '
ipfs dag get $IPLDHASH/hello > sub1 &&
ipfs dag get $IPLDHASH/sub > sub2 &&
ipfs dag get $IPLDHASH/sub/beep > sub3 &&
ipfs dag get $IPLDHASH/sub/beep/0 > sub4 &&
ipfs dag get $IPLDHASH/sub/beep/1 > sub5
'

test_expect_success "sub-objects look right" '
echo "\"world\"" > sub1_exp &&
test_cmp sub1_exp sub1 &&
echo "{\"beep\":[0,\"bop\"],\"dict\":\"ionary\"}" > sub2_exp &&
test_cmp sub2_exp sub2 &&
echo "[0,\"bop\"]" > sub3_exp &&
test_cmp sub3_exp sub3 &&
echo "0" > sub4_exp &&
test_cmp sub4_exp sub4 &&
echo "\"bop\"" > sub5_exp &&
test_cmp sub5_exp sub5
'

test_expect_success "can pin cbor object" '
ipfs pin add $EXPHASH
'
Expand Down

0 comments on commit cb611c8

Please sign in to comment.