This repository has been archived by the owner on Aug 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
ipld_test.go
97 lines (89 loc) · 2.3 KB
/
ipld_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package ipld
import (
"testing"
mh "github.com/jbenet/go-multihash"
)
type TC struct {
src Node
links map[string]string
typ string
ctx interface{}
}
var testCases []TC
func mmh(b58 string) mh.Multihash {
h, err := mh.FromB58String(b58)
if err != nil {
panic("failed to decode multihash")
}
return h
}
func init() {
testCases = append(testCases, TC{
src: Node{
"foo": "bar",
"bar": []int{1, 2, 3},
"baz": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
},
"test": Node {
// This is not a link because mlink is not a string but a Node
"mlink": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
},
},
},
links: map[string]string{
"baz": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
"test/mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
},
typ: "",
ctx: nil,
}, TC{
src: Node{
"@context": "/ipfs/QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo/mdag",
"baz": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
},
"bazz": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
},
"bar": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPb",
},
"bar2": Node{
"@bar": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPa",
},
"\\@foo": Node{
"mlink": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPa",
},
},
},
links: map[string]string{
"baz": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
"bazz": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo",
"bar": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPb",
"bar2/@foo": "QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPa",
},
typ: "",
ctx: "/ipfs/QmZku7P7KeeHAnwMr6c4HveYfMzmtVinNXzibkiNbfDbPo/mdag",
})
}
func TestParsing(t *testing.T) {
for tci, tc := range testCases {
t.Logf("===== Test case #%d =====", tci)
doc := tc.src
// check links
links := doc.Links()
t.Logf("links: %#v", links)
if len(links) != len(tc.links) {
t.Errorf("links do not match, not the same number of links, expected %d, got %d", len(tc.links), len(links))
}
for k, l1 := range tc.links {
l2 := links[k]
if l1 != l2["mlink"] {
t.Errorf("links do not match. %d/%#v %#v != %#v[mlink]", tci, k, l1, l2)
}
}
}
}