From 1bbbc4911ea1e4ee0c58a69fcc0b8ebba9d752fd Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Tue, 2 Nov 2021 09:36:24 -0400 Subject: [PATCH] update lint_test.go TestLintReports is updated to use golang.org/x/vuln/vlint. The internal/ directory will be deleted in the next CL. Change-Id: Ifa4f5b3772963e2ae85f972fe61776429bace107 Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/360716 Trust: Julie Qiu Run-TryBot: Julie Qiu TryBot-Result: Go Bot Reviewed-by: Jonathan Amsterdam --- go.mod | 4 ++-- go.sum | 2 ++ lint_test.go | 22 ++++++++-------------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index c6668ff0..dcdc7483 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/go-git/gcfg v1.5.0 // indirect github.com/go-git/go-billy/v5 v5.3.1 // indirect github.com/go-git/go-git/v5 v5.4.2 - github.com/google/go-cmp v0.5.6 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect @@ -21,7 +20,8 @@ require ( golang.org/x/mod v0.4.1 golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect + golang.org/x/vuln v0.0.0-20211109030331-63d5d8171d01 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index ea8f4a0e..4311706c 100644 --- a/go.sum +++ b/go.sum @@ -100,6 +100,8 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/vuln v0.0.0-20211109030331-63d5d8171d01 h1:aohfMrFbzRmVFllsufGifzVZzGJHuCrdmXA88J2FX9Q= +golang.org/x/vuln v0.0.0-20211109030331-63d5d8171d01/go.mod h1:vGjwvr4zd0JNGaeuScTP00A/lDhN8Ao3GFprqIUiIcM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/lint_test.go b/lint_test.go index 4a4d217e..0b2f0b28 100644 --- a/lint_test.go +++ b/lint_test.go @@ -11,10 +11,11 @@ import ( "strings" "testing" - "golang.org/x/vulndb/internal/report" - "gopkg.in/yaml.v2" + "golang.org/x/vuln/vlint" ) +const reportsDir = "reports" + func TestLintReports(t *testing.T) { if runtime.GOOS == "js" { t.Skipf("wasm builder does not have network access") @@ -22,28 +23,21 @@ func TestLintReports(t *testing.T) { if runtime.GOOS == "android" { t.Skipf("android builder does not have access to reports/") } - - reports, err := ioutil.ReadDir("reports") + reports, err := ioutil.ReadDir(reportsDir) if err != nil { t.Fatalf("unable to read reports/: %s", err) } - for _, rf := range reports { if rf.IsDir() { continue } t.Run(rf.Name(), func(t *testing.T) { - b, err := ioutil.ReadFile(filepath.Join("reports", rf.Name())) + fn := filepath.Join(reportsDir, rf.Name()) + lints, err := vlint.LintReport(fn) if err != nil { - t.Fatalf("unable to read %q: %s", rf.Name(), err) + t.Fatalf("vulnlint.LintReport(%q): %s", fn, err) } - - var r report.Report - if err := yaml.UnmarshalStrict(b, &r); err != nil { - t.Fatalf("unable to parse report %q: %s", rf.Name(), err) - } - - if lints := r.Lint(); len(lints) > 0 { + if len(lints) > 0 { t.Errorf(strings.Join(lints, "\n")) } })