-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ecosystems): add tests for ecosystem consistency (#2615)
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
1 parent
6643900
commit e4d75cd
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |