Conversation
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
grype/matcher/dpkg/testdata/eol-debian8/debian/results/debian@8/cve-1999-1332.json
Outdated
Show resolved
Hide resolved
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
|
|
||
| func TestWithSharedFixture(t *testing.T) { | ||
| // use a fixture from internal/dbtest/testdata/shared/ | ||
| dbtest.SharedDBs(t, "all").Run(func(t *testing.T, db *dbtest.DB) { |
There was a problem hiding this comment.
Is there a benefit of having the Run callback instead of just something like:
db := dbtest.SharedDBs(t, "all").Build()
There was a problem hiding this comment.
I had the same question.
There was a problem hiding this comment.
There is a Build() method similar to what you have there, only it returns a slice of DBs. One thing baked into this is the ability to build/test with multiple schemas. This allows a single chokepoint where we can control which schemas as used by default for testing (or can be overridden by arguments). Having the Run() method allows us to not really change the test body but we can test multiple subjects -- it's only saving test writers from boilerplate of for each db build call t.Run with the DB schema name and test name....
| var conditions []string | ||
| var args []interface{} | ||
| for _, p := range patterns { | ||
| conditions = append(conditions, "id LIKE ?") |
There was a problem hiding this comment.
This looks like patterns will always query as part of the ID, not the contents? Is this for exploring the results or something else?
There was a problem hiding this comment.
not against adding that -- lets do that in a follow up PR
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This works towards replacing the existing test mocks that sit above the DB layer with a new test harness that supports:
The nice thing about the testdata directories used as input to the builds is that they are simply vunnel workspaces, so should still be 100% interoperable with the vunnel CLI if need be (pending a small vunnel fix inbound for windows compatibility).
This PR starts with replacing only the
dpkgmatcher tests and mocks with this new approach, however, these refactors will be rolled through the remaining matcher and integration tests.In terms of writing tests, the helpers keep the verbosity down a lot, while giving us a nice chokepoint for future refactors to take place (instead of full test rewrites). Here's an example of writing a test using the new helpers:
I feel that as we port more matcher tests over we will refine the helper functions considerably.
Note
Reviewers might want to take a look at the dbtest readme that is on the branch. This explains a lot of how this would be used.
TODO