MCPcopy
hub / github.com/grpc/grpc-go / TestRLSKey

Function TestRLSKey

balancer/rls/internal/keys/builder_test.go:260–369  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func TestRLSKey(t *testing.T) {
261 bm, err := MakeBuilderMap(&rlspb.RouteLookupConfig{
262 GrpcKeybuilders: []*rlspb.GrpcKeyBuilder{goodKeyBuilder1, goodKeyBuilder2},
263 })
264 if err != nil {
265 t.Fatalf("MakeBuilderMap() failed: %v", err)
266 }
267
268 tests := []struct {
269 desc string
270 path string
271 md metadata.MD
272 wantKM KeyMap
273 }{
274 {
275 // No keyBuilder is found for the provided service.
276 desc: "service not found in key builder map",
277 path: "/notFoundService/method",
278 md: metadata.Pairs("n1", "v1", "n2", "v2"),
279 wantKM: KeyMap{},
280 },
281 {
282 // No keyBuilder is found for the provided method.
283 desc: "method not found in key builder map",
284 path: "/gBar/notFoundMethod",
285 md: metadata.Pairs("n1", "v1", "n2", "v2"),
286 wantKM: KeyMap{},
287 },
288 {
289 // A keyBuilder is found, but none of the headers match.
290 desc: "directPathMatch-NoMatchingKey",
291 path: "/gBar/method1",
292 md: metadata.Pairs("notMatchingKey", "v1"),
293 wantKM: KeyMap{Map: map[string]string{}, Str: ""},
294 },
295 {
296 // A keyBuilder is found, and a single headers matches.
297 desc: "directPathMatch-SingleKey",
298 path: "/gBar/method1",
299 md: metadata.Pairs("n1", "v1"),
300 wantKM: KeyMap{Map: map[string]string{"k1": "v1"}, Str: "k1=v1"},
301 },
302 {
303 // A keyBuilder is found, and multiple headers match, but the first
304 // match is chosen.
305 desc: "directPathMatch-FirstMatchingKey",
306 path: "/gBar/method1",
307 md: metadata.Pairs("n2", "v2", "n1", "v1"),
308 wantKM: KeyMap{Map: map[string]string{"k1": "v1"}, Str: "k1=v1"},
309 },
310 {
311 // A keyBuilder is found as a wildcard match, but none of the
312 // headers match.
313 desc: "wildcardPathMatch-NoMatchingKey",
314 path: "/gFoobar/method1",
315 md: metadata.Pairs("notMatchingKey", "v1"),
316 wantKM: KeyMap{Map: map[string]string{}, Str: ""},
317 },

Callers

nothing calls this directly

Calls 6

PairsFunction · 0.92
MakeBuilderMapFunction · 0.85
RLSKeyMethod · 0.80
FatalfMethod · 0.65
EqualMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected