-
-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathapi_internal_test.go
More file actions
62 lines (58 loc) · 1.19 KB
/
Copy pathapi_internal_test.go
File metadata and controls
62 lines (58 loc) · 1.19 KB
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
package huma
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetServerURLWithDefaultVars(t *testing.T) {
tests := []struct {
name string
url string
vars map[string]*ServerVariable
expected string
}{
{
name: "AbsURL",
url: "http://localhost:{port}/api/{version}{ext}?{unknown_var}",
vars: map[string]*ServerVariable{
"port": {
Default: "8080",
},
"version": {
Enum: []string{"v1", "v2"},
},
"ext": {},
},
expected: "http://localhost:8080/api/v1?{unknown_var}",
},
{
name: "RelativeURL",
url: "/{basepath}/{version}",
vars: map[string]*ServerVariable{
"basepath": {
Default: "api",
},
"version": {
Default: "v2",
},
},
expected: "/api/v2",
},
{
name: "EmptyURL",
url: "",
expected: "",
},
{
name: "NoVars",
url: "http://localhost:{port}/api/{version}",
expected: "http://localhost:{port}/api/{version}",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
server := Server{URL: test.url, Variables: test.vars}
url := getServerURLWithDefaultVars(server)
assert.Equal(t, test.expected, url)
})
}
}