(t *testing.T)
| 585 | } |
| 586 | |
| 587 | func TestContext_PathParam(t *testing.T) { |
| 588 | var testCases = []struct { |
| 589 | name string |
| 590 | given PathValues |
| 591 | whenParamName string |
| 592 | expect string |
| 593 | }{ |
| 594 | { |
| 595 | name: "param exists", |
| 596 | given: PathValues{ |
| 597 | {Name: "uid", Value: "101"}, |
| 598 | {Name: "fid", Value: "501"}, |
| 599 | }, |
| 600 | whenParamName: "uid", |
| 601 | expect: "101", |
| 602 | }, |
| 603 | { |
| 604 | name: "multiple same param values exists - return first", |
| 605 | given: PathValues{ |
| 606 | {Name: "uid", Value: "101"}, |
| 607 | {Name: "uid", Value: "202"}, |
| 608 | {Name: "fid", Value: "501"}, |
| 609 | }, |
| 610 | whenParamName: "uid", |
| 611 | expect: "101", |
| 612 | }, |
| 613 | { |
| 614 | name: "param does not exists", |
| 615 | given: PathValues{ |
| 616 | {Name: "uid", Value: "101"}, |
| 617 | }, |
| 618 | whenParamName: "nope", |
| 619 | expect: "", |
| 620 | }, |
| 621 | } |
| 622 | |
| 623 | for _, tc := range testCases { |
| 624 | t.Run(tc.name, func(t *testing.T) { |
| 625 | e := New() |
| 626 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 627 | c := e.NewContext(req, nil) |
| 628 | |
| 629 | c.SetPathValues(tc.given) |
| 630 | |
| 631 | assert.EqualValues(t, tc.expect, c.Param(tc.whenParamName)) |
| 632 | }) |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | func TestContext_PathParamDefault(t *testing.T) { |
| 637 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…