summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-01-18 22:48:18 +0100
committerCyborus <cyborus@cyborus.xyz>2024-01-18 22:48:18 +0100
commit6d2c1ce21cb9f838a43491a50a22c9e38741a7e5 (patch)
tree3dce68cd820389389f4e02ad52f76884a803b5f3 /tests
parentadd additional properties support (diff)
downloadforgejo-api-6d2c1ce21cb9f838a43491a50a22c9e38741a7e5.tar.xz
forgejo-api-6d2c1ce21cb9f838a43491a50a22c9e38741a7e5.zip
update tests to new api
Diffstat (limited to 'tests')
-rw-r--r--tests/ci_test.rs255
1 files changed, 144 insertions, 111 deletions
diff --git a/tests/ci_test.rs b/tests/ci_test.rs
index c7e3b90..7bb1019 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 forgejo_api::{Forgejo, structs::*};
#[tokio::test]
async fn ci() -> eyre::Result<()> {
@@ -32,27 +32,29 @@ async fn ci() -> eyre::Result<()> {
Ok(())
}
-async fn user(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
- let myself = api.myself().await?;
- ensure!(myself.is_admin, "user should be admin");
+async fn user(api: &Forgejo) -> eyre::Result<()> {
+ let myself = api.user_get_current().await?;
+ ensure!(myself.is_admin.unwrap(), "user should be admin");
ensure!(
- myself.login == "TestingAdmin",
+ myself.login.as_ref().unwrap() == "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."))?;
+ .user_get("TestingAdmin")
+ .await?;
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");
- let followers = api.get_followers("TestingAdmin").await?;
- ensure!(followers == Some(Vec::new()), "follower list not empty");
+ let query = UserListFollowingQuery { page: None, limit: None };
+ let following = api.user_list_following("TestingAdmin", query).await?;
+ ensure!(following == Vec::new(), "following list not empty");
+
+ let query = UserListFollowersQuery { page: None, limit: None };
+ let followers = api.user_list_followers("TestingAdmin", query).await?;
+ ensure!(followers == Vec::new(), "follower list not empty");
let url = url::Url::parse(&std::env::var("FORGEJO_API_CI_INSTANCE_URL")?)?;
let password_api = Forgejo::new(
@@ -66,7 +68,7 @@ async fn user(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
.wrap_err("failed to log in using username and password")?;
ensure!(
- api.myself().await? == password_api.myself().await?,
+ api.user_get_current().await? == password_api.user_get_current().await?,
"users not equal comparing token-auth and pass-auth"
);
@@ -94,32 +96,32 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
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(),
+ let repo_opt = CreateRepoOption {
+ auto_init: Some(false),
+ default_branch: Some("main".into()),
description: Some("Test Repo".into()),
- gitignores: "".into(),
- issue_labels: "".into(),
- license: "".into(),
+ gitignores: Some("".into()),
+ issue_labels: Some("".into()),
+ license: Some("".into()),
name: "test".into(),
- private: false,
- readme: "".into(),
- template: false,
- trust_model: forgejo_api::TrustModel::Default,
+ private: Some(false),
+ readme: None,
+ template: Some(false),
+ trust_model: Some("default".into()),
};
- let remote_repo = api.create_repo(repo_opt).await?;
+ let remote_repo = api.create_current_user_repo(repo_opt).await?;
ensure!(
- remote_repo.has_pull_requests,
+ remote_repo.has_pull_requests.unwrap(),
"repo does not accept pull requests"
);
ensure!(
- remote_repo.owner.login == "TestingAdmin",
+ remote_repo.owner.as_ref().unwrap().login.as_ref().unwrap() == "TestingAdmin",
"repo owner is not \"TestingAdmin\""
);
- ensure!(remote_repo.name == "test", "repo owner is not \"test\"");
+ ensure!(remote_repo.name.as_ref().unwrap() == "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();
+ let mut remote_url = remote_repo.clone_url.clone().unwrap();
remote_url.set_username("TestingAdmin").unwrap();
remote_url.set_password(Some("password")).unwrap();
let _ = git()
@@ -137,29 +139,29 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
let _ = git().args(["commit", "-m", "egg"]).status()?;
let _ = git().args(["push", "-u", "origin", "test"]).status()?;
- let pr_opt = forgejo_api::CreatePullRequestOption {
+ let pr_opt = CreatePullRequestOption {
assignee: None,
- assignees: vec!["TestingAdmin".into()],
- base: "main".into(),
- body: "This is a test PR".into(),
+ assignees: Some(vec!["TestingAdmin".into()]),
+ base: Some("main".into()),
+ body: Some("This is a test PR".into()),
due_date: None,
- head: "test".into(),
- labels: Vec::new(),
+ head: Some("test".into()),
+ labels: None,
milestone: None,
- title: "test pr".into(),
+ title: Some("test pr".into()),
};
let pr = api
- .create_pr("TestingAdmin", "test", pr_opt)
+ .repo_create_pull_request("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)
+ .repo_pull_request_is_merged("TestingAdmin", "test", pr.number.unwrap())
.await
- .wrap_err_with(|| eyre!("couldn't find unmerged pr {}", pr.number))?;
+ .is_ok();
ensure!(!is_merged, "pr should not yet be merged");
- let merge_opt = forgejo_api::MergePullRequestOption {
- act: forgejo_api::MergePrAction::Merge,
+ let merge_opt = MergePullRequestOption {
+ r#do: "merge".into(),
merge_commit_id: None,
merge_message_field: None,
merge_title_field: None,
@@ -168,103 +170,106 @@ 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)
+ api.repo_merge_pull_request("TestingAdmin", "test", pr.number.unwrap(), merge_opt)
.await
- .wrap_err_with(|| eyre!("couldn't merge pr {}", pr.number))?;
+ .wrap_err_with(|| eyre!("couldn't merge pr {}", pr.number.unwrap()))?;
let is_merged = api
- .is_merged("TestingAdmin", "test", pr.number)
+ .repo_pull_request_is_merged("TestingAdmin", "test", pr.number.unwrap())
.await
- .wrap_err_with(|| eyre!("couldn't find merged pr {}", pr.number))?;
+ .is_ok();
ensure!(is_merged, "pr should be merged");
let _ = git().args(["fetch"]).status()?;
let _ = git().args(["pull"]).status()?;
+ let query = RepoListReleasesQuery {
+ draft: None,
+ pre_release: None,
+ per_page: None,
+ page: None,
+ limit: None,
+ };
ensure!(
- api.get_releases("TestingAdmin", "test", forgejo_api::ReleaseQuery::default())
+ api.repo_list_releases("TestingAdmin", "test", query)
.await
.wrap_err("releases list not found")?
.is_empty(),
"there should be no releases yet"
);
- let tag_opt = forgejo_api::CreateTagOption {
+ let tag_opt = CreateTagOption {
message: Some("This is a tag!".into()),
tag_name: "v1.0".into(),
target: None,
};
- api.create_tag("TestingAdmin", "test", tag_opt)
+ api.repo_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(),
- draft: true,
- name: "v1.0".into(),
- prerelease: false,
+ let release_opt = CreateReleaseOption {
+ body: Some("This is a release!".into()),
+ draft: Some(true),
+ name: Some("v1.0".into()),
+ prerelease: Some(false),
tag_name: "v1.0".into(),
target_commitish: None,
};
let release = api
- .create_release("TestingAdmin", "test", release_opt)
+ .repo_create_release("TestingAdmin", "test", release_opt)
.await
.wrap_err("failed to create release")?;
- let edit_release = forgejo_api::EditReleaseOption {
+ let edit_release = EditReleaseOption {
+ body: None,
draft: Some(false),
- ..Default::default()
+ name: None,
+ prerelease: None,
+ tag_name: None,
+ target_commitish: None,
};
- api.edit_release("TestingAdmin", "test", release.id, edit_release)
+ api.repo_edit_release("TestingAdmin", "test", release.id.unwrap(), edit_release)
.await
.wrap_err("failed to edit release")?;
let release_by_tag = api
- .get_release_by_tag("TestingAdmin", "test", "v1.0")
+ .repo_get_release_by_tag("TestingAdmin", "test", "v1.0")
.await
.wrap_err("failed to find release")?;
let release_latest = api
- .latest_release("TestingAdmin", "test")
+ .repo_get_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(
+ .repo_create_release_attachment(
"TestingAdmin",
"test",
- release.id,
- "test.txt",
+ release.id.unwrap(),
b"This is a file!".to_vec(),
+ RepoCreateReleaseAttachmentQuery { name: Some("test.txt".into()) },
)
.await
.wrap_err("failed to create release attachment")?;
ensure!(
- api.download_release_attachment("TestingAdmin", "test", release.id, attachment.id)
+ &*api.download_release_attachment("TestingAdmin", "test", release.id.unwrap(), attachment.id.unwrap())
.await?
- .as_deref()
- == Some(b"This is a file!"),
+ == b"This is a file!",
"couldn't download attachment"
);
- ensure!(
- api.download_zip_archive("TestingAdmin", "test", "v1.0")
- .await?
- .is_some(),
- "couldn't download zip archive"
- );
- ensure!(
- api.download_tarball_archive("TestingAdmin", "test", "v1.0")
- .await?
- .is_some(),
- "couldn't download tape archive"
- );
+ let _zip_archive = api.repo_get_archive("TestingAdmin", "test", "v1.0.zip")
+ .await.unwrap();
+ let _tar_archive = api.repo_get_archive("TestingAdmin", "test", "v1.0.tar.gz")
+ .await.unwrap();
+ // check these contents when their return value is fixed
- api.delete_release_attachment("TestingAdmin", "test", release.id, attachment.id)
+ api.repo_delete_release_attachment("TestingAdmin", "test", release.id.unwrap(), attachment.id.unwrap())
.await
.wrap_err("failed to deleted attachment")?;
- api.delete_release("TestingAdmin", "test", release.id)
+ api.repo_delete_release("TestingAdmin", "test", release.id.unwrap())
.await
.wrap_err("failed to delete release")?;
- api.delete_tag("TestingAdmin", "test", "v1.0")
+ api.repo_delete_tag("TestingAdmin", "test", "v1.0")
.await
.wrap_err("failed to delete release")?;
@@ -272,124 +277,152 @@ async fn repo(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
}
async fn admin(api: &forgejo_api::Forgejo) -> eyre::Result<()> {
- let user_opt = forgejo_api::CreateUserOption {
+ let user_opt = CreateUserOption {
created_at: None,
email: "user@noreply.example.org".into(),
full_name: None,
login_name: None,
- must_change_password: false,
- password: "userpass".into(),
- restricted: false,
- send_notify: true,
+ must_change_password: None,
+ password: Some("userpass".into()),
+ restricted: Some(false),
+ send_notify: Some(true),
source_id: None,
username: "Pipis".into(),
- visibility: "public".into(),
+ visibility: Some("public".into()),
};
let _ = api
.admin_create_user(user_opt)
.await
.wrap_err("failed to create user")?;
+ let query = AdminSearchUsersQuery {
+ source_id: None,
+ login_name: None,
+ page: None,
+ limit: None,
+ };
let users = api
- .admin_users(forgejo_api::AdminUserQuery::default())
+ .admin_search_users(query)
.await
.wrap_err("failed to search users")?;
ensure!(
- users.iter().find(|u| u.login == "Pipis").is_some(),
+ users.iter().find(|u| u.login.as_ref().unwrap() == "Pipis").is_some(),
"could not find new user"
);
+ let query = AdminGetAllEmailsQuery {
+ page: None,
+ limit: None,
+ };
let users = api
- .admin_get_emails(forgejo_api::EmailListQuery::default())
+ .admin_get_all_emails(query)
.await
.wrap_err("failed to search emails")?;
ensure!(
users
.iter()
- .find(|u| u.email == "user@noreply.example.org")
+ .find(|u| u.email.as_ref().unwrap() == "user@noreply.example.org")
.is_some(),
"could not find new user"
);
- let org_opt = forgejo_api::CreateOrgOption {
+ let org_opt = CreateOrgOption {
description: None,
+ email: None,
full_name: None,
location: None,
repo_admin_change_team_access: None,
username: "test-org".into(),
- visibility: forgejo_api::OrgVisibility::Public,
+ visibility: Some("public".into()),
website: None,
};
let _ = api
.admin_create_org("Pipis", org_opt)
.await
.wrap_err("failed to create org")?;
+ let query = AdminGetAllOrgsQuery {
+ page: None,
+ limit: None,
+ };
ensure!(
- !api.admin_get_orgs(forgejo_api::AdminOrganizationQuery::default())
+ !api.admin_get_all_orgs(query)
.await?
.is_empty(),
"org list empty"
);
- let key_opt = forgejo_api::CreateKeyOption {
+ let key_opt = CreateKeyOption {
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN68ehQAsbGEwlXPa2AxbAh1QxFQrtRel2jeC0hRlPc1 user@noreply.example.org".into(),
read_only: None,
title: "Example Key".into(),
};
let key = api
- .admin_add_key("Pipis", key_opt)
+ .admin_create_public_key("Pipis", key_opt)
.await
.wrap_err("failed to create key")?;
- api.admin_delete_key("Pipis", key.id)
+ api.admin_delete_user_public_key("Pipis", key.id.unwrap())
.await
.wrap_err("failed to delete key")?;
- let rename_opt = forgejo_api::RenameUserOption {
+ let rename_opt = RenameUserOption {
new_username: "Bepis".into(),
};
api.admin_rename_user("Pipis", rename_opt)
.await
.wrap_err("failed to rename user")?;
- api.admin_delete_user("Bepis", true)
+ let query = AdminDeleteUserQuery {
+ purge: Some(true),
+ };
+ api.admin_delete_user("Bepis", query)
.await
.wrap_err("failed to delete user")?;
+ let query = AdminDeleteUserQuery {
+ purge: Some(true),
+ };
ensure!(
- api.admin_delete_user("Ghost", true).await.is_err(),
+ api.admin_delete_user("Ghost", query).await.is_err(),
"deleting fake user should fail"
);
+ let query = AdminCronListQuery {
+ page: None,
+ limit: None,
+ };
let crons = api
- .admin_get_crons(forgejo_api::CronQuery::default())
+ .admin_cron_list(query)
.await
.wrap_err("failed to get crons list")?;
- api.admin_run_cron(&crons.get(0).ok_or_else(|| eyre!("no crons"))?.name)
+ api.admin_cron_run(&crons.get(0).ok_or_else(|| eyre!("no crons"))?.name.as_ref().unwrap())
.await
.wrap_err("failed to run cron")?;
- let hook_opt = forgejo_api::CreateHookOption {
+ let hook_opt = CreateHookOption {
active: None,
authorization_header: None,
branch_filter: None,
- config: forgejo_api::CreateHookOptionConfig {
- content_type: "json".into(),
- url: url::Url::parse("http://test.local/").unwrap(),
- other: Default::default(),
+ config: CreateHookOptionConfig {
+ // content_type: "json".into(),
+ // url: url::Url::parse("http://test.local/").unwrap(),
+ additional: [("content_type".into(), "json".into()), ("url".into(), "http://test.local/".into())].into(),
},
- events: Vec::new(),
- _type: forgejo_api::HookType::Forgejo,
+ events: Some(Vec::new()),
+ r#type: "forgejo".into(),
};
// yarr har har me matey this is me hook
let hook = api
.admin_create_hook(hook_opt)
.await
.wrap_err("failed to create hook")?;
- let edit_hook = forgejo_api::EditHookOption {
+ let edit_hook = EditHookOption {
active: Some(true),
- ..Default::default()
+ authorization_header: None,
+ branch_filter: None,
+ config: None,
+ events: None,
};
- api.admin_edit_hook(hook.id, edit_hook)
+ api.admin_edit_hook(hook.id.unwrap(), edit_hook)
.await
.wrap_err("failed to edit hook")?;
- api.admin_delete_hook(hook.id)
+ api.admin_delete_hook(hook.id.unwrap())
.await
.wrap_err("failed to delete hook")?;