mirror of https://github.com/grpc/grpc-go.git
rls: Add an Equal method to the KeyBuilderMap type. (#3441)
This commit is contained in:
parent
5c17da6907
commit
dc074d6727
|
|
@ -27,6 +27,7 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
rlspb "google.golang.org/grpc/balancer/rls/internal/proto/grpc_lookup_v1"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
|
@ -122,6 +123,11 @@ func (bm BuilderMap) RLSKey(md metadata.MD, path string) KeyMap {
|
|||
return b.keys(md)
|
||||
}
|
||||
|
||||
// BuilderMapEqual returns true if the provided BuilderMap objects are equal.
|
||||
func BuilderMapEqual(a, b BuilderMap) bool {
|
||||
return cmp.Equal(a, b, cmp.AllowUnexported(builder{}, matcher{}))
|
||||
}
|
||||
|
||||
// builder provides the actual functionality of building RLS keys. These are
|
||||
// stored in the BuilderMap.
|
||||
// While processing a pick, the picker looks in the BuilderMap for the
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func TestMakeBuilderMap(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
builderMap, err := MakeBuilderMap(test.cfg)
|
||||
if err != nil || !cmp.Equal(builderMap, test.wantBuilderMap, cmp.AllowUnexported(builder{}, matcher{})) {
|
||||
if err != nil || !BuilderMapEqual(builderMap, test.wantBuilderMap) {
|
||||
t.Errorf("MakeBuilderMap(%+v) returned {%v, %v}, want: {%v, nil}", test.cfg, builderMap, err, test.wantBuilderMap)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue