-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapper_test.go
44 lines (37 loc) · 1.09 KB
/
mapper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package revisor
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSimpleMapper_New(t *testing.T) {
mapper := newSimpleMapper("", map[string][]string{
"GET": []string{"/path", "/path/{id}"},
})
assert.NotNil(t, mapper)
}
func TestSimpleMapper_MapRequest(t *testing.T) {
mapper := newSimpleMapper("", map[string][]string{
"GET": []string{"/path", "/path/{id}"},
})
mapper.router.Methods("OPTIONS")
tests := []struct {
name string
request *http.Request
tmpl string
isSet bool
}{
{"tmpl found", httptest.NewRequest("GET", "/path", nil), "/path", true},
{"tmpl root not configured", httptest.NewRequest("GET", "/", nil), "", false},
{"tmpl with parameter found", httptest.NewRequest("GET", "/path/resource-id", nil), "/path/{id}", true},
{"tmpl is not configured", httptest.NewRequest("OPTIONS", "/", nil), "", false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tmpl, _, ok := mapper.mapRequest(test.request)
assert.Equal(t, test.isSet, ok)
assert.Equal(t, test.tmpl, tmpl)
})
}
}