Skip to content

Commit

Permalink
Add some tests for collect_approved_reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Aug 27, 2024
1 parent e311106 commit a28e418
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl ClientSet {
Ok(())
}

// TODO: add test
fn get_client(&mut self, host: &str) -> Result<Arc<Client>, anyhow::Error> {
if let Some(client) = self.clients.get(host) {
return Ok(client.clone());
Expand Down
60 changes: 60 additions & 0 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct Changeset {

impl Changeset {
// pr_reviews must be sorted by key submitted_at!
// TODO: add test
pub fn collect_approved_reviews(&mut self, pr_reviews: &[Review], head_sha: &String) {
let mut last_review_by: Vec<String> = vec![];

Expand Down Expand Up @@ -156,3 +157,62 @@ impl CommitMetadata {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::github::Review;

fn gen_change_review() -> (Changeset, Vec<Review>) {
(
Changeset {
commits: vec![
CommitMetadata {
headline: "Commit 1".to_owned(),
link: "https://github.com/example/project/commit/00000000000000000000000000000001".to_owned(),
},
CommitMetadata {
headline: "Commit 2".to_owned(),
link: "https://github.com/example/project/commit/00000000000000000000000000000002".to_owned(),
},
],
pr_link: Some("https://github.com/example/project/pulls/1".to_owned()),
approvals: Vec::new(),
},
vec![
Review {
approved: true,
commit_id: "00000000000000000000000000000001".to_owned(),
submitted_at: 1,
user: "user1".to_owned(),
},
Review {
approved: true,
commit_id: "00000000000000000000000000000002".to_owned(),
submitted_at: 2,
user: "user2".to_owned(),
},
Review {
approved: false,
commit_id: "00000000000000000000000000000003".to_owned(),
submitted_at: 3,
user: "user3".to_owned(),
},
],
)
}

#[test]
fn collect_approved_reviews() {
let (mut changeset, pr_reviews) = gen_change_review();
changeset.collect_approved_reviews(&pr_reviews, &"00000000000000000000000000000002".to_string());
assert_eq!(changeset.approvals, vec!["user2"]);
}

#[test]
fn collect_approved_reviews_extra_commit() {
let (mut changeset, pr_reviews) = gen_change_review();
changeset.collect_approved_reviews(&pr_reviews, &"00000000000000000000000000000003".to_string());
assert_eq!(changeset.approvals, Vec::<String>::new());
}
}
1 change: 1 addition & 0 deletions src/helm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct ImageRefs {
}

impl ImageRefs {
// TODO: add test
pub fn parse(repo: &Repository, diff_file: &DiffFile) -> Result<Self, anyhow::Error> {
let blob_id = diff_file.id();
let blob = repo
Expand Down

0 comments on commit a28e418

Please sign in to comment.