(t *testing.T)
| 634 | } |
| 635 | |
| 636 | func TestContext_PathParamDefault(t *testing.T) { |
| 637 | var testCases = []struct { |
| 638 | name string |
| 639 | given PathValues |
| 640 | whenParamName string |
| 641 | whenDefaultValue string |
| 642 | expect string |
| 643 | }{ |
| 644 | { |
| 645 | name: "param exists", |
| 646 | given: PathValues{ |
| 647 | {Name: "uid", Value: "101"}, |
| 648 | {Name: "fid", Value: "501"}, |
| 649 | }, |
| 650 | whenParamName: "uid", |
| 651 | whenDefaultValue: "999", |
| 652 | expect: "101", |
| 653 | }, |
| 654 | { |
| 655 | name: "param exists and is empty", |
| 656 | given: PathValues{ |
| 657 | {Name: "uid", Value: ""}, |
| 658 | {Name: "fid", Value: "501"}, |
| 659 | }, |
| 660 | whenParamName: "uid", |
| 661 | whenDefaultValue: "999", |
| 662 | expect: "", // <-- this is different from QueryParamOr behaviour |
| 663 | }, |
| 664 | { |
| 665 | name: "param does not exists", |
| 666 | given: PathValues{ |
| 667 | {Name: "uid", Value: "101"}, |
| 668 | }, |
| 669 | whenParamName: "nope", |
| 670 | whenDefaultValue: "999", |
| 671 | expect: "999", |
| 672 | }, |
| 673 | } |
| 674 | |
| 675 | for _, tc := range testCases { |
| 676 | t.Run(tc.name, func(t *testing.T) { |
| 677 | e := New() |
| 678 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 679 | c := e.NewContext(req, nil) |
| 680 | |
| 681 | c.SetPathValues(tc.given) |
| 682 | |
| 683 | assert.EqualValues(t, tc.expect, c.ParamOr(tc.whenParamName, tc.whenDefaultValue)) |
| 684 | }) |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | func TestContextGetAndSetPathValuesMutability(t *testing.T) { |
| 689 | t.Run("c.PathValues() does not return copy and modifying raw slice mutates value in context", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…