Skip to content

Commit caabbd6

Browse files
committed
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 <[email protected]> Reviewed-by: Tatiana Bradley <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent a9d9eed commit caabbd6

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

internal/vuln/client.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (c *Client) byIDsFilter(ctx context.Context, ids []string, filter func(*osv
311311
}
312312
var filtered []*osv.Entry
313313
for _, entry := range entries {
314-
if filter(entry) {
314+
if entry != nil && filter(entry) {
315315
filtered = append(filtered, entry)
316316
}
317317
}
@@ -321,6 +321,9 @@ func (c *Client) byIDsFilter(ctx context.Context, ids []string, filter func(*osv
321321
return filtered, nil
322322
}
323323

324+
// byIDs returns OSV entries for given ids.
325+
// The i-th entry in the returned value corresponds to the i-th ID
326+
// and can be nil if there is no entry with the given ID.
324327
func (c *Client) byIDs(ctx context.Context, ids []string) (_ []*osv.Entry, err error) {
325328
entries := make([]*osv.Entry, len(ids))
326329
g, gctx := errgroup.WithContext(ctx)

internal/vuln/client_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"encoding/json"
1111
"fmt"
12+
"path/filepath"
1213
"reflect"
1314
"strings"
1415
"testing"
@@ -19,8 +20,8 @@ import (
1920
"golang.org/x/tools/txtar"
2021
)
2122

22-
const (
23-
dbTxtar = "testdata/db.txtar"
23+
var (
24+
dbTxtar = filepath.Join("testdata", "db.txtar")
2425
)
2526

2627
var (
@@ -41,7 +42,7 @@ var (
4142
Ecosystem: "Go",
4243
},
4344
Ranges: []osv.Range{
44-
osv.Range{
45+
{
4546
Type: "SEMVER",
4647
Events: []osv.RangeEvent{
4748
{Introduced: "0"}, {Fixed: "1.1.0"},
@@ -70,7 +71,7 @@ var (
7071
Ecosystem: "Go",
7172
},
7273
Ranges: []osv.Range{
73-
osv.Range{
74+
{
7475
Type: "SEMVER", Events: []osv.RangeEvent{{Introduced: "0"},
7576
{Fixed: "1.2.0"},
7677
}}},

0 commit comments

Comments
 (0)