Skip to content

Remove dependency on imdl to run tests? #241

@josecelano

Description

@josecelano

We are using the intermodal console command to generate torrents for testing.

Whenever we need a test torrent, we generate a random text file and then use the imdl command to create the torrent file. You can read this PR comment to understand how test torrent can be generated using imdl.

We have a wrapper for the imdl command. See https://github.com/torrust/torrust-index-backend/blob/develop/tests/common/contexts/torrent/file.rs#L32-L52

Recently we have started creating the test torrent direct the same way we build to torrent files for the API endpoint to download the torrent file. That endpoint builds the torrent file from that data in the database. On this PR, we introduced a new endpoint to generate random torrent files we needed to test the frontend. We wanted to test the torrent upload with cypress.

Now that we have started generating test torrents directly without using a third-party package, I suggest removing the dependency on imdl to run unit tests.

The module to generate and parse torrent files for testing is: https://github.com/torrust/torrust-index-backend/blob/develop/tests/common/contexts/torrent/file.rs

But I see two problems:

  1. We also use the imdl to parse torrent files. We could also use our code to parse torrent files but ...
  2. I do not like to use production code to test production code.

I've opened an issue on the intermodal repo asking them for a package. If they release a package, we could start using the package instead using the console command. Alternatively, we could create our own package to create/parse torrent files.

One thing I miss from imdl is it does not give you the pieces. THis is an example output for imdl in json format:

{
  "name": "file-d6170378-2c14-4ccc-870d-2a8e15195e23.txt",
  "comment": null,
  "creation_date": 1690537323,
  "created_by": "imdl/0.1.12",
  "source": null,
  "info_hash": "a366418d2ac082bcdd57ddae3449ab4ad52f6a84",
  "torrent_size": 201,
  "content_size": 37,
  "private": false,
  "tracker": null,
  "announce_list": [],
  "update_url": null,
  "dht_nodes": [],
  "piece_size": 16384,
  "piece_count": 1,
  "file_count": 1,
  "files": [
    "file-d6170378-2c14-4ccc-870d-2a8e15195e23.txt"
  ]
}

And this is what you get using another service like: https://chocobo1.github.io/bencode_online/

{
   "created by": "imdl/0.1.12",
   "creation date": 1690537323,
   "encoding": "UTF-8",
   "info": {
      "length": 37,
      "name": "file-d6170378-2c14-4ccc-870d-2a8e15195e23.txt",
      "piece length": 16384,
      "pieces": "<hex>3E E7 F3 33 EA A5 CC D1 33 84 A3 85 F9 32 6B 2E 18 0F FB 20</hex>"
   }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions