def test_apply_package_name_suffix_invalid_yaml(tmpdir): metadata_dir = tmpdir.mkdir('metadata') metadata_dir.join('annotations.yaml').write( '"This is why you fail." - Yoda') expected = 'metadata/annotations/yaml is not valid YAML' with pytest.raises(IIBError, match=expected): build._apply_package_name_suffix(str(metadata_dir))
def test_apply_package_name_suffix_invalid_annotations_yaml( annotations, expected_error, tmpdir): metadata_dir = tmpdir.mkdir('metadata') annotations_yaml = metadata_dir.join('annotations.yaml') with open(str(annotations_yaml), 'w') as f: yaml.dump(annotations, f) with pytest.raises(IIBError, match=expected_error): build._apply_package_name_suffix(str(metadata_dir))
def test_apply_package_name_suffix(organization, package, expected_package, expected_labels, tmpdir): metadata_dir = tmpdir.mkdir('metadata') annotations_yaml = metadata_dir.join('annotations.yaml') annotations_yaml.write( textwrap.dedent(f'''\ annotations: operators.operatorframework.io.bundle.channel.default.v1: stable operators.operatorframework.io.bundle.channels.v1: stable operators.operatorframework.io.bundle.manifests.v1: manifests/ operators.operatorframework.io.bundle.mediatype.v1: registry+v1 operators.operatorframework.io.bundle.metadata.v1: metadata/ operators.operatorframework.io.bundle.package.v1: {package} ''')) package_name, labels = build._apply_package_name_suffix( str(metadata_dir), organization) assert package_name == expected_package assert labels == expected_labels with open(annotations_yaml, 'r') as f: annotations_yaml_content = yaml.load(f) annotation_key = 'operators.operatorframework.io.bundle.package.v1' assert annotations_yaml_content['annotations'][ annotation_key] == expected_package
def test_apply_package_name_suffix_missing_annotations_yaml(tmpdir): metadata_dir = tmpdir.mkdir('metadata') expected = 'metadata/annotations.yaml does not exist in the bundle' with pytest.raises(IIBError, match=expected): build._apply_package_name_suffix(str(metadata_dir))