Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests #556

Merged
merged 6 commits into from
Jun 1, 2022
41 changes: 40 additions & 1 deletion routers/gorillamux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,22 @@ func TestServerPath(t *testing.T) {
_, err = NewRouter(&openapi3.T{Servers: openapi3.Servers{
server,
&openapi3.Server{URL: "http://example.com/"},
&openapi3.Server{URL: "http://example.com/path"}},
&openapi3.Server{URL: "http://example.com/path"},
newServerWithVariables(
"{scheme}://localhost",
map[string]string{
"scheme": "https",
}),
newServerWithVariables(
"{url}",
map[string]string{
"url": "http://example.com/path",
}),
newServerWithVariables(
"http://example.com:{port}/path",
map[string]string{
"port": "8088",
})},
})
require.NoError(t, err)
}
Expand Down Expand Up @@ -268,3 +283,27 @@ func TestRelativeURL(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "/hello", route.Path)
}

func newServerWithVariables(url string, variables map[string]string) *openapi3.Server {
var serverVariables = map[string]*openapi3.ServerVariable{}

for key, value := range variables {
serverVariables[key] = newServerVariable(value)
}

return &openapi3.Server{
ExtensionProps: openapi3.ExtensionProps{},
URL: url,
Description: "",
Variables: serverVariables,
}
}

func newServerVariable(defaultValue string) *openapi3.ServerVariable {
return &openapi3.ServerVariable{
ExtensionProps: openapi3.ExtensionProps{},
Enum: nil,
Default: defaultValue,
Description: "",
}
}