1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

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:
Vasiliy Tolstov 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 {
r := memory.NewRegistry()
m := r.(*memory.Registry)
m.Setup()
m.Services = testData
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 {
r := memory.NewRegistry()
r.(*memory.Registry).Setup()
return r
reg := r.(*memory.Registry)
reg.Services = testData
return reg
}
func TestCallAddress(t *testing.T) {

View File

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

View File

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

View File

@ -22,6 +22,7 @@ var (
timeout = time.Millisecond * 10
)
/*
// Setup sets mock data
func (m *Registry) Setup() {
m.Lock()
@ -30,6 +31,7 @@ func (m *Registry) Setup() {
// add some memory data
m.Services = Data
}
*/
func (m *Registry) watch(r *registry.Result) {
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{}
r := memory.NewRegistry()
r.(*memory.Registry).Setup()
rg := r.(*memory.Registry)
rg.Services = testData
cache := NewSelector(Registry(r))
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)
r := memory.NewRegistry()
r.(*memory.Registry).Setup()
r.(*memory.Registry).Services = testData
// create service
return NewService(