From 2a321445b0f6f59d66ff59322bbceb0880cad395 Mon Sep 17 00:00:00 2001 From: Igor Mihalik Date: Sat, 23 May 2020 20:23:36 +0200 Subject: [PATCH] test for v3 to handle properly URL Paths, relates to #81 --- v3/sockjs/handler_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/v3/sockjs/handler_test.go b/v3/sockjs/handler_test.go index 121bd19..6df8093 100644 --- a/v3/sockjs/handler_test.go +++ b/v3/sockjs/handler_test.go @@ -8,6 +8,9 @@ import ( "net/url" "testing" "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var testOptions = DefaultOptions @@ -122,3 +125,26 @@ func TestHandler_SessionByRequest(t *testing.T) { t.Errorf("Expected parser sessionID from URL error, got 'nil'") } } + +func TestHandler_StrictPathMatching(t *testing.T) { + handler := NewHandler("/echo", testOptions, nil) + server := httptest.NewServer(handler) + defer server.Close() + + cases := []struct { + url string + expectedStatus int + }{ + {url: "/echo", expectedStatus: http.StatusOK}, + {url: "/test/echo", expectedStatus: http.StatusNotFound}, + {url: "/echo/test/test/echo", expectedStatus: http.StatusNotFound}, + } + + for _, urlCase := range cases { + t.Run(urlCase.url, func(t *testing.T) { + resp, err := http.Get(server.URL + urlCase.url) + require.NoError(t, err) + assert.Equal(t, urlCase.expectedStatus, resp.StatusCode) + }) + } +}