-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathserver_test.go
75 lines (71 loc) · 1.43 KB
/
server_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package server
import (
"context"
"net/http"
"testing"
"github.com/bouk/httprouter"
)
// WithContext is a helper function to cut down on boilerplate in server test files
func WithContext(ctx context.Context, r *http.Request, kv map[string]string) *http.Request {
params := make(httprouter.Params, 0, len(kv))
for k, v := range kv {
params = append(params, httprouter.Param{
Key: k,
Value: v,
})
}
return r.WithContext(httprouter.WithParams(ctx, params))
}
func Test_validBasepath(t *testing.T) {
type args struct {
basepath string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Basepath can be empty",
args: args{
basepath: "",
},
want: true,
},
{
name: "Basepath is not empty and valid",
args: args{
basepath: "/russ",
},
want: true,
},
{
name: "Basepath can include numbers, hyphens, and underscores",
args: args{
basepath: "/3shishka-bob/-rus4s_rus-1_s-",
},
want: true,
},
{
name: "Basepath is not empty and invalid - no slashes",
args: args{
basepath: "russ",
},
want: false,
},
{
name: "Basepath is not empty and invalid - extra slashes",
args: args{
basepath: "//russ//",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := validBasepath(tt.args.basepath); got != tt.want {
t.Errorf("validBasepath() = %v, want %v", got, tt.want)
}
})
}
}