remove mock data from memory registry

memory registry can be used as fast inprocess registry,
so mock data needs to be in tests only

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2019-06-12 17:20:06 +03:00
parent 2b18b11ab1
commit ab692ff590
10 changed files with 165 additions and 8 deletions

51
broker/common_test.go Normal file
View File

@ -0,0 +1,51 @@
package broker
import (
"github.com/micro/go-micro/registry"
)
var (
// mock data
testData = map[string][]*registry.Service{
"foo": []*registry.Service{
{
Name: "foo",
Version: "1.0.0",
Nodes: []*registry.Node{
{
Id: "foo-1.0.0-123",
Address: "localhost",
Port: 9999,
},
{
Id: "foo-1.0.0-321",
Address: "localhost",
Port: 9999,
},
},
},
{
Name: "foo",
Version: "1.0.1",
Nodes: []*registry.Node{
{
Id: "foo-1.0.1-321",
Address: "localhost",
Port: 6666,
},
},
},
{
Name: "foo",
Version: "1.0.3",
Nodes: []*registry.Node{
{
Id: "foo-1.0.3-345",
Address: "localhost",
Port: 8888,
},
},
},
},
}
)

View File

@ -14,7 +14,7 @@ import (
func newTestRegistry() *memory.Registry { func newTestRegistry() *memory.Registry {
r := memory.NewRegistry() r := memory.NewRegistry()
m := r.(*memory.Registry) m := r.(*memory.Registry)
m.Setup() m.Services = testData
return m return m
} }

51
client/common_test.go Normal file
View File

@ -0,0 +1,51 @@
package client
import (
"github.com/micro/go-micro/registry"
)
var (
// mock data
testData = map[string][]*registry.Service{
"foo": []*registry.Service{
{
Name: "foo",
Version: "1.0.0",
Nodes: []*registry.Node{
{
Id: "foo-1.0.0-123",
Address: "localhost",
Port: 9999,
},
{
Id: "foo-1.0.0-321",
Address: "localhost",
Port: 9999,
},
},
},
{
Name: "foo",
Version: "1.0.1",
Nodes: []*registry.Node{
{
Id: "foo-1.0.1-321",
Address: "localhost",
Port: 6666,
},
},
},
{
Name: "foo",
Version: "1.0.3",
Nodes: []*registry.Node{
{
Id: "foo-1.0.3-345",
Address: "localhost",
Port: 8888,
},
},
},
},
}
)

View File

@ -13,8 +13,9 @@ import (
func newTestRegistry() registry.Registry { func newTestRegistry() registry.Registry {
r := memory.NewRegistry() r := memory.NewRegistry()
r.(*memory.Registry).Setup() reg := r.(*memory.Registry)
return r reg.Services = testData
return reg
} }
func TestCallAddress(t *testing.T) { func TestCallAddress(t *testing.T) {

View File

@ -1,4 +1,4 @@
package memory package micro
import ( import (
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
@ -6,7 +6,7 @@ import (
var ( var (
// mock data // mock data
Data = map[string][]*registry.Service{ testData = map[string][]*registry.Service{
"foo": []*registry.Service{ "foo": []*registry.Service{
{ {
Name: "foo", Name: "foo",

View File

@ -14,7 +14,7 @@ func TestFunction(t *testing.T) {
wg.Add(1) wg.Add(1)
r := memory.NewRegistry() r := memory.NewRegistry()
r.(*memory.Registry).Setup() r.(*memory.Registry).Services = testData
// create service // create service
fn := NewFunction( fn := NewFunction(

View File

@ -22,6 +22,7 @@ var (
timeout = time.Millisecond * 10 timeout = time.Millisecond * 10
) )
/*
// Setup sets mock data // Setup sets mock data
func (m *Registry) Setup() { func (m *Registry) Setup() {
m.Lock() m.Lock()
@ -30,6 +31,7 @@ func (m *Registry) Setup() {
// add some memory data // add some memory data
m.Services = Data m.Services = Data
} }
*/
func (m *Registry) watch(r *registry.Result) { func (m *Registry) watch(r *registry.Result) {
var watchers []*Watcher var watchers []*Watcher

51
selector/common_test.go Normal file
View File

@ -0,0 +1,51 @@
package selector
import (
"github.com/micro/go-micro/registry"
)
var (
// mock data
testData = map[string][]*registry.Service{
"foo": []*registry.Service{
{
Name: "foo",
Version: "1.0.0",
Nodes: []*registry.Node{
{
Id: "foo-1.0.0-123",
Address: "localhost",
Port: 9999,
},
{
Id: "foo-1.0.0-321",
Address: "localhost",
Port: 9999,
},
},
},
{
Name: "foo",
Version: "1.0.1",
Nodes: []*registry.Node{
{
Id: "foo-1.0.1-321",
Address: "localhost",
Port: 6666,
},
},
},
{
Name: "foo",
Version: "1.0.3",
Nodes: []*registry.Node{
{
Id: "foo-1.0.3-345",
Address: "localhost",
Port: 8888,
},
},
},
},
}
)

View File

@ -10,7 +10,8 @@ func TestRegistrySelector(t *testing.T) {
counts := map[string]int{} counts := map[string]int{}
r := memory.NewRegistry() r := memory.NewRegistry()
r.(*memory.Registry).Setup() rg := r.(*memory.Registry)
rg.Services = testData
cache := NewSelector(Registry(r)) cache := NewSelector(Registry(r))
next, err := cache.Select("foo") next, err := cache.Select("foo")

View File

@ -30,7 +30,7 @@ func testService(ctx context.Context, wg *sync.WaitGroup, name string) Service {
wg.Add(1) wg.Add(1)
r := memory.NewRegistry() r := memory.NewRegistry()
r.(*memory.Registry).Setup() r.(*memory.Registry).Services = testData
// create service // create service
return NewService( return NewService(