This commit is contained in:
Kaan Barmore-Genç 2022-08-19 16:45:15 -04:00 committed by GitHub
parent 80d8c8885b
commit 9e9940dc5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View file

@ -22,3 +22,6 @@ anyhow = "1.0"
governor = "0.4" governor = "0.4"
# TODO: Relies on a yet-unreleased interface. Switch to an actual crate release once available # TODO: Relies on a yet-unreleased interface. Switch to an actual crate release once available
die-exit = { git = "https://github.com/Xavientois/die.git", rev = "31d3801f4e21654b0b28430987b1e21fc7728676" } die-exit = { git = "https://github.com/Xavientois/die.git", rev = "31d3801f4e21654b0b28430987b1e21fc7728676" }
[dev-dependencies]
httpmock = "0.6"

View file

@ -123,3 +123,32 @@ async fn main() -> anyhow::Result<()> {
return Ok(()); return Ok(());
} }
#[cfg(test)]
mod tests {
use httpmock::MockServer;
use serde_json::json;
#[test]
fn create_repo_success_test() {
// Arrange
let server = MockServer::start();
let mock = server.mock(|when, then| {
when.method("POST")
.path("/user/repos")
.header("Authorization", "token TOKEN")
.header("Content-Type", "application/json");
then.status(201)
.json_body(json!({ "html_url": "http://example.com" }));
});
let client = GithubClient::new("TOKEN", &server.base_url());
// Act
let result = client.create_repo("myRepo");
// Assert
mock.assert();
assert_eq!(result.is_ok(), true);
assert_eq!(result.unwrap(), "http://example.com");
}
}