Example #1
0
def test_get_schema1_manifest():
    retriever = ContentRetrieverForTesting.for_config(
        {
            "config": {
                "Labels": {
                    "foo": "bar",
                },
            },
            "rootfs": {
                "type": "layers",
                "diff_ids": []
            },
            "history": [
                {
                    "created": "2018-04-03T18:37:09.284840891Z",
                    "created_by": "foo"
                },
                {
                    "created": "2018-04-12T18:37:09.284840891Z",
                    "created_by": "bar"
                },
                {
                    "created": "2018-04-03T18:37:09.284840891Z",
                    "created_by": "foo"
                },
            ],
            "architecture":
            "amd64",
            "os":
            "linux",
        },
        "sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7",
        7023,
    )

    manifest = OCIManifest(Bytes.for_string_or_unicode(SAMPLE_MANIFEST))
    assert manifest.get_manifest_labels(retriever) == {
        "com.example.key1": "value1",
        "com.example.key2": "value2",
        "foo": "bar",
    }

    schema1 = manifest.get_schema1_manifest("somenamespace", "somename",
                                            "sometag", retriever)
    assert schema1 is not None
    assert schema1.media_type == DOCKER_SCHEMA1_MANIFEST_CONTENT_TYPE
    assert set(
        schema1.local_blob_digests
    ) == (set(manifest.local_blob_digests) - {
        "sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7"
    })
    assert len(schema1.layers) == 3

    via_convert = manifest.convert_manifest([schema1.media_type],
                                            "somenamespace", "somename",
                                            "sometag", retriever)
    assert via_convert.digest == schema1.digest
Example #2
0
def test_get_schema1_manifest_incorrect_history():
    retriever = ContentRetrieverForTesting.for_config(
        {
            "config": {
                "Labels": {
                    "foo": "bar",
                },
            },
            "rootfs": {
                "type": "layers",
                "diff_ids": []
            },
            "history": [
                {
                    "created": "2018-04-03T18:37:09.284840891Z",
                    "created_by": "foo"
                },
                {
                    "created": "2018-04-03T18:37:09.284840891Z",
                    "created_by": "foo"
                },
            ],
            "architecture":
            "amd64",
            "os":
            "linux",
        },
        "sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7",
        7023,
    )

    manifest = OCIManifest(Bytes.for_string_or_unicode(SAMPLE_MANIFEST))
    assert manifest.get_manifest_labels(retriever) == {
        "com.example.key1": "value1",
        "com.example.key2": "value2",
        "foo": "bar",
    }

    with pytest.raises(MalformedOCIManifest):
        manifest.get_schema1_manifest("somenamespace", "somename", "sometag",
                                      retriever)