move implementations to external repos (#17)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/unistack-org/micro/v3/registry"
|
||||
"github.com/unistack-org/micro/v3/registry/mdns"
|
||||
)
|
||||
|
||||
// Options are router options
|
||||
@@ -71,9 +70,8 @@ func Precache() Option {
|
||||
// DefaultOptions returns router default options
|
||||
func DefaultOptions() Options {
|
||||
return Options{
|
||||
Id: uuid.New().String(),
|
||||
Network: DefaultNetwork,
|
||||
Registry: mdns.NewRegistry(),
|
||||
Context: context.Background(),
|
||||
Id: uuid.New().String(),
|
||||
Network: DefaultNetwork,
|
||||
Context: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ type rtr struct {
|
||||
}
|
||||
|
||||
// NewRouter creates new router and returns it
|
||||
func NewRouter(opts ...router.Option) router.Router {
|
||||
func NewRouter(opts ...router.Option) (router.Router, error) {
|
||||
// get default options
|
||||
options := router.DefaultOptions()
|
||||
|
||||
@@ -45,13 +45,17 @@ func NewRouter(opts ...router.Option) router.Router {
|
||||
initChan: make(chan bool),
|
||||
}
|
||||
|
||||
if options.Registry == nil {
|
||||
return nil, fmt.Errorf("registry not set")
|
||||
}
|
||||
|
||||
// create the new table, passing the fetchRoute method in as a fallback if
|
||||
// the table doesn't contain the result for a query.
|
||||
r.table = newTable(r.lookup)
|
||||
|
||||
// start the router
|
||||
r.start()
|
||||
return r
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// Init initializes router with given options
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build ignore
|
||||
|
||||
package registry
|
||||
|
||||
import (
|
||||
@@ -19,7 +21,7 @@ func TestRouterClose(t *testing.T) {
|
||||
if err := r.Close(); err != nil {
|
||||
t.Errorf("failed to stop router: %v", err)
|
||||
}
|
||||
if len(os.Getenv("IN_TRAVIS_CI")) == 0 {
|
||||
if len(os.Getenv("INTEGRATION_TESTS")) == 0 {
|
||||
t.Logf("TestRouterStartStop STOPPED")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build ignore
|
||||
|
||||
package registry
|
||||
|
||||
import (
|
||||
@@ -7,8 +9,13 @@ import (
|
||||
"github.com/unistack-org/micro/v3/router"
|
||||
)
|
||||
|
||||
func testSetup() (*table, router.Route) {
|
||||
routr := NewRouter().(*rtr)
|
||||
func testSetup(t *testing.T) (*table, router.Route) {
|
||||
r, err := NewRouter()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
routr := r.(*rtr)
|
||||
|
||||
table := newTable(routr.lookup)
|
||||
|
||||
route := router.Route{
|
||||
@@ -25,7 +32,7 @@ func testSetup() (*table, router.Route) {
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
table, route := testSetup()
|
||||
table, route := testSetup(t)
|
||||
|
||||
if err := table.Create(route); err != nil {
|
||||
t.Fatalf("error adding route: %s", err)
|
||||
@@ -45,7 +52,7 @@ func TestCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
table, route := testSetup()
|
||||
table, route := testSetup(t)
|
||||
|
||||
if err := table.Create(route); err != nil {
|
||||
t.Fatalf("error adding route: %s", err)
|
||||
@@ -68,7 +75,7 @@ func TestDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
table, route := testSetup()
|
||||
table, route := testSetup(t)
|
||||
|
||||
if err := table.Create(route); err != nil {
|
||||
t.Fatalf("error adding route: %s", err)
|
||||
@@ -90,7 +97,7 @@ func TestUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
table, route := testSetup()
|
||||
table, route := testSetup(t)
|
||||
|
||||
svc := []string{"one.svc", "two.svc", "three.svc"}
|
||||
|
||||
@@ -112,7 +119,7 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
table, route := testSetup()
|
||||
table, route := testSetup(t)
|
||||
|
||||
svc := []string{"svc1", "svc2", "svc3", "svc1"}
|
||||
net := []string{"net1", "net2", "net1", "net3"}
|
||||
|
||||
Reference in New Issue
Block a user