2015-12-09 21:23:16 +02:00
|
|
|
package selector
|
2015-12-09 02:02:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-12-09 21:23:16 +02:00
|
|
|
|
|
|
|
"github.com/micro/go-micro/registry/mock"
|
2015-12-09 02:02:45 +02:00
|
|
|
)
|
|
|
|
|
2018-12-29 17:44:51 +02:00
|
|
|
func TestRegistrySelector(t *testing.T) {
|
2015-12-09 02:02:45 +02:00
|
|
|
counts := map[string]int{}
|
|
|
|
|
2018-12-29 17:44:51 +02:00
|
|
|
cache := NewSelector(Registry(mock.NewRegistry()))
|
2015-12-09 02:02:45 +02:00
|
|
|
|
2018-12-29 17:44:51 +02:00
|
|
|
next, err := cache.Select("foo")
|
2015-12-09 02:02:45 +02:00
|
|
|
if err != nil {
|
2018-12-29 17:44:51 +02:00
|
|
|
t.Errorf("Unexpected error calling cache select: %v", err)
|
2015-12-09 02:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
node, err := next()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected node err, got err: %v", err)
|
|
|
|
}
|
|
|
|
counts[node.Id]++
|
|
|
|
}
|
|
|
|
|
2018-12-29 17:44:51 +02:00
|
|
|
t.Logf("Selector Counts %v", counts)
|
2016-05-07 01:04:08 +02:00
|
|
|
}
|