1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-30 04:31:03 +02:00
kratos/transport/grpc/balancer_test.go
haiyux 00c05e82a3
test:remove testify go mod (#1766)
* test:remove testify go mod

* tidy go mdo

* fix test
2022-01-14 10:02:42 +08:00

41 lines
916 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 TestBalancerName(t *testing.T) {
o := &clientOptions{}
WithBalancerName("p2c")(o)
if !reflect.DeepEqual("p2c", o.balancerName) {
t.Errorf("expect %v, got %v", "p2c", o.balancerName)
}
}
func TestFilters(t *testing.T) {
o := &clientOptions{}
WithFilter(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))
}
}