Skip to content

test: add unit tests for rust resolver#8

Open
Jaydeep869 wants to merge 4 commits intoSBOMit:masterfrom
Jaydeep869:fix-rust-resolver-tests
Open

test: add unit tests for rust resolver#8
Jaydeep869 wants to merge 4 commits intoSBOMit:masterfrom
Jaydeep869:fix-rust-resolver-tests

Conversation

@Jaydeep869
Copy link
Copy Markdown
Contributor

@Jaydeep869 Jaydeep869 commented Apr 1, 2026

Description:
This PR introduces comprehensive unit tests for the Rust resolver, completing the test coverage for all ecosystem resolvers.

Changes:

  • Created pkg/resolver/rust_test.go with 13 robust test cases.
  • Validated Cargo registry path parsing (registry/src and registry/cache).
  • Validated index.crates.io indexing paths.
  • Verified correct handling of ignored compilation files (/target/) and internal project source paths.
  • Validated correct PURL format generation (pkg:cargo/<name>@<version>).
  • Verified package file filtering Matches checks via CreateFileFilters.

Motivation:
Addresses the lack of unit tests for the Rust resolver, catching errors with Cargo path parsing and maintaining parity with tests added in PRs #2 and #3.

Fixes: #6

Checklist

  • Test coverage for main Rust resolver functions (Resolve and CreateFileFilters)
  • Edge cases are covered
  • All tests pass (go test ./pkg/resolver -v -run Rust)
screenshot

Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@Elvand-Lie
Copy link
Copy Markdown

Hey @Jaydeep869, quick question on the compiled artifacts test. The path you used is under /target/debug/deps/ doesn't that get dropped by isRustIgnoredPath before isCompiledRustArtifact or isOwnedByKnownCrate are even reached? If so the test passes but isOwnedByKnownCrate is never actually called. It's worth checking whether that function is even reachable for compiled artifacts given that isRustIgnoredPath drops everything under /target/ first.

Also was a direct test for NormalizeRustCrateName intentionally left out? You added TestDecodeGoModulePath in #3 so figured it might have just been missed.

And on #12 since you and @Sandipmandal25 are covering the same ground, would it make sense to consolidate into one PR? Happy to leave that to whoever the maintainers prefer but just seems cleaner than two open PRs for the same thing.

…RustCrateName

Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@Jaydeep869 Jaydeep869 force-pushed the fix-rust-resolver-tests branch from 08356d2 to 0b5bec3 Compare April 4, 2026 15:36
@Jaydeep869
Copy link
Copy Markdown
Contributor Author

Hey @Elvand-Lie , thank you for the feedback and for taking the time to review this.

You were completely right about the compiled artifacts test. The path was indeed getting caught by the ignored paths filter right away, so it never actually reached or validated the compiled artifact functions. I have updated the test to use a direct registry path so those functions are properly tested and verified.
I also totally missed adding the direct unit test for the crate name normalization function. I appreciate you noticing that oversight. I just added a robust test block for it and pushed the update to this branch.
Thanks again for the help!

@Sandipmandal25
Copy link
Copy Markdown

Hey @Jaydeep869, quick question on the compiled artifacts test. The path you used is under /target/debug/deps/ doesn't that get dropped by isRustIgnoredPath before isCompiledRustArtifact or isOwnedByKnownCrate are even reached? If so the test passes but isOwnedByKnownCrate is never actually called. It's worth checking whether that function is even reachable for compiled artifacts given that isRustIgnoredPath drops everything under /target/ first.

Also was a direct test for NormalizeRustCrateName intentionally left out? You added TestDecodeGoModulePath in #3 so figured it might have just been missed.

And on #12 since you and @Sandipmandal25 are covering the same ground, would it make sense to consolidate into one PR? Happy to leave that to whoever the maintainers prefer but just seems cleaner than two open PRs for the same thing.

#12 closed in the favour of this pr

@stupendoussuperpowers
Copy link
Copy Markdown
Contributor

Can you run gofmt on this? Would make it easier to read.

Signed-off-by: jaydeep869 <jaydeeppokhariya2106@gmail.com>
@Jaydeep869 Jaydeep869 force-pushed the fix-rust-resolver-tests branch from f7047f1 to 81bcda8 Compare April 8, 2026 16:04
@Jaydeep869
Copy link
Copy Markdown
Contributor Author

Can you run gofmt on this? Would make it easier to read.

Sure @stupendoussuperpowers, I’ve run gofmt on it. Does this look okay now?

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.

4 participants