Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRooney committed Oct 4, 2024
1 parent 61a22d2 commit 7f1e818
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions index/rolodex_test_data/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ info:
title: Rolodex Test Data
version: 1.0.0
components:
parameters:
SomeParam:
name: someParam
in: query
description: A parameter that does nothing. Ding a ling!
schema:
type: string
schemas:
Ding:
type: object
Expand Down
2 changes: 2 additions & 0 deletions index/rolodex_test_data/paths/paths.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/some/path:
get:
parameters:
- $ref: '../components.yaml#/components/parameters/SomeParam'
responses:
'200':
description: OK
Expand Down
15 changes: 13 additions & 2 deletions index/search_rolodex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func TestSpecIndex_TestPathsAsRefWithFiles(t *testing.T) {

yml := `paths:
/test:
$ref: 'rolodex_test_data/paths/paths.yaml'
$ref: 'rolodex_test_data/paths/paths.yaml#/~1some~1path'
/test-2:
$ref: './rolodex_test_data/paths/paths.yaml'
$ref: './rolodex_test_data/paths/paths.yaml#/~1some~1path'
`

baseDir := "."
Expand Down Expand Up @@ -166,4 +166,15 @@ func TestSpecIndex_TestPathsAsRefWithFiles(t *testing.T) {
assert.Len(t, rolo.indexes, 2)
assert.Len(t, rolo.GetCaughtErrors(), 0)

params := rolo.rootIndex.GetAllParametersFromOperations()
assert.Len(t, params, 2)
lookupPath, ok := params["/test"]
assert.True(t, ok)
lookupOperation, ok := lookupPath["get"]
assert.True(t, ok)
assert.Len(t, lookupOperation, 1)
lookupRef, ok := lookupOperation["../components.yaml#/components/parameters/SomeParam"]
assert.True(t, ok)
assert.Len(t, lookupRef, 1)
assert.Equal(t, lookupRef[0].Name, "SomeParam")
}

0 comments on commit 7f1e818

Please sign in to comment.