Add tests for the package arch change tagger

This commit is contained in:
Graham Christensen 2019-01-29 20:38:54 -05:00
parent a162d41fb2
commit d35a5c9b0a
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C

View file

@ -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<PackageArchSrc> for Vec<PackageArch> {
fn from(src: PackageArchSrc) -> Vec<PackageArch> {
let mut darwin: Vec<PackageArch> = (0..src.darwin)
.into_iter()
.map(|_| PackageArch {
package: String::from("bogus :)"),
architecture: String::from("x86_64-darwin"),
})
.collect();
let linux: Vec<PackageArch> = (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<String, Vec<String>> = HashMap::new();