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

Use fixtures outside ./fixtures/ #2539

Closed
ripa1995 opened this issue Jun 12, 2023 · 4 comments · Fixed by #2545
Closed

Use fixtures outside ./fixtures/ #2539

ripa1995 opened this issue Jun 12, 2023 · 4 comments · Fixed by #2545
Labels
enhancement New feature or request

Comments

@ripa1995
Copy link
Contributor

ripa1995 commented Jun 12, 2023

Is your feature request related to a problem? Please describe.
In big projects, with a lot of integration tests, it happens that the same fixture needs to be used in multiple tests which are structured in sub folders, leading to duplicated ./fixtures/ files.

Describe the solution you'd like
It would be nice to have the possibility to specify a path to the fixture script (e.g., ../fixtures/users), other than the name of the fixture script (as it is now), leading to something like: #[sqlx::test(fixtures("../other_dir/fixtures/users", "posts"))].

Describe alternatives you've considered
An alternative could be to accept also fixtures_with_path, e.g. #[sqlx::test(fixtures_with_path("../other_dir/fixtures/users"), fixtures("posts"))].

Additional context
None.

I would like to help on that one, if needed ofc.

@ripa1995 ripa1995 added the enhancement New feature or request label Jun 12, 2023
@abonander
Copy link
Collaborator

That sounds like an improvement, yeah. The code for the #[test] attribute is here: https://github.com/launchbadge/sqlx/blob/main/sqlx-macros-core/src/test_attr.rs

I would name it fixtures_path though.

@ripa1995
Copy link
Contributor Author

That sounds like an improvement, yeah. The code for the #[test] attribute is here: https://github.com/launchbadge/sqlx/blob/main/sqlx-macros-core/src/test_attr.rs

I would name it fixtures_path though.

Thanks.

I will start to work on that tomorrow. It should not take too much time.

@ripa1995
Copy link
Contributor Author

ripa1995 commented Jun 13, 2023

@abonander, I've started to do it https://github.com/runtime-machines/sqlx/blob/2539-expand-fixtures/sqlx-macros-core/src/test_attr.rs .

I think it is better to accept only one between fixtures and fixtures_path, like for migrations and migrator. This mostly to avoid issues with the execution order. I have also modified one test such that it uses fixtures from an outer directory.

Another possibility is:

  • accept only fixtures.
  • fixtures field in Args as Vec<LitStr>.
  • in parse_args check if fixture is a path or not, and format it directly with format!("fixtures/{}.sql", fixture.value()) or format!("{}.sql", fixture.value()).
  • in expand_advanced treat everything as before, without the formatting of the fixtures values.

@abonander
Copy link
Collaborator

#2545 (comment)

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.

2 participants