@@ -15,6 +15,7 @@ import (
15
15
"github.com/ipld/go-ipld-prime/linking"
16
16
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
17
17
"github.com/ipld/go-ipld-prime/node/basicnode"
18
+ "github.com/ipld/go-ipld-prime/traversal"
18
19
"github.com/stretchr/testify/require"
19
20
)
20
21
@@ -51,7 +52,8 @@ func ToDirEntry(t *testing.T, linkSys linking.LinkSystem, rootCid cid.Cid, expec
51
52
52
53
func toDirEntryRecursive (t * testing.T , linkSys linking.LinkSystem , rootCid cid.Cid , name string , expectFull bool ) * DirEntry {
53
54
var proto datamodel.NodePrototype = dagpb .Type .PBNode
54
- if rootCid .Prefix ().Codec == cid .Raw {
55
+ isDagPb := rootCid .Prefix ().Codec == cid .DagProtobuf
56
+ if ! isDagPb {
55
57
proto = basicnode .Prototype .Any
56
58
}
57
59
node , err := linkSys .Load (linking.LinkContext {Ctx : context .TODO ()}, cidlink.Link {Cid : rootCid }, proto )
@@ -73,18 +75,36 @@ func toDirEntryRecursive(t *testing.T, linkSys linking.LinkSystem, rootCid cid.C
73
75
Root : rootCid ,
74
76
}
75
77
}
76
- // else is a directory
78
+
77
79
children := make ([]DirEntry , 0 )
78
- for itr := node .MapIterator (); ! itr .Done (); {
79
- k , v , err := itr .Next ()
80
- require .NoError (t , err )
81
- childName , err := k .AsString ()
82
- require .NoError (t , err )
83
- childLink , err := v .AsLink ()
80
+ if isDagPb {
81
+ // else is likely a directory
82
+ for itr := node .MapIterator (); ! itr .Done (); {
83
+ k , v , err := itr .Next ()
84
+ require .NoError (t , err )
85
+ childName , err := k .AsString ()
86
+ require .NoError (t , err )
87
+ childLink , err := v .AsLink ()
88
+ require .NoError (t , err )
89
+ child := toDirEntryRecursive (t , linkSys , childLink .(cidlink.Link ).Cid , name + "/" + childName , expectFull )
90
+ children = append (children , * child )
91
+ }
92
+ } else {
93
+ // not a dag-pb node, let's pretend it is but using IPLD pathing rules
94
+ err := traversal .WalkLocal (node , func (prog traversal.Progress , n ipld.Node ) error {
95
+ if n .Kind () == ipld .Kind_Link {
96
+ l , err := n .AsLink ()
97
+ if err != nil {
98
+ return err
99
+ }
100
+ child := toDirEntryRecursive (t , linkSys , l .(cidlink.Link ).Cid , name + "/" + prog .Path .String (), expectFull )
101
+ children = append (children , * child )
102
+ }
103
+ return nil
104
+ })
84
105
require .NoError (t , err )
85
- child := toDirEntryRecursive (t , linkSys , childLink .(cidlink.Link ).Cid , name + "/" + childName , expectFull )
86
- children = append (children , * child )
87
106
}
107
+
88
108
return & DirEntry {
89
109
Path : name ,
90
110
Root : rootCid ,
@@ -112,7 +132,7 @@ func CompareDirEntries(t *testing.T, a, b DirEntry) {
112
132
CompareDirEntries (t , a .Children [i ], b .Children [j ])
113
133
}
114
134
}
115
- require .True (t , found , fmt .Sprintf ("%s child %s not found in b" , a .Path , a .Children [i ].Path ))
135
+ require .True (t , found , fmt .Sprintf ("@ path [%s], a's child [%s] not found in b" , a .Path , a .Children [i ].Path ))
116
136
}
117
137
}
118
138
0 commit comments