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
32 changes: 16 additions & 16 deletions circular_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func TestExpandCircular_Issue3(t *testing.T) {
jazon, root := expandThisOrDieTrying(t, "fixtures/expansion/overflow.json")
jazon, root := expandThisOrDieTrying(t, "testdata/expansion/overflow.json")
require.NotEmpty(t, jazon)

// circular $ref point to the expanded root document
Expand All @@ -30,7 +30,7 @@ func TestExpandCircular_Issue3(t *testing.T) {
}

func TestExpandCircular_RefExpansion(t *testing.T) {
basePath := filepath.Join("fixtures", "expansion", "circularRefs.json")
basePath := filepath.Join("testdata", "expansion", "circularRefs.json")

carsDoc, err := jsonDoc(basePath)
require.NoError(t, err)
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestExpandCircular_RefExpansion(t *testing.T) {
func TestExpandCircular_Spec2Expansion(t *testing.T) {
// TODO: assert repeatable results (see commented section below)

fixturePath := filepath.Join("fixtures", "expansion", "circular-minimal.json")
fixturePath := filepath.Join("testdata", "expansion", "circular-minimal.json")
jazon, root := expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)

Expand All @@ -75,7 +75,7 @@ func TestExpandCircular_Spec2Expansion(t *testing.T) {
assert.StringNotContainsTf(t, jazon, "circular-minimal.json#/",
"expected %s to be expanded with stripped circular $ref", fixturePath)

fixturePath = filepath.Join("fixtures", "expansion", "circularSpec2.json")
fixturePath = filepath.Join("testdata", "expansion", "circularSpec2.json")
jazon, root = expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)

Expand Down Expand Up @@ -121,33 +121,33 @@ func TestExpandCircular_MoreCircular(t *testing.T) {
// - with circular in a schema in #/responses
// - with circular in a schema in #/parameters

fixturePath := filepath.Join("fixtures", "more_circulars", "spec.json")
fixturePath := filepath.Join("testdata", "more_circulars", "spec.json")
jazon, root := expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)
assertRefInJSON(t, jazon, "item.json#/item")
assertRefResolve(t, jazon, "", root, &ExpandOptions{RelativeBase: fixturePath})

fixturePath = filepath.Join("fixtures", "more_circulars", "spec2.json")
fixturePath = filepath.Join("testdata", "more_circulars", "spec2.json")
jazon, root = expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)
assertRefInJSON(t, jazon, "item2.json#/item")
assertRefResolve(t, jazon, "", root, &ExpandOptions{RelativeBase: fixturePath})

fixturePath = filepath.Join("fixtures", "more_circulars", "spec3.json")
fixturePath = filepath.Join("testdata", "more_circulars", "spec3.json")
jazon, root = expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)
assertRefInJSON(t, jazon, "item.json#/item")
assertRefResolve(t, jazon, "", root, &ExpandOptions{RelativeBase: fixturePath})

fixturePath = filepath.Join("fixtures", "more_circulars", "spec4.json")
fixturePath = filepath.Join("testdata", "more_circulars", "spec4.json")
jazon, root = expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)
assertRefInJSON(t, jazon, "item4.json#/item")
assertRefResolve(t, jazon, "", root, &ExpandOptions{RelativeBase: fixturePath})
}

func TestExpandCircular_Issue957(t *testing.T) {
fixturePath := filepath.Join("fixtures", "bugs", "957", "fixture-957.json")
fixturePath := filepath.Join("testdata", "bugs", "957", "fixture-957.json")
jazon, root := expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)

Expand All @@ -164,7 +164,7 @@ func TestExpandCircular_Issue957(t *testing.T) {
func TestExpandCircular_Bitbucket(t *testing.T) {
// Additional testcase for circular $ref (from bitbucket api)

fixturePath := filepath.Join("fixtures", "more_circulars", "bitbucket.json")
fixturePath := filepath.Join("testdata", "more_circulars", "bitbucket.json")
jazon, root := expandThisOrDieTrying(t, fixturePath)
require.NotEmpty(t, jazon)

Expand All @@ -177,7 +177,7 @@ func TestExpandCircular_Bitbucket(t *testing.T) {

func TestExpandCircular_ResponseWithRoot(t *testing.T) {
rootDoc := new(Swagger)
b, err := os.ReadFile(filepath.Join("fixtures", "more_circulars", "resp.json"))
b, err := os.ReadFile(filepath.Join("testdata", "more_circulars", "resp.json"))
require.NoError(t, err)

require.NoError(t, json.Unmarshal(b, rootDoc))
Expand All @@ -202,7 +202,7 @@ func TestExpandCircular_ResponseWithRoot(t *testing.T) {
}

func TestExpandCircular_Issue415(t *testing.T) {
jazon, root := expandThisOrDieTrying(t, filepath.Join("fixtures", "expansion", "clickmeter.json"))
jazon, root := expandThisOrDieTrying(t, filepath.Join("testdata", "expansion", "clickmeter.json"))
require.NotEmpty(t, jazon)

assertRefInJSON(t, jazon, "#/definitions/")
Expand All @@ -211,7 +211,7 @@ func TestExpandCircular_Issue415(t *testing.T) {
}

func TestExpandCircular_SpecExpansion(t *testing.T) {
jazon, root := expandThisOrDieTrying(t, filepath.Join("fixtures", "expansion", "circularSpec.json"))
jazon, root := expandThisOrDieTrying(t, filepath.Join("testdata", "expansion", "circularSpec.json"))
require.NotEmpty(t, jazon)

assertRefInJSON(t, jazon, "#/definitions/Book")
Expand All @@ -221,7 +221,7 @@ func TestExpandCircular_SpecExpansion(t *testing.T) {

func TestExpandCircular_RemoteCircularID(t *testing.T) {
go func() {
err := http.ListenAndServe("localhost:1234", http.FileServer(http.Dir("fixtures/more_circulars/remote"))) //#nosec
err := http.ListenAndServe("localhost:1234", http.FileServer(http.Dir("testdata/more_circulars/remote"))) //#nosec
if err != nil {
panic(err.Error())
}
Expand All @@ -241,7 +241,7 @@ func TestExpandCircular_RemoteCircularID(t *testing.T) {
assertRefInJSONRegexp(t, jazon, "^http://localhost:1234/tree$") // $ref now point to the root doc

// a spec using the previous circular schema
fixtureSpecPath := filepath.Join("fixtures", "more_circulars", "with-id.json")
fixtureSpecPath := filepath.Join("testdata", "more_circulars", "with-id.json")
jazon, doc := expandThisOrDieTrying(t, fixtureSpecPath)

assertRefInJSON(t, jazon, fixturePath) // all remaining $ref's point to the circular ID (http://...)
Expand All @@ -254,7 +254,7 @@ func TestExpandCircular_RemoteCircularID(t *testing.T) {
func TestCircular_RemoteExpandAzure(t *testing.T) {
// local copy of Azure publicIpAddress.json from azure-rest-api-specs
// (Microsoft.Network/stable/2020-04-01)
server := fixtureServer(t, "fixtures/azure")
server := fixtureServer(t, "testdata/azure")

basePath := server.URL + "/publicIpAddress.json"
jazon, sch := expandThisOrDieTrying(t, basePath)
Expand Down
44 changes: 22 additions & 22 deletions expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import (
)

const (
crossFileRefFixture = "fixtures/expansion/crossFileRef.json"
crossFileRefFixture = "testdata/expansion/crossFileRef.json"
withoutSchemaID = "removed"
withSchemaID = "schema"
pathItemsFixture = "fixtures/expansion/pathItems.json"
extraRefFixture = "fixtures/expansion/extraRef.json"
pathItemsFixture = "testdata/expansion/pathItems.json"
extraRefFixture = "testdata/expansion/extraRef.json"
)

//nolint:gochecknoglobals // it's okay to have embedded test fixtures as globals
var (
//go:embed all:fixtures
//go:embed all:testdata
fixtureAssets embed.FS

// PetStore20 json doc for swagger 2.0 pet store.
Expand All @@ -40,32 +40,32 @@ var (
expectedExtraRef []byte
expectedPathItem []byte

specs = filepath.Join("fixtures", "specs")
specs = filepath.Join("testdata", "specs")
)

func init() { //nolint:gochecknoinits // it's okay to load embedded fixtures in init().
// load embedded fixtures

var err error
PetStore20, err = fixtureAssets.ReadFile("fixtures/expansion/petstore2.0.json")
PetStore20, err = fixtureAssets.ReadFile("testdata/expansion/petstore2.0.json")
if err != nil {
panic(fmt.Sprintf("could not find fixture: %v", err))
}
PetStoreJSONMessage = json.RawMessage(PetStore20)

expectedExtraRef, err = fixtureAssets.ReadFile("fixtures/expansion/expectedExtraRef.json")
expectedExtraRef, err = fixtureAssets.ReadFile("testdata/expansion/expectedExtraRef.json")
if err != nil {
panic(fmt.Sprintf("could not find fixture: %v", err))
}

expectedPathItem, err = fixtureAssets.ReadFile("fixtures/expansion/expectedPathItem.json")
expectedPathItem, err = fixtureAssets.ReadFile("testdata/expansion/expectedPathItem.json")
if err != nil {
panic(fmt.Sprintf("could not find fixture: %v", err))
}
}

func TestExpand_Issue148(t *testing.T) {
fp := filepath.Join("fixtures", "bugs", "schema-148.json")
fp := filepath.Join("testdata", "bugs", "schema-148.json")
b, err := jsonDoc(fp)
require.NoError(t, err)

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestExpand_KnownRef(t *testing.T) {
}

func TestExpand_ResponseSchema(t *testing.T) {
fp := filepath.Join("fixtures", "local_expansion", "spec.json")
fp := filepath.Join("testdata", "local_expansion", "spec.json")
b, err := jsonDoc(fp)
require.NoError(t, err)

Expand Down Expand Up @@ -152,7 +152,7 @@ func TestExpand_EmptySpec(t *testing.T) {

func TestExpand_Spec(t *testing.T) {
// expansion of a rich spec
specPath := filepath.Join("fixtures", "expansion", "all-the-things.json")
specPath := filepath.Join("testdata", "expansion", "all-the-things.json")
specDoc, err := jsonDoc(specPath)
require.NoError(t, err)

Expand Down Expand Up @@ -199,7 +199,7 @@ func TestExpand_Spec(t *testing.T) {
}

func TestExpand_InternalResponse(t *testing.T) {
basePath := normalizeBase(filepath.Join("fixtures", "expansion", "all-the-things.json"))
basePath := normalizeBase(filepath.Join("testdata", "expansion", "all-the-things.json"))
specDoc, err := jsonDoc(basePath)
require.NoError(t, err)

Expand Down Expand Up @@ -261,7 +261,7 @@ func TestExpand_InternalResponse(t *testing.T) {
}

func TestExpand_Response(t *testing.T) {
basePath := filepath.Join("fixtures", "expansion", "all-the-things.json")
basePath := filepath.Join("testdata", "expansion", "all-the-things.json")

specDoc, err := jsonDoc(basePath)
require.NoError(t, err)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestExpand_Response(t *testing.T) {
}

func TestExpand_ResponseAndParamWithRoot(t *testing.T) {
specDoc, err := jsonDoc("fixtures/bugs/1614/gitea.json")
specDoc, err := jsonDoc("testdata/bugs/1614/gitea.json")
require.NoError(t, err)

var spec Swagger
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestExpand_ResponseAndParamWithRoot(t *testing.T) {
}

func TestExpand_InternalParameter(t *testing.T) {
basePath := normalizeBase(filepath.Join("fixtures", "expansion", "params.json"))
basePath := normalizeBase(filepath.Join("testdata", "expansion", "params.json"))

paramDoc, err := jsonDoc(basePath)
require.NoError(t, err)
Expand All @@ -346,7 +346,7 @@ func TestExpand_InternalParameter(t *testing.T) {
}

func TestExpand_Parameter(t *testing.T) {
basePath := filepath.Join("fixtures", "expansion", "params.json")
basePath := filepath.Join("testdata", "expansion", "params.json")

paramDoc, err := jsonDoc(basePath)
require.NoError(t, err)
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestExpand_SwaggerSchema(t *testing.T) {
}

func TestExpand_ContinueOnError(t *testing.T) {
specPath := filepath.Join("fixtures", "expansion", "missingRef.json")
specPath := filepath.Join("testdata", "expansion", "missingRef.json")

defer log.SetOutput(os.Stdout)
log.SetOutput(io.Discard)
Expand All @@ -422,7 +422,7 @@ func TestExpand_ContinueOnError(t *testing.T) {
assert.Equal(t, testCase.Expected, testCase.Input, "Should continue expanding spec when a definition can't be found.")

// missing $ref in items
doc, err := jsonDoc("fixtures/expansion/missingItemRef.json")
doc, err := jsonDoc("testdata/expansion/missingItemRef.json")
require.NoError(t, err)

spec := new(Swagger)
Expand All @@ -434,7 +434,7 @@ func TestExpand_ContinueOnError(t *testing.T) {
}

func TestExpand_InternalSchemas2(t *testing.T) {
basePath := normalizeBase(filepath.Join("fixtures", "expansion", "schemas2.json"))
basePath := normalizeBase(filepath.Join("testdata", "expansion", "schemas2.json"))

carsDoc, err := jsonDoc(basePath)
require.NoError(t, err)
Expand Down Expand Up @@ -597,7 +597,7 @@ func TestExpand_InternalSchemas2(t *testing.T) {
}

func TestExpand_InternalSchemas1(t *testing.T) {
basePath := normalizeBase(filepath.Join("fixtures", "expansion", "schemas1.json"))
basePath := normalizeBase(filepath.Join("testdata", "expansion", "schemas1.json"))

carsDoc, err := jsonDoc(basePath)
require.NoError(t, err)
Expand Down Expand Up @@ -749,14 +749,14 @@ func TestExpand_InternalSchemas1(t *testing.T) {
}

func TestExpand_RelativeBaseURI(t *testing.T) {
server := fixtureServer(t, "fixtures/remote")
server := fixtureServer(t, "testdata/remote")

spec := new(Swagger)

require.NoError(t, ExpandSpec(spec, nil))

// this a spec on local fs...
specDoc, err := jsonDoc("fixtures/remote/all-the-things.json")
specDoc, err := jsonDoc("testdata/remote/all-the-things.json")
require.NoError(t, err)

spec = new(Swagger)
Expand Down
6 changes: 3 additions & 3 deletions resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestResolveRef(t *testing.T) {
}

func TestResolveResponse(t *testing.T) {
specDoc, err := jsonDoc(filepath.Join("fixtures", "expansion", "all-the-things.json"))
specDoc, err := jsonDoc(filepath.Join("testdata", "expansion", "all-the-things.json"))
require.NoError(t, err)

spec := new(Swagger)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestResolveResponseWithBase(t *testing.T) {
}

func TestResolveParam(t *testing.T) {
specDoc, err := jsonDoc(filepath.Join("fixtures", "expansion", "all-the-things.json"))
specDoc, err := jsonDoc(filepath.Join("testdata", "expansion", "all-the-things.json"))
require.NoError(t, err)

var spec Swagger
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestResolveRemoteRef_FromInvalidFragment(t *testing.T) {
// defer server.Close()
//
// rootDoc := new(Swagger)
// b, err := os.ReadFile("fixtures/specs/refed.json")
// b, err := os.ReadFile("testdata/specs/refed.json")
// require.NoError(t, err) && assert.NoError(t, json.Unmarshal(b, rootDoc))
//
// var tgt Schema
Expand Down
4 changes: 2 additions & 2 deletions schema_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestLoader_Issue145(t *testing.T) {
t.Run("with ExpandSpec", func(t *testing.T) {
basePath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "todos.json")
basePath := filepath.Join("testdata", "bugs", "145", "Program Files (x86)", "AppName", "todos.json")
todosDoc, err := jsonDoc(basePath)
require.NoError(t, err)

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

t.Run("with ExpandSchema", func(t *testing.T) {
basePath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "ref.json")
basePath := filepath.Join("testdata", "bugs", "145", "Program Files (x86)", "AppName", "ref.json")
schemaDoc, err := jsonDoc(basePath)
require.NoError(t, err)

Expand Down
Loading
Loading