blob: b7495ef800e5f50a29a75a6fb8d606c08d9ec550 [file] [log] [blame]
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package frontend
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"golang.org/x/vulndb/osv"
)
func TestVulns(t *testing.T) {
e := osv.Entry{
Details: "bad",
Affected: []osv.Affected{{
Package: osv.Package{Name: "bad.com"},
Ranges: []osv.AffectsRange{{
Type: osv.TypeSemver,
Events: []osv.RangeEvent{{Introduced: "0"}, {Fixed: "1.2.3"}},
}},
}},
}
get := func(modulePath string) ([]*osv.Entry, error) {
switch modulePath {
case "good.com":
return nil, nil
case "bad.com":
return []*osv.Entry{&e}, nil
default:
return nil, fmt.Errorf("unknown module %q", modulePath)
}
}
got := Vulns("good.com", "v1.0.0", "good.com", get)
if got != nil {
t.Errorf("got %v, want nil", got)
}
got = Vulns("bad.com", "v1.0.0", "bad.com", get)
want := []Vuln{{
Details: "bad",
FixedVersion: "v1.2.3",
}}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("mismatch (-want, +got):\n%s", diff)
}
got = Vulns("bad.com", "v1.3.0", "bad.com", get)
if got != nil {
t.Errorf("got %v, want nil", got)
}
}