Skip to content
Snippets Groups Projects
Commit 5b8ef6cf authored by Erik Reid's avatar Erik Reid
Browse files

added schema validation to test

parent 317ed6f3
No related branches found
No related tags found
No related merge requests found
......@@ -589,7 +589,7 @@ def _build_interface_services(update_callback=lambda s: None):
assert ifc_name == info['name']
yield {
'hostname': router_name,
'router': router_name,
'interface': info['name'],
'description': info['description']
}
......@@ -609,8 +609,8 @@ def _build_interface_services(update_callback=lambda s: None):
if not service_type:
continue
rp.set(
f'{service_type}:interface-services'
f':{ifc["hostname"]}:{ifc["interface"]}',
f'interface-services:{service_type}:'
f':{ifc["router"]}:{ifc["interface"]}',
json.dumps(ifc))
rp.execute()
......
......@@ -2,6 +2,7 @@
tests of a few worker utilities
"""
import contextlib
import json
import os
import jsonschema
......@@ -28,10 +29,37 @@ def test_build_interface_services(mocked_worker_module):
:param mocked_redis:
:return:
"""
ifc_list_schema = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'ifc-info': {
'type': 'object',
'properties': {
'description': {'type': 'string'},
'router': {'type': 'string'},
'interface': {'type': 'string'}
},
'required': ['router', 'interface', 'description'],
'additionalProperties': False
},
},
'type': 'array',
'items': { '$ref': '#/definitions/ifc-info' }
}
db = backend_db() # also forces initialization
worker._build_interface_services()
l = [v for (k, v) in db.items()
if k.startswith('interface-services:')]
print(len(l))
mdvpn = [json.loads(v) for (k, v) in db.items()
if k.startswith('interface-services:mdvpn')]
jsonschema.validate(mdvpn, ifc_list_schema)
assert mdvpn, 'expected at least one interface'
lhcone = [json.loads(v) for (k, v) in db.items()
if k.startswith('interface-services:mdvpn')]
jsonschema.validate(lhcone, ifc_list_schema)
assert lhcone, 'expected at least one interface'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment