Skip to content

Commit

Permalink
Add test for deleting a team
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jan 20, 2024
1 parent 561ef02 commit ccab18a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/github/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,48 @@ fn team_remove_member() {
]
"###);
}

#[test]
fn team_delete() {
let mut model = DataModel::default();
let user = model.create_user("mark");

// We need at least two github teams, otherwise the diff for removing the last GH team
// won't be generated, because no organization is known to scan for existing unmanaged teams.
model.create_team(
TeamData::new("admins")
.gh_team("admins-gh", &[user])
.gh_team("users-gh", &[user]),
);
let gh = model.gh_model();

model.get_team("admins").remove_gh_team("users-gh");

let team_diff = model.diff_teams(gh);
insta::assert_debug_snapshot!(team_diff, @r###"
[
Edit(
EditTeamDiff {
org: "rust-lang",
name: "admins-gh",
name_diff: None,
description_diff: None,
privacy_diff: None,
member_diffs: [
(
"mark",
Noop,
),
],
},
),
Delete(
DeleteTeamDiff {
org: "rust-lang",
name: "users-gh",
slug: "users-gh",
},
),
]
"###);
}
7 changes: 6 additions & 1 deletion src/github/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ impl TeamData {
self.github_team(team).members.retain(|u| *u != user);
}

pub fn remove_gh_team(&mut self, name: &str) {
self.gh_teams.retain(|t| t.name != name);
}

fn github_team(&mut self, name: &str) -> &mut GitHubTeam {
self.gh_teams
.iter_mut()
Expand Down Expand Up @@ -213,7 +217,8 @@ impl GithubRead for GithubMock {
.collect())
}

fn org_teams(&self, _org: &str) -> anyhow::Result<Vec<(String, String)>> {
fn org_teams(&self, org: &str) -> anyhow::Result<Vec<(String, String)>> {
assert_eq!(org, DEFAULT_ORG);
Ok(self
.teams
.iter()
Expand Down

0 comments on commit ccab18a

Please sign in to comment.