@@ -223,11 +223,22 @@ func (e *osErrContains) errContains(t *testing.T, err error) {
223
223
}
224
224
225
225
func TestClient_FindProviders (t * testing.T ) {
226
+ unknownPeerRecord := makePeerRecord ([]string {})
226
227
bitswapPeerRecord := makePeerRecord ([]string {"transport-bitswap" })
227
228
httpPeerRecord := makePeerRecord ([]string {"transport-ipfs-gateway-http" })
229
+ fooPeerRecord := makePeerRecord ([]string {"transport-foo" })
230
+
228
231
peerProviders := []iter.Result [types.Record ]{
232
+ {Val : & unknownPeerRecord },
229
233
{Val : & bitswapPeerRecord },
230
234
{Val : & httpPeerRecord },
235
+ {Val : & fooPeerRecord },
236
+ }
237
+
238
+ // DefaultProtocolFilter
239
+ defaultFilterPeerProviders := []iter.Result [types.Record ]{
240
+ {Val : & unknownPeerRecord },
241
+ {Val : & bitswapPeerRecord },
231
242
}
232
243
233
244
bitswapRecord := makeBitswapRecord ()
@@ -249,16 +260,23 @@ func TestClient_FindProviders(t *testing.T) {
249
260
expJSONResponse bool
250
261
}{
251
262
{
252
- name : "happy case" ,
263
+ name : "happy case with DefaultProtocolFilter" ,
264
+ routerResult : peerProviders ,
265
+ expResult : defaultFilterPeerProviders ,
266
+ expStreamingResponse : true ,
267
+ },
268
+ {
269
+ name : "pass through with protocol filter disabled" ,
270
+ filterProtocols : []string {},
253
271
routerResult : peerProviders ,
254
272
expResult : peerProviders ,
255
273
expStreamingResponse : true ,
256
274
},
257
275
{
258
- name : "happy case with protocol filter" ,
259
- filterProtocols : []string {"transport-bitswap " },
276
+ name : "happy case with custom protocol filter" ,
277
+ filterProtocols : []string {"transport-foo " },
260
278
routerResult : peerProviders ,
261
- expResult : []iter.Result [types.Record ]{{Val : & bitswapPeerRecord }},
279
+ expResult : []iter.Result [types.Record ]{{Val : & fooPeerRecord }},
262
280
expStreamingResponse : true ,
263
281
},
264
282
{
@@ -270,7 +288,7 @@ func TestClient_FindProviders(t *testing.T) {
270
288
{
271
289
name : "server doesn't support streaming" ,
272
290
routerResult : peerProviders ,
273
- expResult : peerProviders ,
291
+ expResult : defaultFilterPeerProviders ,
274
292
serverStreamingDisabled : true ,
275
293
expJSONResponse : true ,
276
294
},
@@ -497,13 +515,25 @@ func TestClient_Provide(t *testing.T) {
497
515
}
498
516
499
517
func TestClient_FindPeers (t * testing.T ) {
500
- peerRecord1 := makePeerRecord ([]string {"transport-bitswap" })
501
- peerRecord2 := makePeerRecord ([]string {"transport-ipfs-gateway-http" })
518
+ unknownPeerRecord := makePeerRecord ([]string {})
519
+ bitswapPeerRecord := makePeerRecord ([]string {"transport-bitswap" })
520
+ httpPeerRecord := makePeerRecord ([]string {"transport-ipfs-gateway-http" })
521
+ fooPeerRecord := makePeerRecord ([]string {"transport-foo" })
522
+
502
523
peerRecords := []iter.Result [* types.PeerRecord ]{
503
- {Val : & peerRecord1 },
504
- {Val : & peerRecord2 },
524
+ {Val : & unknownPeerRecord },
525
+ {Val : & bitswapPeerRecord },
526
+ {Val : & httpPeerRecord },
527
+ {Val : & fooPeerRecord },
528
+ }
529
+
530
+ // DefaultProtocolFilter
531
+ defaultFilterPeerRecords := []iter.Result [* types.PeerRecord ]{
532
+ {Val : & unknownPeerRecord },
533
+ {Val : & bitswapPeerRecord },
505
534
}
506
- pid := * peerRecord1 .ID
535
+
536
+ pid := * bitswapPeerRecord .ID
507
537
508
538
cases := []struct {
509
539
name string
@@ -521,22 +551,29 @@ func TestClient_FindPeers(t *testing.T) {
521
551
expJSONResponse bool
522
552
}{
523
553
{
524
- name : "happy case" ,
554
+ name : "happy case with DefaultProtocolFilter" ,
555
+ routerResult : peerRecords ,
556
+ expResult : defaultFilterPeerRecords ,
557
+ expStreamingResponse : true ,
558
+ },
559
+ {
560
+ name : "pass through with protocol filter disabled" ,
561
+ filterProtocols : []string {},
525
562
routerResult : peerRecords ,
526
563
expResult : peerRecords ,
527
564
expStreamingResponse : true ,
528
565
},
529
566
{
530
- name : "happy case with protocol filter" ,
531
- filterProtocols : []string {"transport-bitswap " },
567
+ name : "happy case with custom protocol filter" ,
568
+ filterProtocols : []string {"transport-foo " },
532
569
routerResult : peerRecords ,
533
- expResult : []iter.Result [* types.PeerRecord ]{{Val : & peerRecord1 }},
570
+ expResult : []iter.Result [* types.PeerRecord ]{{Val : & fooPeerRecord }},
534
571
expStreamingResponse : true ,
535
572
},
536
573
{
537
574
name : "server doesn't support streaming" ,
538
575
routerResult : peerRecords ,
539
- expResult : peerRecords ,
576
+ expResult : defaultFilterPeerRecords ,
540
577
serverStreamingDisabled : true ,
541
578
expJSONResponse : true ,
542
579
},
0 commit comments