Skip to content

Commit

Permalink
fix bug 418 typo while checking jira issue count
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole authored and andream16 committed Oct 14, 2024
1 parent 7601dec commit 904719e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 72 deletions.
12 changes: 4 additions & 8 deletions pkg/templating/template_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ func EnrichedIssueWithSeverityText(severity string) enrichedIssueOption {
// EnrichedIssueWithCount allows customising the Enriched Issue's Count.
func EnrichedIssueWithCount(count uint) enrichedIssueOption {
return func(ei *enrichedIssue) error {
if count <= 0 {
return errors.Errorf("invalid count %d", count)
}
ei.Count = count
return nil
}
Expand All @@ -109,22 +106,21 @@ func EnrichedIssueWithScanID(scanID string) enrichedIssueOption {
// EnrichedIssueWithScanStartTime allows customising the Enriched Issue's Scan start time.
func EnrichedIssueWithScanStartTime(startTime time.Time) enrichedIssueOption {
return func(ei *enrichedIssue) error {
st := startTime.Format(time.RFC3339)
if startTime.IsZero() {
return errors.Errorf("invalid startTime zero: %s", st)
return errors.Errorf("invalid startTime zero: %s", startTime.String())
}
ei.ScanStartTime = st
ei.ScanStartTime = startTime.Format(time.RFC3339)
return nil
}
}

// EnrichedIssueWithFirstFound allows customising the Enriched Issue's Scan first found time.
func EnrichedIssueWithFirstFound(firstFound time.Time) enrichedIssueOption {
return func(ei *enrichedIssue) error {
ff := firstFound.Format(time.RFC3339)
if firstFound.IsZero() {
return errors.Errorf("invalid firstFound zero %s", ff)
return errors.Errorf("invalid firstFound zero %s", firstFound.String())
}
ff := firstFound.Format(time.RFC3339)
ei.FirstFound = ff
return nil
}
Expand Down
98 changes: 34 additions & 64 deletions pkg/templating/template_description_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"

Expand Down Expand Up @@ -140,133 +139,104 @@ func Test_TemplateStringEnriched(t *testing.T) {
}

func TestDescriptionOptions(t *testing.T) {
type args struct {
option enrichedIssueOption
}

acceptableTime, err := time.Parse(time.RFC3339, "2024-10-10T20:06:33Z")
require.NoError(t, err)

for _, tt := range []struct {
name string
args args
option enrichedIssueOption
wantErr bool
expectedEnrichedIssue *enrichedIssue
}{
{
name: "zero startTime returns err",
args: args{
option: EnrichedIssueWithScanStartTime(time.Time{}),
},
name: "zero startTime returns err",
option: EnrichedIssueWithScanStartTime(time.Time{}),
wantErr: true,
},
{
name: "non zero startTime returns no err",
args: args{
option: EnrichedIssueWithScanStartTime(acceptableTime),
},
name: "non zero startTime returns no err",
option: EnrichedIssueWithScanStartTime(acceptableTime),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
ScanStartTime: acceptableTime.Format(time.RFC3339),
},
},
{
name: "zero firstFound returns err",
args: args{
option: EnrichedIssueWithFirstFound(time.Time{}),
},
name: "zero firstFound returns err",
option: EnrichedIssueWithFirstFound(time.Time{}),
wantErr: true,
},
{
name: "non zero firstFound returns no err",
args: args{
option: EnrichedIssueWithFirstFound(acceptableTime),
},
name: "non zero firstFound returns no err",
option: EnrichedIssueWithFirstFound(acceptableTime),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
FirstFound: acceptableTime.Format(time.RFC3339),
},
},
{
name: "empty tool name returns err",
args: args{
option: EnrichedIssueWithToolName(""),
},
name: "empty tool name returns err",
option: EnrichedIssueWithToolName(""),
wantErr: true,
},
{
name: "valid tool name returns no err",
args: args{
option: EnrichedIssueWithToolName("some-tool"),
},
name: "valid tool name returns no err",
option: EnrichedIssueWithToolName("some-tool"),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
ToolName: "some-tool",
},
},
{
name: "empty confidence text returns err",
args: args{
option: EnrichedIssueWithConfidenceText(""),
},
name: "empty confidence text returns err",
option: EnrichedIssueWithConfidenceText(""),
wantErr: true,
},
{
name: "valid confidence text returns no err",
args: args{
option: EnrichedIssueWithConfidenceText("conf-text-1"),
},
name: "valid confidence text returns no err",
option: EnrichedIssueWithConfidenceText("conf-text-1"),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
ConfidenceText: "conf-text-1",
},
},
{
name: "empty severity text returns err",
args: args{
option: EnrichedIssueWithSeverityText(""),
},
name: "empty severity text returns err",
option: EnrichedIssueWithSeverityText(""),
wantErr: true,
},
{
name: "valid severity text returns no err",
args: args{
option: EnrichedIssueWithSeverityText("severity-text-1"),
},
name: "valid severity text returns no err",
option: EnrichedIssueWithSeverityText("severity-text-1"),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
SeverityText: "severity-text-1",
},
},
{
name: "0 count returns err",
args: args{
option: EnrichedIssueWithCount(0),
name: "0 count returns no err",
option: EnrichedIssueWithCount(0),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
Count: 0,
},
wantErr: true,
},
{
name: "positive count text returns no err",
args: args{
option: EnrichedIssueWithCount(420),
},
name: "positive count returns no err",
option: EnrichedIssueWithCount(420),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
Count: 420,
},
},
{
name: "empty scan ID returns err",
args: args{
option: EnrichedIssueWithScanID(""),
},
name: "empty scan ID returns err",
option: EnrichedIssueWithScanID(""),
wantErr: true,
},
{
name: "valid scan id returns no err",
args: args{
option: EnrichedIssueWithScanID("scan-1"),
},
name: "valid scan id returns no err",
option: EnrichedIssueWithScanID("scan-1"),
wantErr: false,
expectedEnrichedIssue: &enrichedIssue{
ScanID: "scan-1",
Expand All @@ -275,11 +245,11 @@ func TestDescriptionOptions(t *testing.T) {
} {
t.Run(tt.name, func(t *testing.T) {
var ei enrichedIssue
if err := tt.args.option(&ei); tt.wantErr {
if err := tt.option(&ei); tt.wantErr {
require.Error(t, err)
return
}
assert.Equal(t, tt.expectedEnrichedIssue, &ei)
require.Equal(t, tt.expectedEnrichedIssue, &ei)
})
}
}

0 comments on commit 904719e

Please sign in to comment.