Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E tests for torrent routes #121

Merged
merged 5 commits into from
Apr 28, 2023
Merged

E2E tests for torrent routes #121

merged 5 commits into from
Apr 28, 2023

Conversation

josecelano
Copy link
Member

E2E tests for API torrent routes.

To submit multipart forms with reqwest. It'll be used in E2E tests.
It'll be used to store temporary torrent files for E2E tests.
It'll be used to generate unique identifiers for entities in E2E tests.
@josecelano josecelano linked an issue Apr 26, 2023 that may be closed by this pull request
@josecelano
Copy link
Member Author

josecelano commented Apr 26, 2023

Hi @WarmBeer @da2ce7,

Create random torrent files

I needed to generate random torrents for the E2E tests. I found this repo: https://github.com/casey/intermodal. It's a command-line tool to generate torrents.

I think it could be pretty helpful for testing all our BitTorrent-related projects.

Unfortunately, they have not published a library yet (only the binary), but in this case, the wrapper is straightforward:

    fn create_torrent_file(dir: &Path, file_name: &str) -> PathBuf {
        let input_file_path = Path::new(dir).join(file_name);
        let output_file_path = Path::new(dir).join(format!("{file_name}.torrent"));

        let output = Command::new("imdl")
            .args(["torrent", "create", "--show"])
            .args(["--input", &format!("{}", input_file_path.to_string_lossy())])
            .args(["--output", &format!("{}", output_file_path.to_string_lossy())])
            .output()
            .expect("failed to create torrent file: {output_file_path}");

        //io::stdout().write_all(&output.stdout).unwrap();
        io::stderr().write_all(&output.stderr).unwrap();

        output_file_path
    }

Since we use it for E2E testing, it's not a big problem. But for unit testing, having a system dependency would not be a good option.

Extracting logic for torrent edition

I think mods src/utils/parse_torrent.rs and src/models/torrent_file.rs are good candidates to be extracted into a primitives crate for torrent files edition. It could become a library like imdl.

Autoincrement IDs

IDs generated by the database are sometimes a pain because it makes it harder to write the asserts. For example, when you upload a torrent the response contains the ID. I'm going to add the infohash, so I can be sure the torrent was added to the index. In general, I think maybe using the infohash instead of those IDs would improve:

  • Testability
  • DB portability (exports/imports)

If we have cases where the infohash is not a real ID in our domain we could generate a UUID.
In general, I prefer UUID over DB autoincrement.

Finally, I still have to add more tests to finish this PR.

It'll be used to check if the command `imdl` is installed.
It's needed in E2E tests to generate random torrents.
@josecelano josecelano marked this pull request as ready for review April 27, 2023 20:21
@josecelano josecelano added the Testing Checking Torrust label Apr 27, 2023
@josecelano
Copy link
Member Author

ACK e3ed344

@josecelano
Copy link
Member Author

Hi @da2ce7 @WarmBeer, this is ready to review.

@josecelano josecelano merged commit 79c54e8 into torrust:develop Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing Checking Torrust
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

E2E tests: torrent routes
1 participant