summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2023-12-12 03:40:23 +0100
committerCyborus <cyborus@cyborus.xyz>2023-12-12 03:40:23 +0100
commit051f18eddcd4333584b1ec9f68f215e534006f47 (patch)
tree847a378ef7fbd537b50e7bcc1ca89e4ca474406e /tests
parentMerge pull request 'test repository methods' (#24) from repo-tests into main (diff)
downloadforgejo-api-051f18eddcd4333584b1ec9f68f215e534006f47.tar.xz
forgejo-api-051f18eddcd4333584b1ec9f68f215e534006f47.zip
praise rustfmt
Diffstat (limited to 'tests')
-rw-r--r--tests/ci_test.rs124
1 files changed, 96 insertions, 28 deletions
diff --git a/tests/ci_test.rs b/tests/ci_test.rs
index 52e5efe..b949b7f 100644
--- a/tests/ci_test.rs
+++ b/tests/ci_test.rs
@@ -1,5 +1,5 @@
+use eyre::{ensure, eyre, WrapErr};
use forgejo_api::Forgejo;
-use eyre::{eyre, ensure, WrapErr};
#[tokio::test]
async fn ci() -> eyre::Result<()> {
@@ -34,13 +34,19 @@ async fn ci() -> eyre::Result<()> {
async fn user(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
let myself = api.myself().await?;
ensure!(myself.is_admin, "user should be admin");
- ensure!(myself.login == "TestingAdmin", "user should be named \"TestingAdmin\"");
+ ensure!(
+ myself.login == "TestingAdmin",
+ "user should be named \"TestingAdmin\""
+ );
let myself_indirect = api
.get_user("TestingAdmin")
.await?
.ok_or_else(|| eyre!("\"TestingAdmin\" not found, but should have been."))?;
- ensure!(myself == myself_indirect, "result of `myself` does not match result of `get_user`");
+ ensure!(
+ myself == myself_indirect,
+ "result of `myself` does not match result of `get_user`"
+ );
let following = api.get_following("TestingAdmin").await?;
ensure!(following == Some(Vec::new()), "following list not empty");
@@ -57,15 +63,20 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
cmd.current_dir("/test_repo");
cmd
};
- let _ = git().args(["config", "--global", "init.defaultBranch", "main"]).status()?;
+ let _ = git()
+ .args(["config", "--global", "init.defaultBranch", "main"])
+ .status()?;
let _ = git().args(["init"]).status()?;
- let _ = git().args(["config", "user.name", "TestingAdmin"]).status()?;
- let _ = git().args(["config", "user.email", "admin@noreply.example.org"]).status()?;
+ let _ = git()
+ .args(["config", "user.name", "TestingAdmin"])
+ .status()?;
+ let _ = git()
+ .args(["config", "user.email", "admin@noreply.example.org"])
+ .status()?;
tokio::fs::write("/test_repo/README.md", "# Test\nThis is a test repo").await?;
let _ = git().args(["add", "."]).status()?;
let _ = git().args(["commit", "-m", "initial commit"]).status()?;
-
let repo_opt = forgejo_api::CreateRepoOption {
auto_init: false,
default_branch: "main".into(),
@@ -80,19 +91,31 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
trust_model: forgejo_api::TrustModel::Default,
};
let remote_repo = api.create_repo(repo_opt).await?;
- ensure!(remote_repo.has_pull_requests, "repo does not accept pull requests");
- ensure!(remote_repo.owner.login == "TestingAdmin", "repo owner is not \"TestingAdmin\"");
+ ensure!(
+ remote_repo.has_pull_requests,
+ "repo does not accept pull requests"
+ );
+ ensure!(
+ remote_repo.owner.login == "TestingAdmin",
+ "repo owner is not \"TestingAdmin\""
+ );
ensure!(remote_repo.name == "test", "repo owner is not \"test\"");
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
let mut remote_url = remote_repo.clone_url.clone();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
- let _ = git().args(["remote", "add", "origin", remote_url.as_str()]).status()?;
+ let _ = git()
+ .args(["remote", "add", "origin", remote_url.as_str()])
+ .status()?;
let _ = git().args(["push", "-u", "origin", "main"]).status()?;
let _ = git().args(["switch", "-c", "test"]).status()?;
- tokio::fs::write("/test_repo/example.rs", "fn add_one(x: u32) -> u32 { x + 1 }").await?;
+ tokio::fs::write(
+ "/test_repo/example.rs",
+ "fn add_one(x: u32) -> u32 { x + 1 }",
+ )
+ .await?;
let _ = git().args(["add", "."]).status()?;
let _ = git().args(["commit", "-m", "egg"]).status()?;
let _ = git().args(["push", "-u", "origin", "test"]).status()?;
@@ -108,9 +131,15 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
milestone: None,
title: "test pr".into(),
};
- let pr = api.create_pr("TestingAdmin", "test", pr_opt).await.wrap_err("couldn't create pr")?;
+ let pr = api
+ .create_pr("TestingAdmin", "test", pr_opt)
+ .await
+ .wrap_err("couldn't create pr")?;
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
- let is_merged = api.is_merged("TestingAdmin", "test", pr.number).await.wrap_err_with(|| eyre!("couldn't find unmerged pr {}", pr.number))?;
+ let is_merged = api
+ .is_merged("TestingAdmin", "test", pr.number)
+ .await
+ .wrap_err_with(|| eyre!("couldn't find unmerged pr {}", pr.number))?;
ensure!(!is_merged, "pr should not yet be merged");
let merge_opt = forgejo_api::MergePullRequestOption {
act: forgejo_api::MergePrAction::Merge,
@@ -122,20 +151,33 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
head_commit_id: None,
merge_when_checks_succeed: None,
};
- api.merge_pr("TestingAdmin", "test", pr.number, merge_opt).await.wrap_err_with(|| eyre!("couldn't merge pr {}", pr.number))?;
- let is_merged = api.is_merged("TestingAdmin", "test", pr.number).await.wrap_err_with(|| eyre!("couldn't find merged pr {}", pr.number))?;
+ api.merge_pr("TestingAdmin", "test", pr.number, merge_opt)
+ .await
+ .wrap_err_with(|| eyre!("couldn't merge pr {}", pr.number))?;
+ let is_merged = api
+ .is_merged("TestingAdmin", "test", pr.number)
+ .await
+ .wrap_err_with(|| eyre!("couldn't find merged pr {}", pr.number))?;
ensure!(is_merged, "pr should be merged");
let _ = git().args(["fetch"]).status()?;
let _ = git().args(["pull"]).status()?;
- ensure!(api.get_releases("TestingAdmin", "test", forgejo_api::ReleaseQuery::default()).await.wrap_err("releases list not found")?.is_empty(), "there should be no releases yet");
+ ensure!(
+ api.get_releases("TestingAdmin", "test", forgejo_api::ReleaseQuery::default())
+ .await
+ .wrap_err("releases list not found")?
+ .is_empty(),
+ "there should be no releases yet"
+ );
let tag_opt = forgejo_api::CreateTagOption {
message: Some("This is a tag!".into()),
tag_name: "v1.0".into(),
target: None,
};
- api.create_tag("TestingAdmin", "test", tag_opt).await.wrap_err("failed to create tag")?;
+ api.create_tag("TestingAdmin", "test", tag_opt)
+ .await
+ .wrap_err("failed to create tag")?;
let release_opt = forgejo_api::CreateReleaseOption {
body: "This is a release!".into(),
@@ -145,23 +187,49 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
tag_name: "v1.0".into(),
target_commitish: None,
};
- let release = api.create_release("TestingAdmin", "test", release_opt).await.wrap_err("failed to create release")?;
+ let release = api
+ .create_release("TestingAdmin", "test", release_opt)
+ .await
+ .wrap_err("failed to create release")?;
let edit_release = forgejo_api::EditReleaseOption {
draft: Some(false),
..Default::default()
};
- api.edit_release("TestingAdmin", "test", release.id, edit_release).await.wrap_err("failed to edit release")?;
-
- let release_by_tag = api.get_release_by_tag("TestingAdmin", "test", "v1.0").await.wrap_err("failed to find release")?;
- let release_latest = api.latest_release("TestingAdmin", "test").await.wrap_err("failed to find latest release")?;
+ api.edit_release("TestingAdmin", "test", release.id, edit_release)
+ .await
+ .wrap_err("failed to edit release")?;
+
+ let release_by_tag = api
+ .get_release_by_tag("TestingAdmin", "test", "v1.0")
+ .await
+ .wrap_err("failed to find release")?;
+ let release_latest = api
+ .latest_release("TestingAdmin", "test")
+ .await
+ .wrap_err("failed to find latest release")?;
ensure!(release_by_tag == release_latest, "releases not equal");
- let attachment = api.create_release_attachment("TestingAdmin", "test", release.id, "test.txt", b"This is a file!".to_vec()).await.wrap_err("failed to create release attachment")?;
- api.delete_release_attachment("TestingAdmin", "test", release.id, attachment.id).await.wrap_err("failed to deleted attachment")?;
-
- api.delete_release("TestingAdmin", "test", release.id).await.wrap_err("failed to delete release")?;
-
- api.delete_tag("TestingAdmin", "test", "v1.0").await.wrap_err("failed to delete release")?;
+ let attachment = api
+ .create_release_attachment(
+ "TestingAdmin",
+ "test",
+ release.id,
+ "test.txt",
+ b"This is a file!".to_vec(),
+ )
+ .await
+ .wrap_err("failed to create release attachment")?;
+ api.delete_release_attachment("TestingAdmin", "test", release.id, attachment.id)
+ .await
+ .wrap_err("failed to deleted attachment")?;
+
+ api.delete_release("TestingAdmin", "test", release.id)
+ .await
+ .wrap_err("failed to delete release")?;
+
+ api.delete_tag("TestingAdmin", "test", "v1.0")
+ .await
+ .wrap_err("failed to delete release")?;
Ok(())
}