selector: update selector.Select to accept a slice of structs (#1764)

This commit is contained in:
ben-toogood
2020-06-30 15:51:26 +01:00
committed by GitHub
parent 6337c92cd0
commit b882ff3df9
6 changed files with 38 additions and 43 deletions

View File

@@ -9,24 +9,24 @@ import (
// 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 := 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"}
t.Run("Select", func(t *testing.T) {
t.Run("NoRoutes", func(t *testing.T) {
srv, err := s.Select([]*router.Route{})
srv, err := s.Select([]router.Route{})
assert.Nil(t, srv, "Route should be nil")
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})
srv, err := s.Select([]router.Route{r1})
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})
srv, err := s.Select([]router.Route{r1, r2})
assert.Nil(t, err, "Error should be nil")
if srv.Address != r1.Address && srv.Address != r2.Address {
t.Errorf("Expected the route to be one of the inputs")