-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_base_path_test.go
89 lines (83 loc) · 1.98 KB
/
add_base_path_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package op_handler
import (
"testing"
"github.com/danielgtaylor/huma/v2"
"github.com/stretchr/testify/require"
"github.com/cardinalby/hureg/pkg/huma/metadata"
)
func TestAddBasePath(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
opInitPath string
opBasePath string
opPath string
addBasePath string
expectedPath string
expectedBasePath any
}{
{
name: "[]/ to [abc]/",
opInitPath: "/",
opBasePath: "",
opPath: "/",
addBasePath: "/abc",
expectedPath: "/abc/",
expectedBasePath: "/abc",
},
{
name: "[abc]/ to [abc/def]/",
opInitPath: "/",
opBasePath: "/abc",
opPath: "/abc/",
addBasePath: "/def",
expectedPath: "/abc/def/",
expectedBasePath: "/abc/def",
},
{
name: "[a]/c to [a/b]/c",
opInitPath: "/c",
opBasePath: "/a",
opPath: "/a/c",
addBasePath: "/b",
expectedPath: "/a/b/c",
expectedBasePath: "/a/b",
},
{
name: "add empty base path",
opInitPath: "/b",
opBasePath: "/a",
opPath: "/a/b",
addBasePath: "",
expectedPath: "/a/b",
expectedBasePath: "/a",
},
{
name: "add slash base path",
opInitPath: "/b",
opBasePath: "/a",
opPath: "/a/b",
addBasePath: "/",
expectedPath: "/a/b",
expectedBasePath: "/a",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
op := huma.Operation{
Path: tc.opPath,
Metadata: map[string]interface{}{
metadata.KeyInitPath: tc.opInitPath,
},
}
if tc.opBasePath != "" {
op.Metadata[metadata.KeyBasePath] = tc.opBasePath
}
AddBasePath(tc.addBasePath)(&op)
require.Equal(t, tc.expectedPath, op.Path)
require.Equal(t, tc.expectedBasePath, op.Metadata[metadata.KeyBasePath])
})
}
}