-
Notifications
You must be signed in to change notification settings - Fork 35
test: create more tests for image_index #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ctron
wants to merge
1
commit into
guacsec:main
Choose a base branch
from
ctron:feature/issue_1392_1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,100 @@ | ||
| #![allow(clippy::expect_used)] | ||
| #![allow(clippy::unwrap_used)] | ||
|
|
||
| use crate::sbom::cyclonedx::external::split_uid; | ||
| use serde_json::json; | ||
| use test_context::test_context; | ||
| use test_log::test; | ||
| use trustify_common::model::Paginated; | ||
| use trustify_module_analysis::{ | ||
| config::AnalysisConfig, | ||
| service::{AnalysisService, ComponentReference, QueryOptions}, | ||
| }; | ||
| use trustify_module_fundamental::sbom::service::SbomService; | ||
| use trustify_test_context::TrustifyContext; | ||
| use trustify_test_context::{TrustifyContext, subset::ContainsSubset}; | ||
|
|
||
| #[test_context(TrustifyContext)] | ||
| #[test(tokio::test)] | ||
| async fn cdx_prod_comp(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { | ||
| let mut result = ctx | ||
| let result = ctx | ||
| .ingest_documents([ | ||
| "cyclonedx/rh/product_component/example_product_quarkus.json", | ||
| "cyclonedx/rh/product_component/example_component_quarkus.json", | ||
| ]) | ||
| .await?; | ||
|
|
||
| let _prod = result | ||
| .pop() | ||
| .unwrap() | ||
| .id | ||
| .try_as_uid() | ||
| .expect("must have a uid"); | ||
| let _comp = result | ||
| .pop() | ||
| .unwrap() | ||
| .id | ||
| .try_as_uid() | ||
| .expect("must have a uid"); | ||
| let [_prod, _comp] = split_uid(result); | ||
|
|
||
| let _service = SbomService::new(ctx.db.clone()); | ||
|
|
||
| // TODO: implement when we have the tools | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test_context(TrustifyContext)] | ||
| #[test(tokio::test)] | ||
| async fn cdx_imageindex_variant(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { | ||
| let result = ctx | ||
| .ingest_documents([ | ||
| "cyclonedx/rh/image_index_variants/example_container_index.json", | ||
| "cyclonedx/rh/image_index_variants/example_container_variant_amd64.json", | ||
| "cyclonedx/rh/image_index_variants/example_container_variant_arm64.json", | ||
| "cyclonedx/rh/image_index_variants/example_container_variant_ppc.json", | ||
| "cyclonedx/rh/image_index_variants/example_container_variant_s390x.json", | ||
| ]) | ||
| .await?; | ||
|
|
||
| let [index, _amd64, _arm64, _ppc, s390x] = split_uid(result); | ||
|
|
||
| let service = AnalysisService::new(AnalysisConfig::default()); | ||
| service.load_all_graphs(&ctx.db).await?; | ||
|
|
||
| let comp_index = service | ||
| .retrieve_single( | ||
| index, | ||
| ComponentReference::Id( | ||
| "ose-openstack-cinder-csi-driver-operator-container_image-index", | ||
| ), | ||
| QueryOptions::descendants(), | ||
| Paginated::default(), | ||
| &ctx.db, | ||
| ) | ||
| .await?; | ||
|
|
||
| let json = serde_json::to_value(comp_index.items)?; | ||
|
|
||
| println!("{json:#?}"); | ||
|
|
||
| assert!(json.contains_subset(json!([ | ||
| { | ||
| "sbom_id": index, | ||
| "node_id": "ose-openstack-cinder-csi-driver-operator-container_image-index", | ||
| "purl": [ | ||
| "pkg:oci/openshift-ose-openstack-cinder-csi-driver-operator@sha256:4e1a8039dfcd2a1ae7672d99be63777b42f9fad3baca5e9273653b447ae72fe8", | ||
| ], | ||
| "descendants": [ | ||
| { | ||
| "sbom_id": index, | ||
| "node_id": "ose-openstack-cinder-csi-driver-operator-container_s390x", | ||
| "relationship": "variant", | ||
| "purl": [ | ||
| "pkg:oci/ose-openstack-cinder-csi-driver-operator@sha256:d3d96f71664efb8c2bd9290b8e1ca9c9b93a54cecb266078c4d954a2e9c05d4d?arch=s390x&os=linux&tag=v4.15.0-202501280037.p0.gd0c2407.assembly.stream.el8", | ||
| ], | ||
| "descendants": [ | ||
| { | ||
| "sbom_id": s390x, | ||
| "node_id": "ose-openstack-cinder-csi-driver-operator-container_s390x", | ||
| "relationship": "variant", | ||
| "purl": [ | ||
| "pkg:oci/ose-openstack-cinder-csi-driver-operator@sha256:d3d96f71664efb8c2bd9290b8e1ca9c9b93a54cecb266078c4d954a2e9c05d4d?arch=s390x&os=linux&tag=v4.15.0-202501280037.p0.gd0c2407.assembly.stream.el8", | ||
| ], | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| ]))); | ||
|
|
||
| Ok(()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.