Skip to content

Commit

Permalink
address coverage
Browse files Browse the repository at this point in the history
Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Nov 17, 2023
1 parent 745142d commit b575284
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
59 changes: 59 additions & 0 deletions datamodel/low/base/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1756,3 +1756,62 @@ components:

assert.Equal(t, 3.0, res.Value.Schema().ExclusiveMaximum.Value.B)
}

func TestSchema_EmptyySchemaRef(t *testing.T) {
yml := `openapi: 3.0.3
components:
schemas:
Something:
$ref: ''`

var iNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &iNode)
assert.NoError(t, mErr)

config := index.CreateOpenAPIIndexConfig()
config.SpecInfo = &datamodel.SpecInfo{
VersionNumeric: 3.0,
}

idx := index.NewSpecIndexWithConfig(&iNode, config)

yml = `schema:
$ref: ''`

var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)

res, e := ExtractSchema(context.Background(), idxNode.Content[0], idx)
assert.Nil(t, res)
assert.Equal(t, "schema build failed: reference '[empty]' cannot be found at line 2, col 9", e.Error())

}

func TestSchema_EmptyRef(t *testing.T) {
yml := `openapi: 3.0.3
components:
schemas:
Something:
$ref: ''`

var iNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &iNode)
assert.NoError(t, mErr)

config := index.CreateOpenAPIIndexConfig()
config.SpecInfo = &datamodel.SpecInfo{
VersionNumeric: 3.0,
}

idx := index.NewSpecIndexWithConfig(&iNode, config)

yml = `$ref: ''`

var idxNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &idxNode)

res, e := ExtractSchema(context.Background(), idxNode.Content[0], idx)
assert.Nil(t, res)
assert.Equal(t, "schema build failed: reference '[empty]' cannot be found at line 1, col 7", e.Error())

}
14 changes: 14 additions & 0 deletions index/rolodex_remote_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ func TestNewRemoteFS_BasicCheck(t *testing.T) {
assert.Equal(t, "2015-10-21 07:28:00 +0000 GMT", lastMod.String())
}

func TestNewRemoteFS_BasicCheck_NoScheme(t *testing.T) {

server := test_buildServer()
defer server.Close()

remoteFS, _ := NewRemoteFSWithRootURL("")
remoteFS.RemoteHandlerFunc = test_httpClient.Get

file, err := remoteFS.Open("/file1.yaml")

assert.NoError(t, err)
assert.Nil(t, file)
}

func TestNewRemoteFS_BasicCheck_Relative(t *testing.T) {

server := test_buildServer()
Expand Down

0 comments on commit b575284

Please sign in to comment.