Skip to content

Commit 1ab8b9a

Browse files
committed
chore: increase test coverage
1 parent ebc4990 commit 1ab8b9a

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
@@ -276,6 +276,41 @@ func TestProcessedRefFor(t *testing.T) {
276276
assert.Nil(t, processedRefFor(processedNodes, "/tmp/missing.yaml#/Thing", nil))
277277
}
278278

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

0 commit comments

Comments
 (0)