Skip to content

Commit

Permalink
internal/report: remove use of CutPrefix and add test for labels
Browse files Browse the repository at this point in the history
Using new(er) function CutPrefix caused deploy to fail because it expected
to run using older version of Go.

Change-Id: I335ca27870caf0b9d6a57bf98fb3e2be1e205743
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/540855
Auto-Submit: Tatiana Bradley <tatianabradley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
  • Loading branch information
tatianab authored and gopherbot committed Nov 8, 2023
1 parent b4558ea commit bb54b20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func (er ExcludedReason) ToLabel() string {
}

func FromLabel(label string) (ExcludedReason, bool) {
er, ok := strings.CutPrefix(label, excludedLabelPrefix)
pre, er, ok := strings.Cut(label, excludedLabelPrefix)
if pre != "" {
return "", false
}
return ExcludedReason(er), ok
}

Expand Down
13 changes: 13 additions & 0 deletions internal/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ func TestYAMLFilename(t *testing.T) {
}
}

func TestToFromLabel(t *testing.T) {
str := "EFFECTIVELY_PRIVATE"
label := "excluded: EFFECTIVELY_PRIVATE"
er := ExcludedReason(str)
if got, want := er.ToLabel(), label; got != want {
t.Errorf("(%s).ToLabel = %s, want %s", er, got, want)
}
got, ok := FromLabel(label)
if want := er; !ok || got != want {
t.Errorf("FromLabel(%s) = (%s, %t), want (%s, true)", label, got, ok, want)
}
}

func TestParseFilepath(t *testing.T) {
filepath := "data/reports/GO-1999-0023.yaml"
wantFolder := "data/reports"
Expand Down

0 comments on commit bb54b20

Please sign in to comment.