-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a test which shows the error.
- Loading branch information
1 parent
551871a
commit 02e3527
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Tests for calls to the /orgs/{org}/teams/{team}/members API. | ||
mod mock_error; | ||
|
||
use mock_error::setup_error_handler; | ||
use octocrab::{Octocrab, Page}; | ||
use serde::{Deserialize, Serialize}; | ||
use wiremock::{ | ||
matchers::{method, path}, | ||
Mock, MockServer, ResponseTemplate, | ||
}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct FakePage<T> { | ||
items: Vec<T>, | ||
} | ||
|
||
async fn setup_api(template: ResponseTemplate) -> MockServer { | ||
let org = "org"; | ||
let team = "team-name"; | ||
let repo = "testing"; | ||
let mock_server = MockServer::start().await; | ||
|
||
Mock::given(method("DELETE")) | ||
.and(path(format!("/orgs/{org}/teams/{team}/repos/{org}/{repo}"))) | ||
.respond_with(template) | ||
.mount(&mock_server) | ||
.await; | ||
setup_error_handler( | ||
&mock_server, | ||
&format!("DELETE on /orgs/{org}/teams/{team}/repos/{org}/{repo} was not received"), | ||
) | ||
.await; | ||
mock_server | ||
} | ||
|
||
fn setup_octocrab(uri: &str) -> Octocrab { | ||
Octocrab::builder().base_uri(uri).unwrap().build().unwrap() | ||
} | ||
|
||
const ORG: &str = "org"; | ||
const TEAM: &str = "team-name"; | ||
const REPO: &str = "testing"; | ||
|
||
#[tokio::test] | ||
async fn should_remove_team_repo() { | ||
let template = ResponseTemplate::new(204); | ||
let mock_server = setup_api(template).await; | ||
let client = setup_octocrab(&mock_server.uri()); | ||
let teams = client.teams(ORG.to_owned()); | ||
|
||
let result = teams | ||
.repos(TEAM.to_owned()) | ||
.remove(ORG.to_owned(), REPO.to_owned()) | ||
.await; | ||
assert!( | ||
result.is_ok(), | ||
"expected successful result, got error: {:#?}", | ||
result | ||
); | ||
eprintln!("Result: {result:#?}"); | ||
} | ||
|
||
#[tokio::test] | ||
async fn should_add_or_update_team_repo() {} |