1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-14 02:33:03 +02:00
kratos/transport/grpc/balancer_test.go
longxboy 11cd43e3c3
refactor: unify selector filter (#2277)
* unify selector

Co-authored-by: caoguoliang01 <caoguoliang01@bilibili.com>
Co-authored-by: chenzhihui <zhihui_chen@foxmail.com>
2022-08-16 21:21:58 +08:00

32 lines
721 B
Go

package grpc
import (
"context"
"reflect"
"testing"
"github.com/go-kratos/kratos/v2/selector"
"google.golang.org/grpc/metadata"
)
func TestTrailer(t *testing.T) {
trailer := Trailer(metadata.New(map[string]string{"a": "b"}))
if !reflect.DeepEqual("b", trailer.Get("a")) {
t.Errorf("expect %v, got %v", "b", trailer.Get("a"))
}
if !reflect.DeepEqual("", trailer.Get("notfound")) {
t.Errorf("expect %v, got %v", "", trailer.Get("notfound"))
}
}
func TestFilters(t *testing.T) {
o := &clientOptions{}
WithNodeFilter(func(_ context.Context, nodes []selector.Node) []selector.Node {
return nodes
})(o)
if !reflect.DeepEqual(1, len(o.filters)) {
t.Errorf("expect %v, got %v", 1, len(o.filters))
}
}