-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvalidator_test.go
More file actions
45 lines (37 loc) · 840 Bytes
/
validator_test.go
File metadata and controls
45 lines (37 loc) · 840 Bytes
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
45
package mux
import (
"fmt"
"strings"
"testing"
)
func TestMethodValidator(t *testing.T) {
validator := newMethodValidator()
for k := range methods {
t.Run(fmt.Sprintf("Method: %s", k), func(t *testing.T) {
r := &Route{
methodName: k,
}
if err := validator.Validate(r); err != nil {
t.Errorf("Unexpected invalid method (%s)", k)
}
})
}
}
func TestMethodValidatorFail(t *testing.T) {
validator := newMethodValidator()
r := &Route{
methodName: "GGET",
}
if err := validator.Validate(r); err == nil || !strings.Contains(err.Error(), "Method not vaild") {
t.Errorf("Unexpected valid method (%s)", r.methodName)
}
}
func BenchmarkMethodValidaor(b *testing.B) {
validator := newMethodValidator()
route := &Route{
methodName: "GET",
}
for n := 0; n < b.N; n++ {
validator.Validate(route)
}
}