Skip to content

Commit

Permalink
test for v3 to handle properly URL Paths, relates to #81
Browse files Browse the repository at this point in the history
  • Loading branch information
igm committed May 23, 2020
1 parent 50a6500 commit 2a32144
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions v3/sockjs/handler_test.go
Expand Up @@ -8,6 +8,9 @@ import (
"net/url"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var testOptions = DefaultOptions
Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit 2a32144

Please sign in to comment.