diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-07-06 21:18:14 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-07-06 21:18:14 -0700 |
commit | 459bb4531f92f8663afb6f36aa9be5b789bd591f (patch) | |
tree | f14e6c06b8e5c63612d1ff36f8cab40ae8a99d20 /vendor/github.com/gorilla/mux/middleware_test.go | |
parent | 34a3fe426b33a63f2d8e02d4a70c88f137fa5410 (diff) |
Update vendor dependencies
Diffstat (limited to 'vendor/github.com/gorilla/mux/middleware_test.go')
-rw-r--r-- | vendor/github.com/gorilla/mux/middleware_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/gorilla/mux/middleware_test.go b/vendor/github.com/gorilla/mux/middleware_test.go index 93947e8..acf4e16 100644 --- a/vendor/github.com/gorilla/mux/middleware_test.go +++ b/vendor/github.com/gorilla/mux/middleware_test.go @@ -3,6 +3,7 @@ package mux import ( "bytes" "net/http" + "net/http/httptest" "testing" ) @@ -334,3 +335,43 @@ func TestMiddlewareMethodMismatchSubrouter(t *testing.T) { t.Fatal("Middleware was called for a method mismatch") } } + +func TestCORSMethodMiddleware(t *testing.T) { + router := NewRouter() + + cases := []struct { + path string + response string + method string + testURL string + expectedAllowedMethods string + }{ + {"/g/{o}", "a", "POST", "/g/asdf", "POST,PUT,GET,OPTIONS"}, + {"/g/{o}", "b", "PUT", "/g/bla", "POST,PUT,GET,OPTIONS"}, + {"/g/{o}", "c", "GET", "/g/orilla", "POST,PUT,GET,OPTIONS"}, + {"/g", "d", "POST", "/g", "POST,OPTIONS"}, + } + + for _, tt := range cases { + router.HandleFunc(tt.path, stringHandler(tt.response)).Methods(tt.method) + } + + router.Use(CORSMethodMiddleware(router)) + + for _, tt := range cases { + rr := httptest.NewRecorder() + req := newRequest(tt.method, tt.testURL) + + router.ServeHTTP(rr, req) + + if rr.Body.String() != tt.response { + t.Errorf("Expected body '%s', found '%s'", tt.response, rr.Body.String()) + } + + allowedMethods := rr.HeaderMap.Get("Access-Control-Allow-Methods") + + if allowedMethods != tt.expectedAllowedMethods { + t.Errorf("Expected Access-Control-Allow-Methods '%s', found '%s'", tt.expectedAllowedMethods, allowedMethods) + } + } +} |