MCPcopy Index your code
hub / github.com/labstack/echo / TestValuesFromParam

Function TestValuesFromParam

middleware/extractor_test.go:324–405  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

322}
323
324func TestValuesFromParam(t *testing.T) {
325 examplePathValues := echo.PathValues{
326 {Name: "id", Value: "123"},
327 {Name: "gid", Value: "456"},
328 {Name: "gid", Value: "789"},
329 }
330 examplePathValues20 := make(echo.PathValues, 0)
331 for i := 1; i < 25; i++ {
332 examplePathValues20 = append(examplePathValues20, echo.PathValue{Name: "id", Value: fmt.Sprintf("%v", i)})
333 }
334
335 var testCases = []struct {
336 name string
337 givenPathValues echo.PathValues
338 whenName string
339 whenLimit uint
340 expectValues []string
341 expectError string
342 }{
343 {
344 name: "ok, single value",
345 givenPathValues: examplePathValues,
346 whenName: "id",
347 expectValues: []string{"123"},
348 },
349 {
350 name: "ok, multiple value",
351 givenPathValues: examplePathValues,
352 whenName: "gid",
353 whenLimit: 2,
354 expectValues: []string{"456", "789"},
355 },
356 {
357 name: "nok, no values",
358 givenPathValues: nil,
359 whenName: "nope",
360 expectValues: nil,
361 expectError: errParamExtractorValueMissing.Error(),
362 },
363 {
364 name: "nok, no matching value",
365 givenPathValues: examplePathValues,
366 whenName: "nope",
367 expectValues: nil,
368 expectError: errParamExtractorValueMissing.Error(),
369 },
370 {
371 name: "ok, cut values over extractorLimit",
372 givenPathValues: examplePathValues20,
373 whenName: "id",
374 whenLimit: extractorLimit,
375 expectValues: []string{
376 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
377 "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
378 },
379 },
380 }
381

Callers

nothing calls this directly

Calls 4

SetPathValuesMethod · 0.95
valuesFromParamFunction · 0.85
NewContextMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…