diff options
author | Daniel Baumann <daniel@debian.org> | 2024-12-24 09:06:30 +0100 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-24 09:06:30 +0100 |
commit | e0a5f5a9eeb789b191c27a9c9dd3890846f8c5ab (patch) | |
tree | 3f920540ce7a7ef773cb02da74f1f9bdd4e4690f /tests | |
parent | Adding debian version 0.4.1-1. (diff) | |
download | forgejo-api-e0a5f5a9eeb789b191c27a9c9dd3890846f8c5ab.tar.xz forgejo-api-e0a5f5a9eeb789b191c27a9c9dd3890846f8c5ab.zip |
Merging upstream version 0.5.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/admin.rs | 98 | ||||
-rw-r--r-- | tests/repo.rs | 5 | ||||
-rw-r--r-- | tests/user.rs | 2 |
3 files changed, 95 insertions, 10 deletions
diff --git a/tests/admin.rs b/tests/admin.rs index 38d47ba..674ca16 100644 --- a/tests/admin.rs +++ b/tests/admin.rs @@ -30,10 +30,7 @@ async fn user() { .await .expect("failed to search users"); assert!( - users - .iter() - .find(|u| u.login.as_ref().unwrap() == "Pipis") - .is_some(), + users.iter().any(|u| u.login.as_ref().unwrap() == "Pipis"), "could not find new user" ); let query = AdminGetAllEmailsQuery::default(); @@ -44,8 +41,7 @@ async fn user() { assert!( users .iter() - .find(|u| u.email.as_ref().unwrap() == "pipis@noreply.example.org") - .is_some(), + .any(|u| u.email.as_ref().unwrap() == "pipis@noreply.example.org"), "could not find new user" ); } @@ -153,7 +149,7 @@ async fn cron() { .admin_cron_list(query) .await .expect("failed to get crons list"); - api.admin_cron_run(&crons.get(0).expect("no crons").name.as_ref().unwrap()) + api.admin_cron_run(crons.first().expect("no crons").name.as_ref().unwrap()) .await .expect("failed to run cron"); } @@ -192,3 +188,91 @@ async fn hook() { .await .expect("failed to delete hook"); } + +#[tokio::test] +async fn quota_group() { + let api = common::login(); + + let user_opts = CreateUserOption { + created_at: None, + email: "1997@example.com".into(), + full_name: None, + login_name: None, + must_change_password: None, + password: Some("dialtone".into()), + restricted: None, + send_notify: None, + source_id: None, + username: "salesman".into(), + visibility: None, + }; + api.admin_create_user(user_opts) + .await + .expect("failed to create user"); + + let group = CreateQuotaGroupOptions { + name: Some("no doing anything".into()), + rules: Some(vec![CreateQuotaRuleOptions { + limit: Some(0), + name: Some("blah".into()), + subjects: Some(vec![CreateQuotaRuleOptionsSubjects::SizeAll]), + }]), + }; + let quota_group = api + .admin_create_quota_group(group) + .await + .expect("failed to create quota group"); + + api.admin_add_user_to_quota_group("no doing anything", "salesman") + .await + .expect("failed to add user to quota group"); + + assert!(quota_group + .name + .as_ref() + .is_some_and(|name| name == "no doing anything")); + assert!(quota_group + .rules + .as_ref() + .is_some_and(|rules| rules.len() == 1)); + + let quota_groups = api + .admin_list_quota_groups() + .await + .expect("failed to list quota groups"); + assert_eq!(quota_groups.len(), 1); + assert_eq!("a_groups[0], "a_group); + + let quota_info = api + .admin_get_user_quota("salesman") + .await + .expect("failed to get user quota"); + let usage = quota_info + .used + .expect("quota info missing usage info") + .size + .expect("quota info missing size info"); + assert!(usage + .git + .is_some_and(|git| git.lfs.is_some_and(|lfs| lfs == 0))); + assert!(usage + .repos + .as_ref() + .is_some_and(|repos| repos.public.is_some_and(|lfs| lfs == 0))); + assert!(usage + .repos + .is_some_and(|repos| repos.private.is_some_and(|lfs| lfs == 0))); + assert!(usage + .assets + .is_some_and(|assets| assets.artifacts.is_some_and(|lfs| lfs == 0))); + + api.admin_remove_rule_from_quota_group("no doing anything", "blah") + .await + .expect("failed to delete rule from quota group"); + api.admin_remove_user_from_quota_group("no doing anything", "salesman") + .await + .expect("failed to remove user from quota group"); + api.admin_delete_quota_group("no doing anything") + .await + .expect("failed to delete quota group"); +} diff --git a/tests/repo.rs b/tests/repo.rs index 3a0377c..b8e048a 100644 --- a/tests/repo.rs +++ b/tests/repo.rs @@ -271,7 +271,8 @@ async fn release() { "TestingAdmin", "release-test", release.id.unwrap() as u64, - b"This is a file!".to_vec(), + Some(b"This is a file!".to_vec()), + None, RepoCreateReleaseAttachmentQuery { name: Some("test.txt".into()), }, @@ -390,7 +391,7 @@ async fn team_pr_review_request() { .repo_get_pull_request("team-review-org", "team-pr-review", 1) .await .expect("couldn't get pr"); - assert_eq!(pr.requested_reviewers, Some(Vec::new())); + assert_eq!(pr.requested_reviewers, None); } #[tokio::test] diff --git a/tests/user.rs b/tests/user.rs index 3b6e0e3..51e788a 100644 --- a/tests/user.rs +++ b/tests/user.rs @@ -164,7 +164,7 @@ async fn oauth2_login() { let code = code.unwrap(); // Redeem the code and check it works - let url = url::Url::parse(&base_url).unwrap(); + let url = url::Url::parse(base_url).unwrap(); let api = forgejo_api::Forgejo::new(forgejo_api::Auth::None, url.clone()).unwrap(); let request = forgejo_api::structs::OAuthTokenRequest::Confidential { |