def test_metadata_plugin(tmpdir):
    initial_timestamp = datetime.now()
    workflow = prepare()

    workflow.prebuild_results = {
        CpDockerfilePlugin.key: "dockerfile-content",
        DistgitFetchArtefactsPlugin.key: "artefact1\nartefact2",
    }
    workflow.postbuild_results = {
        PostBuildRPMqaPlugin.key: "rpm1\nrpm2",
    }
    workflow.plugins_timestamps = {
        CpDockerfilePlugin.key: initial_timestamp.isoformat(),
        DistgitFetchArtefactsPlugin.key: (initial_timestamp + timedelta(seconds=1)).isoformat(),
        PostBuildRPMqaPlugin.key: (initial_timestamp + timedelta(seconds=3)).isoformat(),
    }
    workflow.plugins_durations = {
        CpDockerfilePlugin.key: 1.01,
        DistgitFetchArtefactsPlugin.key: 2.02,
        PostBuildRPMqaPlugin.key: 3.03,
    }
    workflow.plugins_errors = {
        DistgitFetchArtefactsPlugin.key: 'foo'
    }

    runner = ExitPluginsRunner(
        None,
        workflow,
        [{
            'name': StoreMetadataInOSv3Plugin.key,
            "args": {
                "url": "http://example.com/"
            }
        }]
    )
    output = runner.run()
    assert StoreMetadataInOSv3Plugin.key in output
    labels = output[StoreMetadataInOSv3Plugin.key]["annotations"]
    assert "dockerfile" in labels
    assert is_string_type(labels['dockerfile'])
    assert "artefacts" in labels
    assert is_string_type(labels['artefacts'])
    assert "logs" in labels
    assert is_string_type(labels['logs'])
    assert labels['logs'] == ''
    assert "rpm-packages" in labels
    assert is_string_type(labels['rpm-packages'])
    assert labels['rpm-packages'] == ''
    assert "repositories" in labels
    assert is_string_type(labels['repositories'])
    assert "commit_id" in labels
    assert is_string_type(labels['commit_id'])
    assert "base-image-id" in labels
    assert is_string_type(labels['base-image-id'])
    assert "base-image-name" in labels
    assert is_string_type(labels['base-image-name'])
    assert "image-id" in labels
    assert is_string_type(labels['image-id'])

    assert "digests" in labels
    assert is_string_type(labels['digests'])
    digests = json.loads(labels['digests'])
    expected = [{
        "registry": LOCALHOST_REGISTRY,
        "repository": TEST_IMAGE,
        "tag": 'latest',
        "digest": DIGEST1,
    },{
        "registry": LOCALHOST_REGISTRY,
        "repository": "namespace/image",
        "tag": 'asd123',
        "digest": DIGEST2,
    }]
    assert digests == expected or digests == reversed(expected)

    assert "plugins-metadata" in labels
    assert "errors" in labels["plugins-metadata"]
    assert "durations" in labels["plugins-metadata"]
    assert "timestamps" in labels["plugins-metadata"]

    plugins_metadata = json.loads(labels["plugins-metadata"])
    assert "distgit_fetch_artefacts" in plugins_metadata["errors"]

    assert "cp_dockerfile" in plugins_metadata["durations"]
    assert "distgit_fetch_artefacts" in plugins_metadata["durations"]
    assert plugins_metadata["durations"] in "all_rpm_packages"
dataset/ETHPy150Open projectatomic/atomic-reactor/tests/plugins/test_store_metadata.py/test_metadata_plugin/swapped operands of `in`