cleanup client/selector/lookup (#1937)

* cleanup client/selector/lookup

* add mdns router, remove registry from client

* fix roundtripper

* remove comment

* fix compile issue

* fix mucp test

* fix api router
This commit is contained in:
Asim Aslam
2020-08-17 22:44:45 +01:00
committed by GitHub
parent 7135787b78
commit 50ec6c748f
17 changed files with 398 additions and 418 deletions

View File

@@ -3,47 +3,35 @@ package selector
import (
"testing"
"github.com/micro/go-micro/v3/router"
"github.com/stretchr/testify/assert"
)
// Tests runs all the tests against a selector to ensure the implementations are consistent
func Tests(t *testing.T, s Selector) {
r1 := router.Route{Service: "go.micro.service.foo", Address: "127.0.0.1:8000"}
r2 := router.Route{Service: "go.micro.service.foo", Address: "127.0.0.1:8001"}
r1 := "127.0.0.1:8000"
r2 := "127.0.0.1:8001"
t.Run("Select", func(t *testing.T) {
t.Run("NoRoutes", func(t *testing.T) {
srv, err := s.Select([]router.Route{})
assert.Nil(t, srv, "Route should be nil")
_, err := s.Select([]string{})
assert.Equal(t, ErrNoneAvailable, err, "Expected error to be none available")
})
t.Run("OneRoute", func(t *testing.T) {
srv, err := s.Select([]router.Route{r1})
next, err := s.Select([]string{r1})
srv := next()
assert.Nil(t, err, "Error should be nil")
assert.Equal(t, r1, *srv, "Expected the route to be returned")
assert.Equal(t, r1, srv, "Expected the route to be returned")
})
t.Run("MultipleRoutes", func(t *testing.T) {
srv, err := s.Select([]router.Route{r1, r2})
next, err := s.Select([]string{r1, r2})
assert.Nil(t, err, "Error should be nil")
if srv.Address != r1.Address && srv.Address != r2.Address {
srv := next()
if srv != r1 && srv != r2 {
t.Errorf("Expected the route to be one of the inputs")
}
})
t.Run("Filters", func(t *testing.T) {
var filterApplied bool
filter := func(rts []router.Route) []router.Route {
filterApplied = true
return rts
}
_, err := s.Select([]router.Route{r1, r2}, WithFilter(filter))
assert.Nil(t, err, "Error should be nil")
assert.True(t, filterApplied, "Filters should be applied")
})
})
t.Run("Record", func(t *testing.T) {