From d35a5c9b0af9086d66c9eddf12aef0e7d01e9856 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 29 Jan 2019 20:38:54 -0500 Subject: [PATCH] Add tests for the package arch change tagger --- ofborg/src/tagger.rs | 236 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 235 insertions(+), 1 deletion(-) diff --git a/ofborg/src/tagger.rs b/ofborg/src/tagger.rs index 3d3bc81..eadd707 100644 --- a/ofborg/src/tagger.rs +++ b/ofborg/src/tagger.rs @@ -164,8 +164,8 @@ impl RebuildTagger { } self.selected = vec![ - format!("10.rebuild-linux: {}", self.bucket(counter_linux)), format!("10.rebuild-darwin: {}", self.bucket(counter_darwin)), + format!("10.rebuild-linux: {}", self.bucket(counter_linux)), ]; for tag in &self.selected { @@ -189,6 +189,8 @@ impl RebuildTagger { remove.remove(pos); } + remove.sort(); + remove } @@ -307,6 +309,238 @@ impl MaintainerPRTagger { mod tests { use super::*; + struct PackageArchSrc { + linux: usize, + darwin: usize, + } + + impl PackageArchSrc { + pub fn linux(linux: usize) -> PackageArchSrc { + PackageArchSrc { linux, darwin: 0 } + } + + pub fn darwin(darwin: usize) -> PackageArchSrc { + PackageArchSrc::linux(0).and_darwin(darwin) + } + + pub fn and_linux(mut self, linux: usize) -> PackageArchSrc { + self.linux = linux; + self + } + + pub fn and_darwin(mut self, darwin: usize) -> PackageArchSrc { + self.darwin = darwin; + self + } + } + + impl From for Vec { + fn from(src: PackageArchSrc) -> Vec { + let mut darwin: Vec = (0..src.darwin) + .into_iter() + .map(|_| PackageArch { + package: String::from("bogus :)"), + architecture: String::from("x86_64-darwin"), + }) + .collect(); + let linux: Vec = (0..src.linux) + .into_iter() + .map(|_| PackageArch { + package: String::from("bogus :)"), + architecture: String::from("x86_64-linux"), + }) + .collect(); + + let mut combined = darwin; + combined.extend(linux); + combined + } + } + + #[test] + pub fn test_packages_changed() { + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(0).and_darwin(0).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 0", "10.rebuild-linux: 0",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 11-100", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 1-10", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 11-100", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(1).into()); + + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 0", "10.rebuild-linux: 1-10",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 11-100", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 11-100", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(1).and_darwin(1).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 1-10", "10.rebuild-linux: 1-10",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 11-100", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 11-100", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(10).and_darwin(10).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 1-10", "10.rebuild-linux: 1-10",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 11-100", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 11-100", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(11).and_darwin(11).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 11-100", "10.rebuild-linux: 11-100",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 1-10", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(100).and_darwin(100).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 11-100", "10.rebuild-linux: 11-100",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 1-10", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(101).and_darwin(101).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 101-500", "10.rebuild-linux: 101-500",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 11-100", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 1-10", + "10.rebuild-linux: 11-100", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(500).and_darwin(500).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 101-500", "10.rebuild-linux: 101-500",] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 11-100", + "10.rebuild-darwin: 501+", + "10.rebuild-linux: 0", + "10.rebuild-linux: 1-10", + "10.rebuild-linux: 11-100", + "10.rebuild-linux: 501+" + ] + ); + + let mut tagger = RebuildTagger::new(); + tagger.parse_attrs(PackageArchSrc::linux(501).and_darwin(501).into()); + assert_eq!( + tagger.tags_to_add(), + vec!["10.rebuild-darwin: 501+", "10.rebuild-linux: 501+"] + ); + assert_eq!( + tagger.tags_to_remove(), + vec![ + "10.rebuild-darwin: 0", + "10.rebuild-darwin: 1-10", + "10.rebuild-darwin: 101-500", + "10.rebuild-darwin: 11-100", + "10.rebuild-linux: 0", + "10.rebuild-linux: 1-10", + "10.rebuild-linux: 101-500", + "10.rebuild-linux: 11-100", + ] + ); + } + #[test] pub fn test_files_changed_list() { let mut criteria: HashMap> = HashMap::new();