@cryptotaxi247 / kubo / commits / 60c869d40

dht/test: providers test id compare

Juan Batiz-Benet committed Dec 24, 2014 at 04:23 UTC 60c869d401f34aef977ed65c5d1abb6cd73581f3
1 file changed +10 -3
routing/dht/dht_test.go
+10 -3
@@ -334,10 +334,13 @@ func TestProvidesMany(t *testing.T) {
334 }
335 }
336
337 + var providers = map[u.Key]peer.ID{}
338 +
339 d := 0
340 for k, v := range testCaseValues {
341 d = (d + 1) % len(dhts)
342 dht := dhts[d]
343 + providers[k] = dht.self
344
345 t.Logf("adding local values for %s = %s (on %s)", k, v, dht.self)
346 err := dht.putLocal(k, v)
@@ -370,13 +373,17 @@ func TestProvidesMany(t *testing.T) {
373 getProvider := func(dht *IpfsDHT, k u.Key) {
374 defer wg.Done()
375
376 + expected := providers[k]
377 +
378 provchan := dht.FindProvidersAsync(ctxT, k, 1)
379 select {
380 case prov := <-provchan:
376 - if prov.ID == "" {
381 + actual := prov.ID
382 + if actual == "" {
383 errchan <- fmt.Errorf("Got back nil provider (%s at %s)", k, dht.self)
378 - } else if prov.ID != dhts[3].self {
379 - errchan <- fmt.Errorf("Got back wrong provider (%s at %s)", k, dht.self)
384 + } else if actual != expected {
385 + errchan <- fmt.Errorf("Got back wrong provider (%s != %s) (%s at %s)",
386 + expected, actual, k, dht.self)
387 }
388 case <-ctxT.Done():
389 errchan <- fmt.Errorf("Did not get a provider back (%s at %s)", k, dht.self)