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

test: restructure internal config cases and fixtures #1250

Merged
merged 7 commits into from
Sep 16, 2024

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented Sep 16, 2024

These tests are so old that they predate the repository itself and are not giving the best coverage of what they say they're testing so I've refactored them so that:

  • the fixtures now live in the package, since that's the only place they're used
    • (we could probably improve this a bit further, but I've not done anything extra for now as I don't think it's as important)
  • the tests are now laid out as tables and run in parallel
  • methods are being tested independently, and with improved comparators
  • include a few missing cases such as when the file is missing

@@ -0,0 +1 @@
LoadPath = "a/b/c"
Copy link
Collaborator Author

@G-Rath G-Rath Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: technically due to the tags on Config this will get read, but we always override it so isn't not possible for this to work (which is what we want)

however if someone were to refactor tryLoadConfig (like what I've done in #1248), then this could start getting loaded - hence, I've added this test to safeguard, with the intent to address the actual (currently theoretical) bug in a follow-up

@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.96%. Comparing base (12eefba) to head (83ecc28).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1250      +/-   ##
==========================================
- Coverage   67.96%   67.96%   -0.01%     
==========================================
  Files         174      174              
  Lines       16848    16848              
==========================================
- Hits        11451    11450       -1     
- Misses       4764     4765       +1     
  Partials      633      633              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

wantErr: true,
},
{
name: "target is file in directory with config",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I miss something - should this be directory without config? there isn't osv-scanner.toml in innerFolder

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 I had it written without that the first time, but then got confused with the tryLoadConfig tests and added it - thanks for catching this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now there are two target is file in directory tests - any difference between two tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there were always two tests like this - I've just ported them across. I think technically they're different because one has a config file in them and the other doesn't, but the original test didn't make it clear if that was a part of the test or just a coincidence.

I wasn't that fussed because these tests are very fast to run so I didn't have a huge issue with retaining a potentially duplicated test here (given it's not a total duplicate from a file system POV even if that's not super revertant to the implementation)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to state the difference in the test names - maybe @another-rex knows why we have these tests.

Copy link
Collaborator Author

@G-Rath G-Rath Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fow now I've just adjusted the names to be unique, as I'd like to get this landed ASAP so I can rebase #1248 and #1249 - I'm happy to deal with improving these tests further in a follow-up PR :)

@G-Rath G-Rath requested a review from cuixq September 16, 2024 03:40
@cuixq cuixq merged commit 60609a4 into google:main Sep 16, 2024
13 checks passed
@cuixq cuixq deleted the config/improve-tests branch September 16, 2024 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants