Skip to content

Commit

Permalink
test(ecosystems): add tests for ecosystem consistency (#2615)
Browse files Browse the repository at this point in the history
Test that ecosystem name hardcoding is internally consistent and
consistent with the OSV Schema

Requires OSV Schema submodule to be at or past
ossf/osv-schema@84969b4
(currently unreleased) to pass.
  • Loading branch information
andrewpollock authored Oct 22, 2024
1 parent 6643900 commit e4d75cd
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions osv/ecosystems/ecosystems_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Ecosystem helpers tests."""

import json

import re

import unittest

from . import _ecosystems


class EcosystemsTest(unittest.TestCase):
"""Ecosystem helpers tests."""

def setUp(self):
with open('osv/osv-schema/validation/schema.json') as schema_f:
schema = json.load(schema_f)
self.schema_ecosystems = re.compile(schema['$defs']['ecosystem']['pattern'])
self.canonical_ecosystems = _ecosystems._ecosystems.keys() # pylint: disable=protected-access

def test_ecosystem_supported_by_schema(self):
"""Test ecosystems referenced exist in schema definition"""
for ecosystem in self.canonical_ecosystems:
self.assertIsNotNone(
self.schema_ecosystems.match(ecosystem),
msg=f'"{ecosystem}" not defined in schema')

for ecosystem in _ecosystems.SEMVER_ECOSYSTEMS:
self.assertIsNotNone(
self.schema_ecosystems.match(ecosystem),
msg=f'SEMVER ecosystem "{ecosystem}" not defined in schema')

for ecosystem in _ecosystems.package_urls:
self.assertIsNotNone(
self.schema_ecosystems.match(ecosystem),
msg=f'Purl "{ecosystem}" not defined in schema')

for ecosystem in _ecosystems._OSV_TO_DEPS_ECOSYSTEMS_MAP: # pylint: disable=protected-access
self.assertIsNotNone(
self.schema_ecosystems.match(ecosystem),
msg=f'"{ecosystem}" in deps.dev map not defined in schema')


if __name__ == '__main__':
unittest.main()

0 comments on commit e4d75cd

Please sign in to comment.