diff options
| author | Hana (Hyang-Ah) Kim <hyangah@gmail.com> | 2023-06-28 21:34:46 -0400 |
|---|---|---|
| committer | Hyang-Ah Hana Kim <hyangah@gmail.com> | 2023-06-29 16:27:57 +0000 |
| commit | caabbd68f136081567e8e160bdcd982c90abcdff (patch) | |
| tree | a25ca4de0bcad7605e77df727d7649406cc64efb /internal/vuln | |
| parent | a9d9eedc7cc6e2b6cbb4cdbb34a61060cd90dbeb (diff) | |
| download | go-x-pkgsite-caabbd68f136081567e8e160bdcd982c90abcdff.tar.xz | |
internal/vuln: fix tests on windows
Specify test vuln db data in a platform-independent way.
This CL fixes a path that led to runtime panic shown in
https://build.golang.org/log/eecc6c289819b502bc5449a6af26610092d24a07
And adds comments to clarify Client.byIDs - its return
value can contain nil values if there are no matching
osv entries in the DB.
Updates golang/go#59347
Change-Id: I10a6be8bb1e0bef4f8be204c47591bf20a3480f3
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/506977
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'internal/vuln')
| -rw-r--r-- | internal/vuln/client.go | 5 | ||||
| -rw-r--r-- | internal/vuln/client_test.go | 9 |
2 files changed, 9 insertions, 5 deletions
diff --git a/internal/vuln/client.go b/internal/vuln/client.go index e03e7145..07c64ea8 100644 --- a/internal/vuln/client.go +++ b/internal/vuln/client.go @@ -311,7 +311,7 @@ func (c *Client) byIDsFilter(ctx context.Context, ids []string, filter func(*osv } var filtered []*osv.Entry for _, entry := range entries { - if filter(entry) { + if entry != nil && filter(entry) { filtered = append(filtered, entry) } } @@ -321,6 +321,9 @@ func (c *Client) byIDsFilter(ctx context.Context, ids []string, filter func(*osv return filtered, nil } +// byIDs returns OSV entries for given ids. +// The i-th entry in the returned value corresponds to the i-th ID +// and can be nil if there is no entry with the given ID. func (c *Client) byIDs(ctx context.Context, ids []string) (_ []*osv.Entry, err error) { entries := make([]*osv.Entry, len(ids)) g, gctx := errgroup.WithContext(ctx) diff --git a/internal/vuln/client_test.go b/internal/vuln/client_test.go index 24b29843..8350fec4 100644 --- a/internal/vuln/client_test.go +++ b/internal/vuln/client_test.go @@ -9,6 +9,7 @@ import ( "context" "encoding/json" "fmt" + "path/filepath" "reflect" "strings" "testing" @@ -19,8 +20,8 @@ import ( "golang.org/x/tools/txtar" ) -const ( - dbTxtar = "testdata/db.txtar" +var ( + dbTxtar = filepath.Join("testdata", "db.txtar") ) var ( @@ -41,7 +42,7 @@ var ( Ecosystem: "Go", }, Ranges: []osv.Range{ - osv.Range{ + { Type: "SEMVER", Events: []osv.RangeEvent{ {Introduced: "0"}, {Fixed: "1.1.0"}, @@ -70,7 +71,7 @@ var ( Ecosystem: "Go", }, Ranges: []osv.Range{ - osv.Range{ + { Type: "SEMVER", Events: []osv.RangeEvent{{Introduced: "0"}, {Fixed: "1.2.0"}, }}}, |
