Skip to content

Commit

Permalink
Add tests for referencedDocumentPath
Browse files Browse the repository at this point in the history
  • Loading branch information
kshlm committed Sep 3, 2020
1 parent 673b8bf commit 33ca746
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions openapi3/swagger_loader_referenced_document_path_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package openapi3

import (
"net/url"
"testing"

"github.com/stretchr/testify/require"
)

func TestReferencedDocumentPath(t *testing.T) {
httpURL, err := url.Parse("http://example.com/path/to/schemas/test1.yaml")
if err != nil {
panic(err)
}
fileURL, err := url.Parse("path/to/schemas/test1.yaml")
if err != nil {
panic(err)
}
refEmpty := ""
refNoComponent := "moreschemas/test2.yaml"
refWithComponent := "moreschemas/test2.yaml#/components/schemas/someobject"

for _, test := range []struct {
path *url.URL
ref, expected string
}{
{
path: httpURL,
ref: refEmpty,
expected: "http://example.com/path/to/schemas/",
},
{
path: httpURL,
ref: refNoComponent,
expected: "http://example.com/path/to/schemas/moreschemas/",
},
{
path: httpURL,
ref: refWithComponent,
expected: "http://example.com/path/to/schemas/moreschemas/",
},
{
path: fileURL,
ref: refEmpty,
expected: "path/to/schemas/",
},
{
path: fileURL,
ref: refNoComponent,
expected: "path/to/schemas/moreschemas/",
},
{
path: fileURL,
ref: refWithComponent,
expected: "path/to/schemas/moreschemas/",
},
} {
result, err := referencedDocumentPath(test.path, test.ref)
require.NotNil(t, result)
require.Nil(t, err)
require.Equal(t, test.expected, result.String())
}
}

0 comments on commit 33ca746

Please sign in to comment.