MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestParse

Function TestParse

internal/httprule/parse_test.go:293–345  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

291}
292
293func TestParse(t *testing.T) {
294 for _, spec := range []struct {
295 input string
296 wantFields []string
297 wantOpCodes []int
298 wantPool []string
299 wantVerb string
300 }{
301 {
302 input: "/v1/{name}:bla:baa",
303 wantFields: []string{
304 "name",
305 },
306 wantPool: []string{"v1", "name"},
307 wantVerb: "bla:baa",
308 },
309 {
310 input: "/v1/{name}:",
311 wantFields: []string{
312 "name",
313 },
314 wantPool: []string{"v1", "name"},
315 wantVerb: "",
316 },
317 {
318 input: "/v1/{name=segment/wi:th}",
319 wantFields: []string{
320 "name",
321 },
322 wantPool: []string{"v1", "segment", "wi:th", "name"},
323 wantVerb: "",
324 },
325 } {
326 f, err := Parse(spec.input)
327 if err != nil {
328 t.Errorf("Parse(%q) failed with %v; want success", spec.input, err)
329 continue
330 }
331 tmpl := f.Compile()
332 if !reflect.DeepEqual(tmpl.Fields, spec.wantFields) {
333 t.Errorf("Parse(%q).Fields = %#v; want %#v", spec.input, tmpl.Fields, spec.wantFields)
334 }
335 if !reflect.DeepEqual(tmpl.Pool, spec.wantPool) {
336 t.Errorf("Parse(%q).Pool = %#v; want %#v", spec.input, tmpl.Pool, spec.wantPool)
337 }
338 if tmpl.Template != spec.input {
339 t.Errorf("Parse(%q).Template = %q; want %q", spec.input, tmpl.Template, spec.input)
340 }
341 if tmpl.Verb != spec.wantVerb {
342 t.Errorf("Parse(%q).Verb = %q; want %q", spec.input, tmpl.Verb, spec.wantVerb)
343 }
344 }
345}
346
347func TestParseError(t *testing.T) {
348 for _, spec := range []struct {

Callers

nothing calls this directly

Calls 2

ParseFunction · 0.85
CompileMethod · 0.65

Tested by

no test coverage detected