(t *testing.T)
| 652 | } |
| 653 | |
| 654 | func TestHeaders(t *testing.T) { |
| 655 | // newRequestHeaders creates a new request with a method, url, and headers |
| 656 | newRequestHeaders := func(method, url string, headers map[string]string) *http.Request { |
| 657 | req, err := http.NewRequest(method, url, nil) |
| 658 | if err != nil { |
| 659 | panic(err) |
| 660 | } |
| 661 | for k, v := range headers { |
| 662 | req.Header.Add(k, v) |
| 663 | } |
| 664 | return req |
| 665 | } |
| 666 | |
| 667 | tests := []routeTest{ |
| 668 | { |
| 669 | title: "Headers route, match", |
| 670 | route: new(Route).Headers("foo", "bar", "baz", "ding"), |
| 671 | request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "bar", "baz": "ding"}), |
| 672 | vars: map[string]string{}, |
| 673 | host: "", |
| 674 | path: "", |
| 675 | shouldMatch: true, |
| 676 | }, |
| 677 | { |
| 678 | title: "Headers route, bad header values", |
| 679 | route: new(Route).Headers("foo", "bar", "baz", "ding"), |
| 680 | request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "bar", "baz": "dong"}), |
| 681 | vars: map[string]string{}, |
| 682 | host: "", |
| 683 | path: "", |
| 684 | shouldMatch: false, |
| 685 | }, |
| 686 | { |
| 687 | title: "Headers route, regex header values to match", |
| 688 | route: new(Route).HeadersRegexp("foo", "ba[zr]"), |
| 689 | request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "baw"}), |
| 690 | vars: map[string]string{}, |
| 691 | host: "", |
| 692 | path: "", |
| 693 | shouldMatch: false, |
| 694 | }, |
| 695 | { |
| 696 | title: "Headers route, regex header values to match", |
| 697 | route: new(Route).HeadersRegexp("foo", "ba[zr]"), |
| 698 | request: newRequestHeaders("GET", "http://localhost", map[string]string{"foo": "baz"}), |
| 699 | vars: map[string]string{}, |
| 700 | host: "", |
| 701 | path: "", |
| 702 | shouldMatch: true, |
| 703 | }, |
| 704 | } |
| 705 | |
| 706 | for _, test := range tests { |
| 707 | t.Run(test.title, func(t *testing.T) { |
| 708 | testRoute(t, test) |
| 709 | testTemplate(t, test) |
| 710 | }) |
| 711 | } |
nothing calls this directly
no test coverage detected