Skip to content

Commit

Permalink
Add test data "artifact_manifest.json" from specification example
Browse files Browse the repository at this point in the history
Example is copied from https://github.com/opencontainers/image-spec/blob/4df8887994e871a59f9e30e8dd811d060f6a39ef/artifact.md

Signed-off-by: Toshiki Teramura <toshiki.teramura@gmail.com>
  • Loading branch information
termoshtt committed Nov 17, 2022
1 parent 5c8978b commit b9b54a5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/image/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,63 @@ impl ArtifactManifest {
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::image::DescriptorBuilder;
use std::path::PathBuf;

fn get_manifest_path() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test/data/artifact_manifest.json")
}

fn create_manifest() -> ArtifactManifest {
let blob = DescriptorBuilder::default()
.media_type(MediaType::Other("application/gzip".to_string()))
.size(123)
.digest(
"sha256:87923725d74f4bfb94c9e86d64170f7521aad8221a5de834851470ca142da630"
.to_string(),
)
.build()
.unwrap();
let subject = DescriptorBuilder::default()
.media_type(MediaType::ImageManifest)
.size(1234)
.digest(
"sha256:cc06a2839488b8bd2a2b99dcdc03d5cfd818eed72ad08ef3cc197aac64c0d0a0"
.to_string(),
)
.build()
.unwrap();
let annotations = HashMap::from([
(
"org.opencontainers.artifact.created".to_string(),
"2022-01-01T14:42:55Z".to_string(),
),
("org.example.sbom.format".to_string(), "json".to_string()),
]);
ArtifactManifestBuilder::default()
.artifact_type(MediaType::Other(
"application/vnd.example.sbom.v1".to_string(),
))
.blobs(vec![blob])
.subject(subject)
.annotations(annotations)
.build()
.unwrap()
}

#[test]
fn load_manifest_from_file() {
// arrange
let manifest_path = get_manifest_path();
let expected = create_manifest();

// act
let actual = ArtifactManifest::from_file(manifest_path).expect("from file");

// assert
assert_eq!(actual, expected);
}
}
20 changes: 20 additions & 0 deletions test/data/artifact_manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"mediaType": "application/vnd.oci.artifact.manifest.v1+json",
"artifactType": "application/vnd.example.sbom.v1",
"blobs": [
{
"mediaType": "application/gzip",
"size": 123,
"digest": "sha256:87923725d74f4bfb94c9e86d64170f7521aad8221a5de834851470ca142da630"
}
],
"subject": {
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"size": 1234,
"digest": "sha256:cc06a2839488b8bd2a2b99dcdc03d5cfd818eed72ad08ef3cc197aac64c0d0a0"
},
"annotations": {
"org.opencontainers.artifact.created": "2022-01-01T14:42:55Z",
"org.example.sbom.format": "json"
}
}

0 comments on commit b9b54a5

Please sign in to comment.