File: result_test.go

package info (click to toggle)
golang-golang-x-vuln 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,400 kB
  • sloc: sh: 161; asm: 40; makefile: 7
file content (75 lines) | stat: -rw-r--r-- 1,997 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2022 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 scan

import (
	"strings"
	"testing"

	"golang.org/x/vuln/internal/govulncheck"
)

func TestFrame(t *testing.T) {
	for _, test := range []struct {
		name     string
		frame    *govulncheck.Frame
		short    bool
		wantFunc string
		wantPos  string
	}{
		{
			name: "position and function",
			frame: &govulncheck.Frame{
				Package:  "golang.org/x/vuln/internal/vulncheck",
				Function: "Foo",
				Position: &govulncheck.Position{Filename: "some/path/file.go", Line: 12},
			},
			wantFunc: "golang.org/x/vuln/internal/vulncheck.Foo",
			wantPos:  "some/path/file.go:12",
		},
		{
			name: "receiver",
			frame: &govulncheck.Frame{
				Package:  "golang.org/x/vuln/internal/vulncheck",
				Receiver: "Bar",
				Function: "Foo",
			},
			wantFunc: "golang.org/x/vuln/internal/vulncheck.Bar.Foo",
		},
		{
			name:     "function and receiver",
			frame:    &govulncheck.Frame{Receiver: "*ServeMux", Function: "Handle"},
			wantFunc: "ServeMux.Handle",
		},
		{
			name:     "package and function",
			frame:    &govulncheck.Frame{Package: "net/http", Function: "Get"},
			wantFunc: "net/http.Get",
		},
		{
			name:     "package, function and receiver",
			frame:    &govulncheck.Frame{Package: "net/http", Receiver: "*ServeMux", Function: "Handle"},
			wantFunc: "net/http.ServeMux.Handle",
		},
		{
			name:     "short",
			frame:    &govulncheck.Frame{Package: "net/http", Function: "Get"},
			short:    true,
			wantFunc: "http.Get",
		},
	} {
		t.Run(test.name, func(t *testing.T) {
			buf := &strings.Builder{}
			addSymbolName(buf, test.frame, test.short)
			got := buf.String()
			if got != test.wantFunc {
				t.Errorf("want %v func name; got %v", test.wantFunc, got)
			}
			if got := posToString(test.frame.Position); got != test.wantPos {
				t.Errorf("want %v call position; got %v", test.wantPos, got)
			}
		})
	}
}