Skip to content

Commit

Permalink
add additional test for covering file referece case
Browse files Browse the repository at this point in the history
  • Loading branch information
zak905 authored and daveshanley committed Jul 28, 2023
1 parent 6b0cae7 commit f7a6c9d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions index/find_component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,29 @@ paths:
assert.Equal(t, "unable to read file bytes: bad file read", index.GetReferenceIndexErrors()[0].Error())
assert.Equal(t, "component 'I-am-impossible-to-open-forever.yaml' does not exist in the specification", index.GetReferenceIndexErrors()[1].Error())
}

func TestSpecIndex_UseFileHandler_ErrorReference(t *testing.T) {

spec := `openapi: 3.1.0
info:
title: Test File Handler
version: 1.0.0
paths:
/test:
get:
parameters:
- $ref: "exisiting.yaml#/paths/~1pet~1%$petId%7D/get/parameters"`

var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(spec), &rootNode)

c := CreateOpenAPIIndexConfig()
c.FSHandler = FS{}
c.RemoteURLHandler = httpClient.Get

index := NewSpecIndexWithConfig(&rootNode, c)

assert.Len(t, index.GetReferenceIndexErrors(), 2)
assert.Equal(t, `invalid URL escape "%$p"`, index.GetReferenceIndexErrors()[0].Error())
assert.Equal(t, "component 'exisiting.yaml#/paths/~1pet~1%$petId%7D/get/parameters' does not exist in the specification", index.GetReferenceIndexErrors()[1].Error())
}

0 comments on commit f7a6c9d

Please sign in to comment.