internal/scan: add the ability to do show variant tests
Add a test for full trace mode.
Change-Id: I04ed9000c17d761bc97a079fbc3f678c7c661b88
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/495866
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
diff --git a/internal/scan/print_test.go b/internal/scan/print_test.go
index f8531cd..0b8722f 100644
--- a/internal/scan/print_test.go
+++ b/internal/scan/print_test.go
@@ -23,16 +23,27 @@
}
for _, input := range inputs {
name := strings.TrimSuffix(input, ".json")
- t.Run(name, func(t *testing.T) {
- rawJSON, _ := fs.ReadFile(testdata, input)
- wantText, _ := fs.ReadFile(testdata, name+".txt")
- got := &strings.Builder{}
- testRunHandler(t, rawJSON, scan.NewTextHandler(got))
- if diff := cmp.Diff(string(wantText), got.String()); diff != "" {
- t.Errorf("Readable mismatch (-want, +got):\n%s", diff)
- }
- got.Reset()
+ rawJSON, _ := fs.ReadFile(testdata, input)
+ textfiles, err := fs.Glob(testdata, name+"*.txt")
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, textfile := range textfiles {
+ textname := strings.TrimSuffix(textfile, ".txt")
+ t.Run(textname, func(t *testing.T) {
+ wantText, _ := fs.ReadFile(testdata, textfile)
+ got := &strings.Builder{}
+ handler := scan.NewTextHandler(got)
+ handler.Show = strings.Split(textname, "_")[1:]
+ testRunHandler(t, rawJSON, handler)
+ if diff := cmp.Diff(string(wantText), got.String()); diff != "" {
+ t.Errorf("Readable mismatch (-want, +got):\n%s", diff)
+ }
+ })
+ }
+ t.Run(name+"_json", func(t *testing.T) {
// this effectively tests that we can round trip the json
+ got := &strings.Builder{}
testRunHandler(t, rawJSON, govulncheck.NewJSONHandler(got))
if diff := cmp.Diff(strings.TrimSpace(string(rawJSON)), strings.TrimSpace(got.String())); diff != "" {
t.Errorf("JSON mismatch (-want, +got):\n%s", diff)
diff --git a/internal/scan/testdata/source_traces.txt b/internal/scan/testdata/source_traces.txt
new file mode 100644
index 0000000..7bb6ea1
--- /dev/null
+++ b/internal/scan/testdata/source_traces.txt
@@ -0,0 +1,31 @@
+govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback.
+
+Using govulncheck with
+vulnerability data from .
+Your code is affected by 1 vulnerability from 1 module.
+
+Vulnerability #1: GO-0000-0001
+ Third-party vulnerability
+ More info: https://pkg.go.dev/vuln/GO-0000-0001
+ Module: golang.org/vmod
+ Found in: golang.org/vmod@v0.0.1
+ Fixed in: golang.org/vmod@v0.1.3
+ Platforms: amd
+ Call stacks in your code:
+ #1: for function Vuln
+ main.main
+ vmod.Vuln
+
+=== Informational ===
+
+Found 1 vulnerability in packages that you import, but there are no call
+stacks leading to the use of this vulnerability. You may not need to
+take any action. See https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck
+for details.
+
+Vulnerability #1: GO-0000-0002
+ Stdlib vulnerability
+ More info: https://pkg.go.dev/vuln/GO-0000-0002
+ Standard library
+ Found in: net/http@go0.0.1
+ Fixed in: N/A
\ No newline at end of file