Skip to content

Commit

Permalink
test(test/project): add e2e_lib_project_list_all_works
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
  • Loading branch information
gierens committed Sep 28, 2024
1 parent fdfb49b commit 48ac077
Showing 1 changed file with 69 additions and 10 deletions.
79 changes: 69 additions & 10 deletions test/tests/user/project/list.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 48ac077

Please sign in to comment.