From 48ac077a1da3dccaa116efbf8c382d93714b617a Mon Sep 17 00:00:00 2001 From: Sandro-Alessio Gierens Date: Sat, 28 Sep 2024 16:30:41 +0200 Subject: [PATCH] test(test/project): add e2e_lib_project_list_all_works Signed-off-by: Sandro-Alessio Gierens --- test/tests/user/project/list.rs | 79 ++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/test/tests/user/project/list.rs b/test/tests/user/project/list.rs index 882c8c59..0d5b0c6f 100644 --- a/test/tests/user/project/list.rs +++ b/test/tests/user/project/list.rs @@ -1,8 +1,48 @@ use lrzcc::{Api, Token}; -use lrzcc_test::spawn_app; +use lrzcc_test::{ + random_alphanumeric_string, random_number, random_uuid, spawn_app, +}; use std::str::FromStr; use tokio::task::spawn_blocking; +#[tokio::test] +async fn e2e_lib_project_list_returns_own_project() { + // arrange + let server = spawn_app().await; + let (user, project, token) = server + .setup_test_user_and_project(true) + .await + .expect("Failed to setup test user and project."); + server + .mock_keystone_auth(&token, &user.openstack_id, &user.name) + .mount(&server.keystone_server) + .await; + + spawn_blocking(move || { + // arrange + let client = Api::new( + format!("{}/api", &server.address), + Token::from_str(&token).unwrap(), + None, + None, + ) + .unwrap(); + + // act + let projects = client.project.list().send().unwrap(); + + // assert + assert_eq!(projects.len(), 1); + let project2 = &projects[0]; + assert_eq!(project.id, project2.id); + assert_eq!(project.name, project2.name); + assert_eq!(project.openstack_id, project2.openstack_id); + assert_eq!(project.user_class, project2.user_class); + }) + .await + .unwrap(); +} + #[tokio::test] async fn e2e_lib_project_list_all_denies_access_to_normal_user() { // arrange @@ -78,7 +118,7 @@ async fn e2e_lib_project_list_by_user_class_denies_access_to_normal_user() { } #[tokio::test] -async fn e2e_lib_project_list_returns_own_project() { +async fn e2e_lib_project_list_all_works() { // arrange let server = spawn_app().await; let (user, project, token) = server @@ -100,16 +140,35 @@ async fn e2e_lib_project_list_returns_own_project() { ) .unwrap(); - // act - let projects = client.project.list().send().unwrap(); + // act part 1 - create projects + let mut expected = Vec::new(); + expected.push(project); + for _ in 0..5 { + let name = random_alphanumeric_string(10); + let openstack_id = random_uuid(); + let user_class = random_number(0..6); + let created = client + .project + .create(name.clone(), openstack_id.clone()) + .user_class(user_class) + .send() + .unwrap(); + expected.push(created); + } + + // act part 2 - list all projects + let projects = client.project.list().all().send().unwrap(); // assert - assert_eq!(projects.len(), 1); - let project2 = &projects[0]; - assert_eq!(project.id, project2.id); - assert_eq!(project.name, project2.name); - assert_eq!(project.openstack_id, project2.openstack_id); - assert_eq!(project.user_class, project2.user_class); + assert_eq!(projects.len(), expected.len()); + for (project, expected) in + projects.into_iter().zip(expected.into_iter()) + { + assert_eq!(project.id, expected.id); + assert_eq!(project.name, expected.name); + assert_eq!(project.openstack_id, expected.openstack_id); + assert_eq!(project.user_class, expected.user_class); + } }) .await .unwrap();