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

Add basic unit tests #1

Open
Asone opened this issue Oct 29, 2021 · 3 comments · May be fixed by #66
Open

Add basic unit tests #1

Asone opened this issue Oct 29, 2021 · 3 comments · May be fixed by #66
Labels
enhancement New feature or request

Comments

@Asone
Copy link
Owner

Asone commented Oct 29, 2021

There's currently no unit testing onto the API demo.

At some point, it'd be nice to have those as it would :
1/ Ensure that the demo works as expected
2/ Give example of the different use cases handling to users
3/ Show how to unit test that kind of app

The first step would be to build simple unit test covering :
1/ Juniper
2/ Rocket
3/ Diesel
4/ Lnd Mock

@Asone Asone added the enhancement New feature or request label Feb 18, 2022
@Asone
Copy link
Owner Author

Asone commented Apr 9, 2022

Unit test to do with expected complexity

  • Test HTTP routes : Many examples of unit tests around Rocket routes probably exists to start writing tests quickly
  • Test Diesel methods : Will require to build a test environment for database
  • Test Juniper methods : Will require diesel methods to be mocked
  • Test Invoice methods : No mock exists for lnd wrapper, will require to build one.

@Asone Asone linked a pull request Oct 28, 2022 that will close this issue
@Asone
Copy link
Owner Author

Asone commented Oct 30, 2022

A few notes regarding unit & integration tests with rustlang and the different aspects of it.

  • Testing diesel methods : Digging in issues and docs i found some examples on how to bootstrap a database for testing database transactions.

However, the current drafted solution can only create and drop the test database for EACH test. This makes the solution quite slow and painful :

  • For each test we create a database
  • Then run the migrations
  • and then import the fixtures

This is an acceptable solution for small test suites, however this definitely can't be considered as a viable solution for long term development.

Unfortunately there is no way to perform operations prior a test suite with cargo for now. A hacky option could be the following one however : https://www.reddit.com/r/rust/comments/9wixkj/how_can_i_run_something_prior_to_all_cargo_tests/

@Asone
Copy link
Owner Author

Asone commented Oct 30, 2022

Unfortunately there is no way to perform operations prior a test suite with cargo for now. A hacky option could be the following one however : https://www.reddit.com/r/rust/comments/9wixkj/how_can_i_run_something_prior_to_all_cargo_tests/

It appears that unfortunately the statics don't get a Drop call, which means our temporary test database will never be destroyed.

In order to avoir previous data to remain we could switch to a static name of database and drop previous database on each start of tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant