rls: Add an Equal method to the KeyBuilderMap type. (#3441)

This commit is contained in:
Easwar Swaminathan 2020-03-11 08:51:00 -07:00 committed by GitHub
parent 5c17da6907
commit dc074d6727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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)
}
})