|
@@ -0,0 +1,38 @@
|
|
1
|
+package isokit
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "context"
|
|
5
|
+ "reflect"
|
|
6
|
+ "testing"
|
|
7
|
+)
|
|
8
|
+
|
|
9
|
+func TestNewRoute(t *testing.T) {
|
|
10
|
+ handler := func(ctx context.Context) {}
|
|
11
|
+
|
|
12
|
+ testCases := map[string]struct {
|
|
13
|
+ path string
|
|
14
|
+ expectedVars []string
|
|
15
|
+ }{
|
|
16
|
+ "Without vars": {
|
|
17
|
+ "/this/is/a/path",
|
|
18
|
+ []string(nil),
|
|
19
|
+ },
|
|
20
|
+ "Single var": {
|
|
21
|
+ "/this/{firstVar}/is/a/path",
|
|
22
|
+ []string{"firstVar"},
|
|
23
|
+ },
|
|
24
|
+ "Multiple vars": {
|
|
25
|
+ "/this/is/{firstVar}/a/{secondVar}/path",
|
|
26
|
+ []string{"firstVar", "secondVar"},
|
|
27
|
+ },
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ for title, tc := range testCases {
|
|
31
|
+ t.Run(title, func(t *testing.T) {
|
|
32
|
+ r := NewRoute(tc.path, handler)
|
|
33
|
+ if !reflect.DeepEqual(r.varNames, tc.expectedVars) {
|
|
34
|
+ t.Errorf("wrong vars: expected %#v, got %#v", tc.expectedVars, r.varNames)
|
|
35
|
+ }
|
|
36
|
+ })
|
|
37
|
+ }
|
|
38
|
+}
|