Skip to content

Commit

Permalink
fix: run E2E tests that require a running tracker
Browse files Browse the repository at this point in the history
We have to start the test env before the condition to skip the test:

```
if !env.provides_a_tracker() {
   println!("test skipped. It requires a tracker to be running.");
   return;
}
```

Itherwise the test is never executed, even when you are using the
shared env:

```
TORRUST_IDX_BACK_E2E_SHARED=true cargo test
```
  • Loading branch information
josecelano committed May 5, 2023
1 parent 234e07a commit 4782f67
Showing 1 changed file with 23 additions and 54 deletions.
77 changes: 23 additions & 54 deletions tests/e2e/contexts/torrent/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ mod for_guests {
#[tokio::test]
async fn it_should_allow_guests_to_get_torrents() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let uploader = new_logged_in_user(&env).await;
Expand All @@ -64,16 +61,13 @@ mod for_guests {
#[tokio::test]
async fn it_should_allow_guests_to_get_torrent_details_searching_by_id() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let uploader = new_logged_in_user(&env).await;
Expand Down Expand Up @@ -121,16 +115,13 @@ mod for_guests {
#[tokio::test]
async fn it_should_allow_guests_to_download_a_torrent_file_searching_by_id() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let uploader = new_logged_in_user(&env).await;
Expand Down Expand Up @@ -160,16 +151,13 @@ mod for_guests {
#[tokio::test]
async fn it_should_not_allow_guests_to_delete_torrents() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let uploader = new_logged_in_user(&env).await;
Expand All @@ -193,16 +181,13 @@ mod for_authenticated_users {
#[tokio::test]
async fn it_should_allow_authenticated_users_to_upload_new_torrents() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token);

Expand Down Expand Up @@ -245,14 +230,13 @@ mod for_authenticated_users {
#[tokio::test]
async fn it_should_not_allow_uploading_a_torrent_with_a_title_that_already_exists() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token);

Expand All @@ -268,23 +252,20 @@ mod for_authenticated_users {
let form: UploadTorrentMultipartForm = second_torrent.index_info.into();
let response = client.upload_torrent(form.into()).await;

assert_eq!(response.body, "");
assert_eq!(response.body, "{\"error\":\"This torrent title has already been used.\"}");
assert_eq!(response.status, 400);
}

#[tokio::test]
async fn it_should_not_allow_uploading_a_torrent_with_a_infohash_that_already_exists() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token);

Expand Down Expand Up @@ -314,16 +295,13 @@ mod for_authenticated_users {
#[tokio::test]
async fn it_should_not_allow_non_admins_to_delete_torrents() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let (_test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await;

Expand All @@ -346,16 +324,13 @@ mod for_authenticated_users {
#[tokio::test]
async fn it_should_allow_torrent_owners_to_update_their_torrents() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await;

Expand Down Expand Up @@ -395,16 +370,13 @@ mod for_authenticated_users {
#[tokio::test]
async fn it_should_allow_admins_to_delete_torrents_searching_by_id() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let (_test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await;

Expand All @@ -422,16 +394,13 @@ mod for_authenticated_users {
#[tokio::test]
async fn it_should_allow_admins_to_update_someone_elses_torrents() {
let mut env = TestEnv::new();
env.start().await;

if !env.provides_a_tracker() {
// This test requires the tracker to be running,
// because when you upload a torrent, it's added to the tracker
// whitelist.
println!("test skipped. It requires a tracker to be running.");
return;
}

env.start().await;

let uploader = new_logged_in_user(&env).await;
let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await;

Expand Down

0 comments on commit 4782f67

Please sign in to comment.