Skip to content

Commit

Permalink
chore: move tests (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw authored Jan 12, 2025
1 parent 572e5d7 commit 8d6f684
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,46 +841,3 @@ impl<'a> CompositeStep<'a> {
Some(uses)
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use github_actions_models::common::Uses;

use crate::models::uses::RepositoryUsesExt;

#[test]
fn test_repositoryuses_matches() {
for (uses, template, matches) in [
// OK: `uses:` is more specific than template
("actions/checkout@v3", "actions/checkout", true),
("actions/checkout/foo@v3", "actions/checkout/foo", true),
// OK: equally specific
("actions/checkout@v3", "actions/checkout@v3", true),
("actions/checkout", "actions/checkout", true),
("actions/checkout/foo", "actions/checkout/foo", true),
("actions/checkout/foo@v3", "actions/checkout/foo@v3", true),
// OK: case-insensitive
("actions/checkout@v3", "Actions/Checkout@v3", true),
("actions/checkout/foo", "actions/checkout/Foo", true),
("actions/checkout/foo@v3", "Actions/Checkout/Foo", true),
("actions/checkout@v3", "actions/checkout@V3", true),
// NOT OK: owner/repo do not match
("actions/checkout@v3", "foo/checkout", false),
("actions/checkout@v3", "actions/bar", false),
// NOT OK: subpath does not match
("actions/checkout/foo", "actions/checkout", false),
("actions/checkout/foo@v3", "actions/checkout@v3", false),
// NOT OK: template is more specific than `uses:`
("actions/checkout", "actions/checkout@v3", false),
("actions/checkout/foo", "actions/checkout/foo@v3", false),
] {
let Ok(Uses::Repository(uses)) = Uses::from_str(uses) else {
panic!();
};

assert_eq!(uses.matches(template), matches)
}
}
}
43 changes: 43 additions & 0 deletions src/models/uses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,46 @@ impl UsesExt for Uses {
}
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use github_actions_models::common::Uses;

use crate::models::uses::RepositoryUsesExt;

#[test]
fn test_repositoryuses_matches() {
for (uses, template, matches) in [
// OK: `uses:` is more specific than template
("actions/checkout@v3", "actions/checkout", true),
("actions/checkout/foo@v3", "actions/checkout/foo", true),
// OK: equally specific
("actions/checkout@v3", "actions/checkout@v3", true),
("actions/checkout", "actions/checkout", true),
("actions/checkout/foo", "actions/checkout/foo", true),
("actions/checkout/foo@v3", "actions/checkout/foo@v3", true),
// OK: case-insensitive
("actions/checkout@v3", "Actions/Checkout@v3", true),
("actions/checkout/foo", "actions/checkout/Foo", true),
("actions/checkout/foo@v3", "Actions/Checkout/Foo", true),
("actions/checkout@v3", "actions/checkout@V3", true),
// NOT OK: owner/repo do not match
("actions/checkout@v3", "foo/checkout", false),
("actions/checkout@v3", "actions/bar", false),
// NOT OK: subpath does not match
("actions/checkout/foo", "actions/checkout", false),
("actions/checkout/foo@v3", "actions/checkout@v3", false),
// NOT OK: template is more specific than `uses:`
("actions/checkout", "actions/checkout@v3", false),
("actions/checkout/foo", "actions/checkout/foo@v3", false),
] {
let Ok(Uses::Repository(uses)) = Uses::from_str(uses) else {
panic!();
};

assert_eq!(uses.matches(template), matches)
}
}
}

0 comments on commit 8d6f684

Please sign in to comment.