Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 11 additions & 26 deletions src/compile/codemods/0002_pool_object_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,6 @@ mod tests {
}
}

#[test]
fn rewrites_scalar_pool_to_name_object() {
let mut fm: Mapping = serde_yaml::from_str("name: x\ndescription: y\npool: MyPool").unwrap();
let changed = apply_codemod(&mut fm, &ctx("0.30.0")).expect("apply");
assert!(changed);
assert_eq!(
fm.get(Value::String("pool".into())).cloned(),
Some(serde_yaml::from_str::<Value>("name: MyPool").unwrap())
);
}

#[test]
fn noops_when_pool_is_already_mapping() {
let mut fm: Mapping =
Expand Down Expand Up @@ -128,21 +117,17 @@ mod tests {

#[test]
fn noops_when_pool_absent_standalone_and_version_gte() {
// Standalone pipelines without pool should get the new
// vmImage: ubuntu-22.04 default, not the legacy 1ES pool.
let mut fm: Mapping = serde_yaml::from_str("name: x\ndescription: y").unwrap();
let changed = apply_codemod(&mut fm, &ctx("0.30.0")).expect("apply");
assert!(!changed);
assert!(!fm.contains_key(Value::String("pool".into())));
}

#[test]
fn noops_when_pool_absent_explicit_standalone_and_version_gte() {
let mut fm: Mapping =
serde_yaml::from_str("name: x\ndescription: y\ntarget: standalone").unwrap();
let changed = apply_codemod(&mut fm, &ctx("0.30.0")).expect("apply");
assert!(!changed);
assert!(!fm.contains_key(Value::String("pool".into())));
// Neither implicit nor explicit `standalone` target should
// ever receive the legacy 1ES pool injection.
for yaml in &[
"name: x\ndescription: y",
"name: x\ndescription: y\ntarget: standalone",
] {
let mut fm: Mapping = serde_yaml::from_str(yaml).unwrap();
let changed = apply_codemod(&mut fm, &ctx("0.30.0")).expect("apply");
assert!(!changed, "yaml: {}", yaml);
assert!(!fm.contains_key(Value::String("pool".into())), "yaml: {}", yaml);
}
}

#[test]
Expand Down
19 changes: 10 additions & 9 deletions src/compile/codemods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ mod tests {

#[test]
fn registry_ids_are_unique() {
// Vacuously true while CODEMODS is empty; the assertion
// machinery still compiles so this test guards against
// duplicate ids the moment a real codemod ships.
let mut seen = std::collections::BTreeSet::new();
for c in CODEMODS {
assert!(
Expand All @@ -196,10 +193,9 @@ mod tests {

#[test]
fn codemod_filenames_match_registry_count() {
// Vacuously true while CODEMODS is empty (the directory
// contains only `mod.rs` and `helpers.rs`, which are
// skipped). Once a numeric `<NNNN>_<id>.rs` file lands, this
// test asserts the registry was updated to match.
// Each numeric `<NNNN>_<id>.rs` file must have a corresponding
// entry in CODEMODS; forgetting to register a new codemod
// in the slice is caught here.
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("src/compile/codemods");
let mut numeric_files: Vec<String> = Vec::new();
Expand Down Expand Up @@ -309,12 +305,17 @@ mod tests {

#[test]
fn non_matching_codemod_omitted_from_report() {
// Source has no `a` key, so the rename is a no-op and is
// not listed in the report.
// Source has no `a` key, so the rename is a no-op and must
// not appear in the applied list.
let mut m: Mapping = serde_yaml::from_str("name: x\n").unwrap();
let registry: &[&'static Codemod] = &[&TEST_CODEMOD_RENAME];
let report = apply_codemods_with(&mut m, registry).unwrap();
assert!(!report.changed());
assert!(
report.applied_ids().is_empty(),
"non-matching codemod must not appear in applied list, got: {:?}",
report.applied_ids()
);
}

#[test]
Expand Down