@@ -147,24 +147,87 @@ func TestPeers(t *testing.T) {
147
147
return resp
148
148
}
149
149
150
- t .Run ("GET /routing/v1/peers/{non-peer-cid} returns 400" , func (t * testing.T ) {
150
+ t .Run ("GET /routing/v1/peers/{non-peer-valid- cid} returns 400" , func (t * testing.T ) {
151
151
t .Parallel ()
152
152
153
153
router := & mockContentRouter {}
154
154
resp := makeRequest (t , router , mediaTypeJSON , "bafkqaaa" )
155
155
require .Equal (t , 400 , resp .StatusCode )
156
156
})
157
157
158
- t .Run ("GET /routing/v1/peers/{base58- peer-id} returns 400 " , func (t * testing.T ) {
158
+ t .Run ("GET /routing/v1/peers/{cid-libp2p-key- peer-id} returns 200 with correct body (JSON) " , func (t * testing.T ) {
159
159
t .Parallel ()
160
160
161
161
_ , pid := makePeerID (t )
162
+ results := iter .FromSlice ([]iter.Result [* types.PeerRecord ]{
163
+ {Val : & types.PeerRecord {
164
+ Schema : types .SchemaPeer ,
165
+ ID : & pid ,
166
+ Protocols : []string {"transport-bitswap" , "transport-foo" },
167
+ Addrs : []types.Multiaddr {},
168
+ }},
169
+ {Val : & types.PeerRecord {
170
+ Schema : types .SchemaPeer ,
171
+ ID : & pid ,
172
+ Protocols : []string {"transport-foo" },
173
+ Addrs : []types.Multiaddr {},
174
+ }},
175
+ })
176
+
162
177
router := & mockContentRouter {}
163
- resp := makeRequest (t , router , mediaTypeJSON , b58 .Encode ([]byte (pid )))
164
- require .Equal (t , 400 , resp .StatusCode )
178
+ router .On ("FindPeers" , mock .Anything , pid , 20 ).Return (results , nil )
179
+
180
+ libp2pKeyCID := peer .ToCid (pid ).String ()
181
+ resp := makeRequest (t , router , mediaTypeJSON , libp2pKeyCID )
182
+ require .Equal (t , 200 , resp .StatusCode )
183
+
184
+ header := resp .Header .Get ("Content-Type" )
185
+ require .Equal (t , mediaTypeJSON , header )
186
+
187
+ body , err := io .ReadAll (resp .Body )
188
+ require .NoError (t , err )
189
+
190
+ expectedBody := `{"Peers":[{"Addrs":[],"ID":"` + pid .String () + `","Protocols":["transport-bitswap","transport-foo"],"Schema":"peer"},{"Addrs":[],"ID":"` + pid .String () + `","Protocols":["transport-foo"],"Schema":"peer"}]}`
191
+ require .Equal (t , expectedBody , string (body ))
192
+ })
193
+
194
+ t .Run ("GET /routing/v1/peers/{cid-libp2p-key-peer-id} returns 200 with correct body (NDJSON)" , func (t * testing.T ) {
195
+ t .Parallel ()
196
+
197
+ _ , pid := makePeerID (t )
198
+ results := iter .FromSlice ([]iter.Result [* types.PeerRecord ]{
199
+ {Val : & types.PeerRecord {
200
+ Schema : types .SchemaPeer ,
201
+ ID : & pid ,
202
+ Protocols : []string {"transport-bitswap" , "transport-foo" },
203
+ Addrs : []types.Multiaddr {},
204
+ }},
205
+ {Val : & types.PeerRecord {
206
+ Schema : types .SchemaPeer ,
207
+ ID : & pid ,
208
+ Protocols : []string {"transport-foo" },
209
+ Addrs : []types.Multiaddr {},
210
+ }},
211
+ })
212
+
213
+ router := & mockContentRouter {}
214
+ router .On ("FindPeers" , mock .Anything , pid , 0 ).Return (results , nil )
215
+
216
+ libp2pKeyCID := peer .ToCid (pid ).String ()
217
+ resp := makeRequest (t , router , mediaTypeNDJSON , libp2pKeyCID )
218
+ require .Equal (t , 200 , resp .StatusCode )
219
+
220
+ header := resp .Header .Get ("Content-Type" )
221
+ require .Equal (t , mediaTypeNDJSON , header )
222
+
223
+ body , err := io .ReadAll (resp .Body )
224
+ require .NoError (t , err )
225
+
226
+ expectedBody := `{"Addrs":[],"ID":"` + pid .String () + `","Protocols":["transport-bitswap","transport-foo"],"Schema":"peer"}` + "\n " + `{"Addrs":[],"ID":"` + pid .String () + `","Protocols":["transport-foo"],"Schema":"peer"}` + "\n "
227
+ require .Equal (t , expectedBody , string (body ))
165
228
})
166
229
167
- t .Run ("GET /routing/v1/peers/{cid -peer-id} returns 200 with correct body (JSON)" , func (t * testing.T ) {
230
+ t .Run ("GET /routing/v1/peers/{legacy-base58 -peer-id} returns 200 with correct body (JSON)" , func (t * testing.T ) {
168
231
t .Parallel ()
169
232
170
233
_ , pid := makePeerID (t )
@@ -186,7 +249,8 @@ func TestPeers(t *testing.T) {
186
249
router := & mockContentRouter {}
187
250
router .On ("FindPeers" , mock .Anything , pid , 20 ).Return (results , nil )
188
251
189
- resp := makeRequest (t , router , mediaTypeJSON , peer .ToCid (pid ).String ())
252
+ legacyPeerID := b58 .Encode ([]byte (pid ))
253
+ resp := makeRequest (t , router , mediaTypeJSON , legacyPeerID )
190
254
require .Equal (t , 200 , resp .StatusCode )
191
255
192
256
header := resp .Header .Get ("Content-Type" )
@@ -199,7 +263,7 @@ func TestPeers(t *testing.T) {
199
263
require .Equal (t , expectedBody , string (body ))
200
264
})
201
265
202
- t .Run ("GET /routing/v1/peers/{cid -peer-id} returns 200 with correct body (NDJSON)" , func (t * testing.T ) {
266
+ t .Run ("GET /routing/v1/peers/{legacy-base58 -peer-id} returns 200 with correct body (NDJSON)" , func (t * testing.T ) {
203
267
t .Parallel ()
204
268
205
269
_ , pid := makePeerID (t )
@@ -221,7 +285,8 @@ func TestPeers(t *testing.T) {
221
285
router := & mockContentRouter {}
222
286
router .On ("FindPeers" , mock .Anything , pid , 0 ).Return (results , nil )
223
287
224
- resp := makeRequest (t , router , mediaTypeNDJSON , peer .ToCid (pid ).String ())
288
+ legacyPeerID := b58 .Encode ([]byte (pid ))
289
+ resp := makeRequest (t , router , mediaTypeNDJSON , legacyPeerID )
225
290
require .Equal (t , 200 , resp .StatusCode )
226
291
227
292
header := resp .Header .Get ("Content-Type" )
@@ -233,6 +298,7 @@ func TestPeers(t *testing.T) {
233
298
expectedBody := `{"Addrs":[],"ID":"` + pid .String () + `","Protocols":["transport-bitswap","transport-foo"],"Schema":"peer"}` + "\n " + `{"Addrs":[],"ID":"` + pid .String () + `","Protocols":["transport-foo"],"Schema":"peer"}` + "\n "
234
299
require .Equal (t , expectedBody , string (body ))
235
300
})
301
+
236
302
}
237
303
238
304
func makeName (t * testing.T ) (crypto.PrivKey , ipns.Name ) {
0 commit comments