@@ -164,3 +164,70 @@ func TestRoutingCombosFull(t *testing.T) {
164164 t .Errorf ("Incorrect routing combos (-want, +got):\n %s" , diff )
165165 }
166166}
167+
168+ func TestRoutingInfoVarianFieldName (t * testing.T ) {
169+ variant := & RoutingInfoVariant {
170+ FieldPath : []string {"request" , "b" , "c" },
171+ }
172+ got := variant .FieldName ()
173+ want := "request.b.c"
174+ if got != want {
175+ t .Errorf ("mismatch in FieldName got=%q, want=%q" , got , want )
176+ }
177+ }
178+
179+ func TestRoutingInfoVariantTemplateAsString (t * testing.T ) {
180+ variant := & RoutingInfoVariant {
181+ Prefix : RoutingPathSpec {
182+ Segments : []string {"a" , "b" , "c" },
183+ },
184+ Matching : RoutingPathSpec {
185+ Segments : []string {"d" , "*" },
186+ },
187+ Suffix : RoutingPathSpec {
188+ Segments : []string {"e" , "**" },
189+ },
190+ }
191+ got := variant .TemplateAsString ()
192+ want := "a/b/c/d/*/e/**"
193+ if got != want {
194+ t .Errorf ("mismatch in TemplateAsString got=%q, want=%q" , got , want )
195+ }
196+ }
197+
198+ func TestPathTemplateBuilder (t * testing.T ) {
199+ got := NewPathTemplate ().
200+ WithLiteral ("v1" ).
201+ WithVariable (NewPathVariable ("parent" , "child" ).
202+ WithLiteral ("projects" ).
203+ WithMatch ().
204+ WithLiteral ("locations" ).
205+ WithMatchRecursive ()).
206+ WithVariableNamed ("v2" , "field" ).
207+ WithVerb ("verb" )
208+ name := "v1"
209+ verb := "verb"
210+ want := & PathTemplate {
211+ Segments : []PathSegment {
212+ {
213+ Literal : & name ,
214+ },
215+ {
216+ Variable : & PathVariable {
217+ FieldPath : []string {"parent" , "child" },
218+ Segments : []string {"projects" , "*" , "locations" , "**" },
219+ },
220+ },
221+ {
222+ Variable : & PathVariable {
223+ FieldPath : []string {"v2" , "field" },
224+ Segments : []string {"*" },
225+ },
226+ },
227+ },
228+ Verb : & verb ,
229+ }
230+ if diff := cmp .Diff (want , got ); diff != "" {
231+ t .Errorf ("bad builder result (-want, +got):\n %s" , diff )
232+ }
233+ }
0 commit comments