Skip to content

Commit

Permalink
Merge pull request #165 from kevinrizza/versions-field
Browse files Browse the repository at this point in the history
Support crd.versions field
  • Loading branch information
kevinrizza authored Oct 1, 2019
2 parents 250382e + 09dd121 commit 81cef80
Show file tree
Hide file tree
Showing 4 changed files with 728 additions and 3 deletions.
12 changes: 9 additions & 3 deletions operatorcourier/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ def _crd_validation(self, bundle):
if "group" not in crd['spec']:
self._log_error("crd spec.group not defined.")
valid = False
if "version" not in crd['spec']:
self._log_error("crd spec.version not defined.")
valid = False
if "versions" not in crd['spec']:
if "version" not in crd['spec']:
self._log_error("crd spec.version or spec.versions not defined")
valid = False

return valid

Expand Down Expand Up @@ -271,6 +272,11 @@ def _csv_spec_validation(self, spec, bundleData):

if 'version' in csvOwnedCrd:
if 'spec' in crd:
if 'versions' in crd['spec']:
if csvOwnedCrd['version'] not in crd['spec']['versions']:
self._log_error('CSV.spec.crd.owned.version is'
'not in CRD.spec.versions list')
valid = False
if 'version' in crd['spec']:
if csvOwnedCrd['version'] != crd['spec']['version']:
self._log_error('CRD.spec.version does not match '
Expand Down
347 changes: 347 additions & 0 deletions tests/test_files/bundles/verification/crdversions.invalid.bundle.yaml

Large diffs are not rendered by default.

348 changes: 348 additions & 0 deletions tests/test_files/bundles/verification/crdversions.valid.bundle.yaml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,27 @@ def _test_invalid_bundle(bundleFile):
unformatted_bundle = unformat_bundle(bundle)
valid, _ = ValidateCmd().validate(unformatted_bundle)
assert not valid


@pytest.mark.parametrize('file_name', [
"tests/test_files/bundles/verification/crdversions.invalid.bundle.yaml",
])
def test_invalid_crd_versions_field(file_name):
with open(file_name) as f:
bundle = yaml.safe_load(f)
bundle = unformat_bundle(bundle)
valid, _ = ValidateCmd().validate(bundle)

assert not valid


@pytest.mark.parametrize('file_name', [
"tests/test_files/bundles/verification/crdversions.valid.bundle.yaml",
])
def test_valid_crd_versions_field(file_name):
with open(file_name) as f:
bundle = yaml.safe_load(f)
bundle = unformat_bundle(bundle)
valid, _ = ValidateCmd().validate(bundle)

assert valid

0 comments on commit 81cef80

Please sign in to comment.