1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/client/selector/default_test.go

32 lines
576 B
Go
Raw Normal View History

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
2019-01-14 17:27:25 +02:00
"github.com/micro/go-micro/registry/memory"
2015-12-09 02:02:45 +02:00
)
func TestRegistrySelector(t *testing.T) {
2015-12-09 02:02:45 +02:00
counts := map[string]int{}
2019-01-14 17:27:25 +02:00
r := memory.NewRegistry()
rg := r.(*memory.Registry)
rg.Services = testData
2019-01-14 17:27:25 +02:00
cache := NewSelector(Registry(r))
2015-12-09 02:02:45 +02:00
next, err := cache.Select("foo")
2015-12-09 02:02:45 +02:00
if err != nil {
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]++
}
t.Logf("Selector Counts %v", counts)
}