Skip to content

Commit f82bb41

Browse files
committed
chore: increase test coverage
1 parent cea59aa commit f82bb41

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

bundler/composer_functions_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,41 @@ func TestProcessedRefFor(t *testing.T) {
274274
assert.Nil(t, processedRefFor(processedNodes, "/tmp/missing.yaml#/Thing", nil))
275275
}
276276

277+
func TestComposedRefFor(t *testing.T) {
278+
got, ok := composedRefFor(nil, "/tmp/common.yaml#/components/schemas/Thing/properties/id")
279+
assert.False(t, ok)
280+
assert.Empty(t, got)
281+
282+
processedNodes := orderedmap.New[string, *processRef]()
283+
processedNodes.Set("/tmp/common.yaml#/components/schemas/Nil", nil)
284+
processedNodes.Set("/tmp/common.yaml#/components/schemas/Empty", &processRef{})
285+
processedNodes.Set("/tmp/common.yaml#/components/schemas/Thing", &processRef{
286+
location: []string{"components", "schemas", "Thing"},
287+
})
288+
processedNodes.Set("/tmp/common.yaml#/components/schemas/Thing/properties", &processRef{
289+
location: []string{"components", "schemas", "ThingProperties"},
290+
})
291+
processedNodes.Set("/tmp/common.yaml#/components/schemas/Thing/properties/id", &processRef{
292+
location: []string{"components", "schemas", "ExactMatch"},
293+
})
294+
295+
got, ok = composedRefFor(processedNodes, "/tmp/common.yaml#/components/schemas/Thing/properties/id/type")
296+
require.True(t, ok)
297+
assert.Equal(t, "#/components/schemas/ExactMatch/type", got)
298+
299+
got, ok = composedRefFor(processedNodes, "/tmp/common.yaml#/components/schemas/ThingExtra")
300+
assert.False(t, ok)
301+
assert.Empty(t, got)
302+
303+
got, ok = composedRefFor(processedNodes, "/tmp/common.yaml#/components/schemas/Thing/properties/id")
304+
assert.True(t, ok)
305+
assert.Equal(t, "#/components/schemas/ThingProperties/id", got)
306+
307+
got, ok = composedRefFor(orderedmap.New[string, *processRef](), "/tmp/common.yaml#/components/schemas/Missing")
308+
assert.False(t, ok)
309+
assert.Empty(t, got)
310+
}
311+
277312
func TestInlineProcessRef(t *testing.T) {
278313
assert.Nil(t, inlineProcessRef(nil))
279314

0 commit comments

Comments
 (0)