Skip to content

Commit

Permalink
Add tests for schema composition (#3276)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Jun 6, 2024
1 parent bcf5813 commit bc1b5cd
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion test/unit/module/schema/resolver/test_ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,33 @@ def setUp(self) -> None:
"fooBar": {
"type": "object",
"properties": {"a": {"type": "string"}, "b": {"type": "string"}},
}
},
"anyOf": {
"anyOf": [
{"$ref": "#/definitions/fooBar"},
{
"type": "object",
"properties": {
"a": {"type": "boolean"},
"c": {"type": "boolean"},
"d": {"type": "boolean"},
},
},
]
},
},
"properties": {
"foo": {"type": "string"},
"bar": {"$ref": "#/definitions/bar"},
"fooBars": {"type": "array", "items": {"$ref": "#/definitions/fooBar"}},
"refFirst": {
"$ref": "#/definitions/fooBar",
"type": "object",
"properties": {
"a": {"type": "boolean"},
},
},
"anyOf": {"$ref": "#/definitions/anyOf"},
},
}

Expand All @@ -44,5 +65,23 @@ def test_pointer(self):
("/properties/fooBars/*/a", {"type": "string"}),
)

# first one found is string (not boolean)
self.assertEqual(
resolver.resolve_cfn_pointer("/properties/anyOf/a"),
("/properties/anyOf/a", {"type": "string"}),
)

# second option in anyOf has the property we are looking for
self.assertEqual(
resolver.resolve_cfn_pointer("/properties/anyOf/c"),
("/properties/anyOf/c", {"type": "boolean"}),
)

# refs are handled first
self.assertEqual(
resolver.resolve_cfn_pointer("/properties/refFirst/a"),
("/properties/refFirst/a", {"type": "string"}),
)

with self.assertRaises(RefResolutionError):
resolver.resolve_cfn_pointer("/properties/bar/key")

0 comments on commit bc1b5cd

Please sign in to comment.