MCPcopy
hub / github.com/go-chi/chi / TestMuxHandlePatternValidation

Function TestMuxHandlePatternValidation

mux_test.go:642–732  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

640}
641
642func TestMuxHandlePatternValidation(t *testing.T) {
643 testCases := []struct {
644 name string
645 pattern string
646 method string
647 path string
648 expectedBody string
649 expectedStatus int
650 shouldPanic bool
651 }{
652 // Valid patterns
653 {
654 name: "Valid pattern without HTTP GET",
655 pattern: "/user/{id}",
656 shouldPanic: false,
657 method: "GET",
658 path: "/user/123",
659 expectedBody: "without-prefix GET",
660 expectedStatus: http.StatusOK,
661 },
662 {
663 name: "Valid pattern with HTTP POST",
664 pattern: "POST /products/{id}",
665 shouldPanic: false,
666 method: "POST",
667 path: "/products/456",
668 expectedBody: "with-prefix POST",
669 expectedStatus: http.StatusOK,
670 },
671 {
672 name: "Valid pattern with multiple whitespace after method",
673 pattern: "PATCH \t /",
674 shouldPanic: false,
675 method: "PATCH",
676 path: "/",
677 expectedBody: "extended-whitespace PATCH",
678 expectedStatus: http.StatusOK,
679 },
680 // Invalid patterns
681 {
682 name: "Invalid pattern with no method",
683 pattern: "INVALID/user/{id}",
684 shouldPanic: true,
685 },
686 {
687 name: "Invalid pattern with supported method",
688 pattern: "GET/user/{id}",
689 shouldPanic: true,
690 },
691 {
692 name: "Invalid pattern with unsupported method",
693 pattern: "UNSUPPORTED /unsupported-method",
694 shouldPanic: true,
695 },
696 }
697
698 for _, tc := range testCases {
699 t.Run(tc.name, func(t *testing.T) {

Callers

nothing calls this directly

Calls 7

HandleMethod · 0.95
HandleFuncMethod · 0.95
NewRouterFunction · 0.85
HandlerFuncMethod · 0.80
CloseMethod · 0.80
testRequestFunction · 0.70
WriteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…