cve-bin-tool icon indicating copy to clipboard operation
cve-bin-tool copied to clipboard

test: PURL generation for language parsers

Open terriko opened this issue 11 months ago • 5 comments

We're currently in the process of adding PURL generation to our language parsers, but currently aren't using it for anything. Eventually we will as part of the planned gsoc project described in #3771 . But while we're waiting for bigger things, we could definitely stand to have some unit tests!

To avoid wasting time parsing files twice, we may want to add the generate_purl tests into the existingtest_language_package code, and do really basic unit-tests where we throw both valid and invalid vendor, package, version info into generate_purl

terriko avatar Mar 20 '24 17:03 terriko

I would like to work on this as I'm already working on PURL generation. Would be a good learning experience. @terriko @anthonyharrison

joydeep049 avatar Mar 20 '24 21:03 joydeep049

Also, the generate_purl test would be aimed at testing the generate_purl function of the language parsers, or the basic version written in __init__.py? Would we take normalization into consideration when we are testing the function? @terriko @anthonyharrison

joydeep049 avatar Mar 25 '24 17:03 joydeep049

Eagerly waiting for response @terriko :)

joydeep049 avatar Apr 05 '24 16:04 joydeep049

The goal is always for us to get as close as possible to 100% test coverage, so definitely both. If you've never worked with code coverage tools like codecov, they can help you figure out what parts your tests cover and which parts are not covered.

terriko avatar Apr 08 '24 19:04 terriko

Note that I don't actually expect us to get to 100% over all of cve-bin-tool because it is asymptotically hard, some of the code has to be tested against real data, and some of the tests would take a long time, so we aim to hover around 80% mostly as a balance of coverage vs practicality. But for something like this where you're literally just making a string and it'll execute in a few microseconds, there's no reason not to test Every Possible Code Path, unless of course upon testing it you realize that a lot of them could be collapsed into a single code path so you don't have to write as many tests. Refactoring is a valid way to improve code coverage too. 📈

terriko avatar Apr 08 '24 19:04 terriko

Tagging @inosmeet to take a look at these tests.

terriko avatar Aug 07 '24 15:08 terriko