(t *testing.T)
| 59 | ) |
| 60 | |
| 61 | func TestMakeBuilderMap(t *testing.T) { |
| 62 | gFooBuilder := builder{ |
| 63 | headerKeys: []matcher{{key: "k1", names: []string{"n1"}}, {key: "k2", names: []string{"n1"}}}, |
| 64 | constantKeys: map[string]string{ |
| 65 | "const-key-1": "const-val-1", |
| 66 | "const-key-2": "const-val-2", |
| 67 | }, |
| 68 | hostKey: "host", |
| 69 | serviceKey: "service", |
| 70 | methodKey: "method", |
| 71 | } |
| 72 | wantBuilderMap1 := map[string]builder{"/gFoo/": gFooBuilder} |
| 73 | wantBuilderMap2 := map[string]builder{ |
| 74 | "/gFoo/": gFooBuilder, |
| 75 | "/gBar/method1": {headerKeys: []matcher{{key: "k1", names: []string{"n1", "n2"}}}}, |
| 76 | "/gFoobar/": {headerKeys: []matcher{{key: "k1", names: []string{"n1", "n2"}}}}, |
| 77 | } |
| 78 | |
| 79 | tests := []struct { |
| 80 | desc string |
| 81 | cfg *rlspb.RouteLookupConfig |
| 82 | wantBuilderMap BuilderMap |
| 83 | }{ |
| 84 | { |
| 85 | desc: "One good GrpcKeyBuilder", |
| 86 | cfg: &rlspb.RouteLookupConfig{ |
| 87 | GrpcKeybuilders: []*rlspb.GrpcKeyBuilder{goodKeyBuilder1}, |
| 88 | }, |
| 89 | wantBuilderMap: wantBuilderMap1, |
| 90 | }, |
| 91 | { |
| 92 | desc: "Two good GrpcKeyBuilders", |
| 93 | cfg: &rlspb.RouteLookupConfig{ |
| 94 | GrpcKeybuilders: []*rlspb.GrpcKeyBuilder{goodKeyBuilder1, goodKeyBuilder2}, |
| 95 | }, |
| 96 | wantBuilderMap: wantBuilderMap2, |
| 97 | }, |
| 98 | } |
| 99 | |
| 100 | for _, test := range tests { |
| 101 | t.Run(test.desc, func(t *testing.T) { |
| 102 | builderMap, err := MakeBuilderMap(test.cfg) |
| 103 | if err != nil || !builderMap.Equal(test.wantBuilderMap) { |
| 104 | t.Errorf("MakeBuilderMap(%+v) returned {%v, %v}, want: {%v, nil}", test.cfg, builderMap, err, test.wantBuilderMap) |
| 105 | } |
| 106 | }) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | func TestMakeBuilderMapErrors(t *testing.T) { |
| 111 | tests := []struct { |
nothing calls this directly
no test coverage detected