GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(cli): unit-test partition_purls ecosystem filter · SocketDev/socket-patch@457f702

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • crates/socket-patch-cli/src
    • ecosystem_dispatch.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎crates/socket-patch-cli/src/ecosystem_dispatch.rs‎

Copy file name to clipboardExpand all lines: crates/socket-patch-cli/src/ecosystem_dispatch.rs
+125Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,3 +704,128 @@ pub async fn find_packages_for_rollback(
704704

705705
all_packages
706706
}
707+
708+
#[cfg(test)]
709+
mod tests {
710+
use super::*;
711+
712+
#[test]
713+
fn partition_purls_no_filter_single_npm() {
714+
let purls = vec!["pkg:npm/[email protected]".to_string()];
715+
let map = partition_purls(&purls, None);
716+
assert_eq!(map.len(), 1);
717+
assert_eq!(
718+
map.get(&Ecosystem::Npm),
719+
Some(&vec!["pkg:npm/[email protected]".to_string()])
720+
);
721+
}
722+
723+
#[test]
724+
fn partition_purls_no_filter_mixed_ecosystems() {
725+
let purls = vec![
726+
"pkg:npm/[email protected]".to_string(),
727+
"pkg:pypi/[email protected]".to_string(),
728+
"pkg:cargo/[email protected]".to_string(),
729+
];
730+
let map = partition_purls(&purls, None);
731+
assert_eq!(map.len(), 3);
732+
assert_eq!(
733+
map.get(&Ecosystem::Npm),
734+
Some(&vec!["pkg:npm/[email protected]".to_string()])
735+
);
736+
assert_eq!(
737+
map.get(&Ecosystem::Pypi),
738+
Some(&vec!["pkg:pypi/[email protected]".to_string()])
739+
);
740+
#[cfg(feature = "cargo")]
741+
assert_eq!(
742+
map.get(&Ecosystem::Cargo),
743+
Some(&vec!["pkg:cargo/[email protected]".to_string()])
744+
);
745+
}
746+
747+
#[test]
748+
fn partition_purls_no_filter_empty_input() {
749+
let purls: Vec<String> = Vec::new();
750+
let map = partition_purls(&purls, None);
751+
assert!(map.is_empty());
752+
}
753+
754+
#[test]
755+
fn partition_purls_no_filter_duplicate_purls_preserved() {
756+
let purls = vec![
757+
"pkg:npm/[email protected]".to_string(),
758+
"pkg:npm/[email protected]".to_string(),
759+
];
760+
let map = partition_purls(&purls, None);
761+
assert_eq!(map.len(), 1);
762+
assert_eq!(
763+
map.get(&Ecosystem::Npm),
764+
Some(&vec![
765+
"pkg:npm/[email protected]".to_string(),
766+
"pkg:npm/[email protected]".to_string(),
767+
])
768+
);
769+
}
770+
771+
#[test]
772+
fn partition_purls_no_filter_unknown_ecosystem_dropped() {
773+
let purls = vec!["pkg:weirdo/x@1".to_string()];
774+
let map = partition_purls(&purls, None);
775+
assert!(map.is_empty());
776+
}
777+
778+
#[test]
779+
fn partition_purls_allow_list_excludes_one() {
780+
let purls = vec![
781+
"pkg:npm/[email protected]".to_string(),
782+
"pkg:pypi/[email protected]".to_string(),
783+
];
784+
let allowed = vec!["npm".to_string()];
785+
let map = partition_purls(&purls, Some(allowed.as_slice()));
786+
assert_eq!(map.len(), 1);
787+
assert_eq!(
788+
map.get(&Ecosystem::Npm),
789+
Some(&vec!["pkg:npm/[email protected]".to_string()])
790+
);
791+
assert!(map.get(&Ecosystem::Pypi).is_none());
792+
}
793+
794+
#[test]
795+
fn partition_purls_allow_list_matches_none() {
796+
let purls = vec!["pkg:npm/[email protected]".to_string()];
797+
let allowed = vec!["pypi".to_string()];
798+
let map = partition_purls(&purls, Some(allowed.as_slice()));
799+
assert!(map.is_empty());
800+
}
801+
802+
#[test]
803+
fn partition_purls_allow_list_matches_all() {
804+
let purls = vec![
805+
"pkg:npm/[email protected]".to_string(),
806+
"pkg:pypi/[email protected]".to_string(),
807+
];
808+
let allowed = vec!["npm".to_string(), "pypi".to_string()];
809+
let map = partition_purls(&purls, Some(allowed.as_slice()));
810+
assert_eq!(map.len(), 2);
811+
assert_eq!(
812+
map.get(&Ecosystem::Npm),
813+
Some(&vec!["pkg:npm/[email protected]".to_string()])
814+
);
815+
assert_eq!(
816+
map.get(&Ecosystem::Pypi),
817+
Some(&vec!["pkg:pypi/[email protected]".to_string()])
818+
);
819+
}
820+
821+
#[test]
822+
fn partition_purls_empty_allow_list_matches_nothing() {
823+
let purls = vec![
824+
"pkg:npm/[email protected]".to_string(),
825+
"pkg:pypi/[email protected]".to_string(),
826+
];
827+
let allowed: Vec<String> = Vec::new();
828+
let map = partition_purls(&purls, Some(allowed.as_slice()));
829+
assert!(map.is_empty());
830+
}
831+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.