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_regenerate_bundle._apply_package_name_suffix( str(metadata_dir), '-cmp')
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_regenerate_bundle._apply_package_name_suffix( str(metadata_dir), '-vk')
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_regenerate_bundle._apply_package_name_suffix( str(metadata_dir), '-msd')
def test_apply_package_name_suffix(package_name_suffix, 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_regenerate_bundle._apply_package_name_suffix( str(metadata_dir), package_name_suffix) 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_annotations_with_preserved_quotes(tmpdir): metadata_dir = tmpdir.mkdir('metadata') annotations_yaml = metadata_dir.join('annotations.yaml') annotations_yaml.write( textwrap.dedent('''\ annotations: operators.operatorframework.io.bundle.package.v1: amq-streams spam: "spam:maps" ''')) build_regenerate_bundle._apply_package_name_suffix(str(metadata_dir), '-cmp') annotations_yaml_content = annotations_yaml.read() assert annotations_yaml_content == textwrap.dedent('''\ annotations: operators.operatorframework.io.bundle.package.v1: amq-streams-cmp spam: "spam:maps" ''')