Skip to content

Commit

Permalink
test: fix resolving tests due to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Nov 3, 2022
1 parent f49c3ac commit 994e59c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 121 deletions.
92 changes: 0 additions & 92 deletions cmd/ogen/main_test.go

This file was deleted.

2 changes: 2 additions & 0 deletions jsonschema/resolve_test.go
Expand Up @@ -3,6 +3,7 @@ package jsonschema
import (
"context"
"encoding/json"
"strings"
"testing"

"github.com/go-faster/errors"
Expand All @@ -16,6 +17,7 @@ import (
type external map[string]components

func (e external) Get(_ context.Context, loc string) ([]byte, error) {
loc = strings.TrimPrefix(loc, "/")
r, ok := e[loc]
if !ok {
return nil, errors.Errorf("unexpected location %q", loc)
Expand Down
37 changes: 8 additions & 29 deletions openapi/parser/resolve_external_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"net/http/httptest"
"net/url"
"path"
"strings"
"testing"

"github.com/go-faster/errors"
Expand All @@ -25,6 +26,7 @@ import (
type external map[string]any

func (e external) Get(_ context.Context, loc string) ([]byte, error) {
loc = strings.TrimPrefix(loc, "/")
r, ok := e[loc]
if !ok {
return nil, errors.Errorf("unexpected location %q", loc)
Expand Down Expand Up @@ -214,7 +216,7 @@ func TestExternalReference(t *testing.T) {
Examples: []jsonschema.Example{exampleValue},
}
localExample = &openapi.Example{
Ref: "#/components/examples/LocalExample",
Ref: "foo.json#/components/examples/RemoteExample",
Value: exampleValue,
}
param = &openapi.Parameter{
Expand All @@ -233,7 +235,7 @@ func TestExternalReference(t *testing.T) {
Schema: schema,
Examples: map[string]*openapi.Example{
"ref": {
Ref: "#/components/examples/LocalExample",
Ref: "foo.json#/components/examples/RemoteExample",
Value: exampleValue,
},
},
Expand Down Expand Up @@ -310,7 +312,10 @@ func TestExternalReference(t *testing.T) {
"LocalParameter": param,
},
Examples: map[string]*openapi.Example{
"LocalExample": localExample,
"LocalExample": {
Ref: "#/components/examples/LocalExample",
Value: exampleValue,
},
},
RequestBodies: map[string]*openapi.RequestBody{
"LocalRequestBody": requestBody,
Expand Down Expand Up @@ -464,30 +469,4 @@ func TestInitialLocation(t *testing.T) {
a.NoError(err)
check(a, parsed)
})
t.Run("File", func(t *testing.T) {
a := require.New(t)

rootURL := &url.URL{
Path: path.Join(rootPrefix, rootSpec),
}

var called []string
parsed, err := Parse(spec, Settings{
External: jsonschema.NewExternalResolver(jsonschema.ExternalOptions{
ReadFile: func(p string) ([]byte, error) {
called = append(called, p)
return fs.ReadFile(remotes, p)
},
}),
File: location.NewFile(rootSpec, rootURL.String(), raw),
RootURL: rootURL,
})
a.NoError(err)
a.Equal([]string{
"_testdata/remotes/api/response.json",
"_testdata/remotes/schemas.json",
}, called)

check(a, parsed)
})
}

0 comments on commit 994e59c

Please sign in to comment.