Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"testing"
)

//go:embed fixtures/json/bench/header.partial
//go:embed testdata/json/bench/header.partial
var benchHeader []byte

//go:embed fixtures/json/bench/path-item.partial
//go:embed testdata/json/bench/path-item.partial
var benchPathItem []byte

//go:embed fixtures/json/bench/footer.partial
//go:embed testdata/json/bench/footer.partial
var benchFooter []byte

func BenchmarkAnalyzed(b *testing.B) {
Expand Down
6 changes: 3 additions & 3 deletions example_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ExampleSpec_restrictNetwork() {
// Use this when the convenient, opinionated defaults fit; reach for the manual options shown
// in the other examples when you need a custom policy.
func ExampleSpecRestricted() {
const root = "fixtures/yaml"
const root = "testdata/yaml"

// A document inside the trusted root loads normally.
doc, err := loads.SpecRestricted("swagger/spec.yml", root)
Expand Down Expand Up @@ -106,7 +106,7 @@ func ExampleSpecRestricted() {
// spec.PathLoader — is confined, with no unconfined fallback left behind. Prefer this to
// AddLoader, which only prepends and leaves the unconfined default reachable.
func ExampleSetRestrictedLoaders() {
loads.SetRestrictedLoaders("fixtures/yaml")
loads.SetRestrictedLoaders("testdata/yaml")
defer loads.SetLoaders() // restore the built-in default

doc, err := loads.Spec("swagger/spec.yml")
Expand All @@ -131,7 +131,7 @@ func ExampleSetRestrictedLoaders() {
// ".." traversal, or a symlink pointing outside. Passing it through [loads.WithLoadingOptions]
// makes the confinement apply to reference resolution as well.
func ExampleSpec_restrictFilesystem() {
const root = "fixtures/yaml"
const root = "testdata/yaml"

// A document inside the trusted root loads normally.
doc, err := loads.Spec("swagger/spec.yml", loads.WithLoadingOptions(loading.WithRoot(root)))
Expand Down
12 changes: 6 additions & 6 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
"github.com/go-openapi/swag/loading"
)

//go:embed fixtures
//go:embed testdata
var embeddedFixtures embed.FS

// Example with default loaders defined at the package level.
func ExampleSpec_file() {
path := "fixtures/yaml/swagger/spec.yml"
path := "testdata/yaml/swagger/spec.yml"
doc, err := loads.Spec(path)
if err != nil {
fmt.Println("Could not load this spec")
Expand All @@ -37,7 +37,7 @@ func ExampleSpec_file() {

// Example with custom loaders passed as options.
func ExampleLoaderOption() {
path := "fixtures/yaml/swagger/spec.yml"
path := "testdata/yaml/swagger/spec.yml"

// a simpler version of loads.JSONDoc
jsonLoader := loads.NewDocLoaderWithMatch(
Expand Down Expand Up @@ -143,7 +143,7 @@ func ExampleSpec_http_json() {
func ExampleSpec_embedded_yaml() {
// loads a YAML spec from a file on an embedded file system
doc, err := loads.Spec(
path.Join("fixtures", "yaml", "swagger", "spec.yml"), // [embed.FS] sep is "/" even on windows
path.Join("testdata", "yaml", "swagger", "spec.yml"), // [embed.FS] sep is "/" even on windows
loads.WithLoadingOptions(
loading.WithFS(embeddedFixtures),
))
Expand All @@ -165,7 +165,7 @@ func ExampleSpec_embedded_yaml() {
}

func serveSomeYAMLDocument() *httptest.Server {
source, err := os.Open(filepath.Join("fixtures", "yaml", "swagger", "spec.yml"))
source, err := os.Open(filepath.Join("testdata", "yaml", "swagger", "spec.yml"))
if err != nil {
panic(err)
}
Expand All @@ -177,7 +177,7 @@ func serveSomeYAMLDocument() *httptest.Server {
}

func serveSomeJSONDocument() *httptest.Server {
source, err := os.Open(filepath.Join("fixtures", "json", "resources", "pathLoaderIssue.json"))
source, err := os.Open(filepath.Join("testdata", "json", "resources", "pathLoaderIssue.json"))
if err != nil {
panic(err)
}
Expand Down
16 changes: 8 additions & 8 deletions fmts/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema any) b

func TestPropertyFixtures(t *testing.T) {
for _, extension := range extensions {
path := filepath.Join("..", "fixtures", extension, "models", "properties")
path := filepath.Join("..", "testdata", extension, "models", "properties")
files, err := os.ReadDir(path)
if err != nil {
t.Fatal(err)
Expand All @@ -130,7 +130,7 @@ func TestPropertyFixtures(t *testing.T) {

func TestAdditionalPropertiesWithObject(t *testing.T) {
schema := new(spec.Schema)
b, err := YAMLDoc("../fixtures/yaml/models/modelWithObjectMap.yaml")
b, err := YAMLDoc("../testdata/yaml/models/modelWithObjectMap.yaml")
require.NoError(t, err)

require.NoError(t, json.Unmarshal(b, schema))
Expand All @@ -139,7 +139,7 @@ func TestAdditionalPropertiesWithObject(t *testing.T) {
}

func TestModelFixtures(t *testing.T) {
path := filepath.Join("..", "fixtures", "json", "models")
path := filepath.Join("..", "testdata", "json", "models")
files, err := os.ReadDir(path)
require.NoError(t, err)
specs := []string{"modelWithObjectMap", "models", "modelWithComposition", "modelWithExamples", "multipleModels"}
Expand All @@ -156,7 +156,7 @@ FILES:
}
roundTripTest(t, "model", "json", filepath.Join(path, f.Name()), &spec.Schema{})
}
path = filepath.Join("..", "fixtures", "yaml", "models")
path = filepath.Join("..", "testdata", "yaml", "models")
files, err = os.ReadDir(path)
require.NoError(t, err)

Expand All @@ -176,7 +176,7 @@ YAMLFILES:
}

func TestParameterFixtures(t *testing.T) {
path := filepath.Join("..", "fixtures", "json", "resources", "parameters")
path := filepath.Join("..", "testdata", "json", "resources", "parameters")
files, err := os.ReadDir(path)
require.NoError(t, err)

Expand All @@ -186,7 +186,7 @@ func TestParameterFixtures(t *testing.T) {
}

func TestOperationFixtures(t *testing.T) {
path := filepath.Join("..", "fixtures", "json", "resources", "operations")
path := filepath.Join("..", "testdata", "json", "resources", "operations")
files, err := os.ReadDir(path)
require.NoError(t, err)

Expand All @@ -196,7 +196,7 @@ func TestOperationFixtures(t *testing.T) {
}

func TestResponseFixtures(t *testing.T) {
path := filepath.Join("..", "fixtures", "json", "responses")
path := filepath.Join("..", "testdata", "json", "responses")
files, err := os.ReadDir(path)
require.NoError(t, err)

Expand All @@ -210,7 +210,7 @@ func TestResponseFixtures(t *testing.T) {
}

func TestResourcesFixtures(t *testing.T) {
path := filepath.Join("..", "fixtures", "json", "resources")
path := filepath.Join("..", "testdata", "json", "resources")
files, err := os.ReadDir(path)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-openapi/testify/v2/require"
)

//go:embed fixtures/json/petstore.json
//go:embed testdata/json/petstore.json
var petstoreJSON []byte

func TestLoadJSON(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/go-openapi/testify/v2/require"
)

const optionFixture = "fixtures/json/resources/pathLoaderIssue.json"
const optionFixture = "testdata/json/resources/pathLoaderIssue.json"

var errTest = errors.New("test")

Expand Down
8 changes: 4 additions & 4 deletions restricted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestRestrictedHTTPClient(t *testing.T) {
}

func TestSpecRestricted(t *testing.T) {
const root = "fixtures/yaml"
const root = "testdata/yaml"

t.Run("should load a YAML spec within the root", func(t *testing.T) {
doc, err := loads.SpecRestricted("swagger/spec.yml", root)
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestSpecRestricted(t *testing.T) {
}

func TestJSONSpecRestricted(t *testing.T) {
const root = "fixtures/json"
const root = "testdata/json"

t.Run("should load a JSON spec within the root", func(t *testing.T) {
doc, err := loads.JSONSpecRestricted("petstore-basic.json", root)
Expand All @@ -112,7 +112,7 @@ func TestJSONSpecRestricted(t *testing.T) {
}

func TestJSONDocRestricted(t *testing.T) {
const root = "fixtures/json"
const root = "testdata/json"

t.Run("should load within the root", func(t *testing.T) {
ldr := loads.JSONDocRestricted(root)
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestJSONDocRestricted(t *testing.T) {
// document still loads from the registered root.
doc, err := loads.Spec("petstore-basic.json",
loads.WithDocLoader(loads.JSONDocRestricted(root)),
loads.WithLoadingOptions(loading.WithRoot("fixtures/yaml")),
loads.WithLoadingOptions(loading.WithRoot("testdata/yaml")),
)
require.NoError(t, err)
assert.Equal(t, "petstore.swagger.wordnik.com", doc.Host())
Expand Down
8 changes: 4 additions & 4 deletions set_loaders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSetLoaders(t *testing.T) {
var called bool
loads.SetLoaders(loads.NewDocLoaderWithMatch(customLoader(&called), nil)) // nil matcher: catch-all

doc, err := loads.Spec("fixtures/json/petstore-basic.json")
doc, err := loads.Spec("testdata/json/petstore-basic.json")
require.NoError(t, err)
assert.True(t, called, "the custom loader should be used")
assert.Equal(t, "petstore.swagger.wordnik.com", doc.Host())
Expand All @@ -46,15 +46,15 @@ func TestSetLoaders(t *testing.T) {
var called bool
loads.SetLoaders(loads.NewDocLoaderWithMatch(customLoader(&called), nil))

_, err := spec.PathLoader("fixtures/json/petstore-basic.json")
_, err := spec.PathLoader("testdata/json/petstore-basic.json")
require.NoError(t, err)
assert.True(t, called, "spec.PathLoader should use the new chain")
})

t.Run("should restore the built-in default when called with no usable loader", func(t *testing.T) {
loads.SetLoaders() // reset

doc, err := loads.Spec("fixtures/yaml/swagger/spec.yml")
doc, err := loads.Spec("testdata/yaml/swagger/spec.yml")
require.NoError(t, err)
assert.Equal(t, "api.example.com", doc.Host())
})
Expand All @@ -63,7 +63,7 @@ func TestSetLoaders(t *testing.T) {
func TestSetRestrictedLoaders(t *testing.T) {
t.Cleanup(func() { loads.SetLoaders() }) // restore the built-in default

loads.SetRestrictedLoaders("fixtures/yaml")
loads.SetRestrictedLoaders("testdata/yaml")

t.Run("should load a spec within the root via the package default", func(t *testing.T) {
doc, err := loads.Spec("swagger/spec.yml")
Expand Down
22 changes: 11 additions & 11 deletions spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
"github.com/go-openapi/testify/v2/require"
)

//go:embed fixtures/json/petstore-basic.json
//go:embed testdata/json/petstore-basic.json
var petStoreJSON []byte

//go:embed fixtures/yaml/search.yaml
//go:embed testdata/yaml/search.yaml
var yamlSpec []byte

//go:embed fixtures/json/expected-expanded.json
//go:embed testdata/json/expected-expanded.json
var expectedExpanded []byte

//go:embed fixtures/json/cascade-ref-expanded.json
//go:embed testdata/json/cascade-ref-expanded.json
var cascadeRefExpanded []byte

func TestUnknownSpecVersion(t *testing.T) {
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestLoadsYAMLContent(t *testing.T) {

// for issue #11.
func TestRegressionExpand(t *testing.T) {
swaggerFile := "fixtures/yaml/swagger/1/2/3/4/swagger.yaml"
swaggerFile := "testdata/yaml/swagger/1/2/3/4/swagger.yaml"
document, err := Spec(swaggerFile)
require.NoError(t, err)
require.NotNil(t, document)
Expand All @@ -65,7 +65,7 @@ func TestRegressionExpand(t *testing.T) {
}

func TestCascadingRefExpand(t *testing.T) {
swaggerFile := "fixtures/yaml/swagger/spec.yml"
swaggerFile := "testdata/yaml/swagger/spec.yml"
document, err := Spec(swaggerFile)
require.NoError(t, err)
require.NotNil(t, document)
Expand All @@ -85,7 +85,7 @@ func TestFailsInvalidJSON(t *testing.T) {

// issue go-swagger/go-swagger#1816 (regression when cloning original spec).
func TestIssue1846(t *testing.T) {
swaggerFile := "fixtures/bugs/1816/fixture-1816.yaml"
swaggerFile := "testdata/bugs/1816/fixture-1816.yaml"
document, err := Spec(swaggerFile)
require.NoError(t, err)
require.NotNil(t, document)
Expand All @@ -108,7 +108,7 @@ func TestIssue1846(t *testing.T) {
}

func TestEmbedded(t *testing.T) {
swaggerFile := "fixtures/yaml/swagger/spec.yml"
swaggerFile := "testdata/yaml/swagger/spec.yml"
document, err := Spec(swaggerFile)
require.NoError(t, err)
require.NotNil(t, document)
Expand Down Expand Up @@ -148,15 +148,15 @@ func TestDocument(t *testing.T) {
}

func TestSpecCircular(t *testing.T) {
swaggerFile := "fixtures/json/resources/pathLoaderIssue.json"
swaggerFile := "testdata/json/resources/pathLoaderIssue.json"
document, err := Spec(swaggerFile)
require.NoError(t, err)
require.NotNil(t, document)
}

func TestIssueSpec145(t *testing.T) {
t.Run("with remote $ref", func(t *testing.T) {
docPath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "todos.json")
docPath := filepath.Join("testdata", "bugs", "145", "Program Files (x86)", "AppName", "todos.json")

t.Run("with Spec loader", func(t *testing.T) {
document, err := Spec(docPath)
Expand All @@ -178,7 +178,7 @@ func TestIssueSpec145(t *testing.T) {
})

t.Run("with self-contained root", func(t *testing.T) {
docPath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "todos-expanded.json")
docPath := filepath.Join("testdata", "bugs", "145", "Program Files (x86)", "AppName", "todos-expanded.json")

t.Run("with Spec loader", func(t *testing.T) {
document, err := Spec(docPath)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading