Skip to content

Commit

Permalink
Updates based on Codereview
Browse files Browse the repository at this point in the history
- Update `Outcome` variable in `finding/finding_test.go`
- Add `t.Parallel()` for test parallelization
- Add comparison using `cmp.Diff` to test for mismatches
- Update test cases for various outcomes

Signed-off-by: naveensrinivasan <[email protected]>
  • Loading branch information
naveensrinivasan committed Jun 8, 2023
1 parent db8ed5e commit 5e64e17
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions finding/finding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ func TestOutcome_UnmarshalYAML(t *testing.T) {
n *yaml.Node
}
tests := []struct { //nolint:govet
name string
o Outcome
args args
wantErr bool
name string
wantOutcome Outcome
args args
wantErr bool
}{
{
name: "positive outcome",
o: OutcomePositive,
name: "positive outcome",
wantOutcome: OutcomePositive,
args: args{
n: &yaml.Node{
Kind: yaml.ScalarNode,
Expand All @@ -222,8 +222,8 @@ func TestOutcome_UnmarshalYAML(t *testing.T) {
wantErr: false,
},
{
name: "negative outcome",
o: OutcomeNegative,
name: "negative outcome",
wantOutcome: OutcomeNegative,
args: args{
n: &yaml.Node{
Kind: yaml.ScalarNode,
Expand All @@ -233,8 +233,8 @@ func TestOutcome_UnmarshalYAML(t *testing.T) {
wantErr: false,
},
{
name: "NotAvailable outcome",
o: OutcomeNotAvailable,
name: "NotAvailable outcome",
wantOutcome: OutcomeNotAvailable,
args: args{
n: &yaml.Node{
Kind: yaml.ScalarNode,
Expand All @@ -244,8 +244,8 @@ func TestOutcome_UnmarshalYAML(t *testing.T) {
wantErr: false,
},
{
name: "NotSupported outcome",
o: OutcomeNotSupported,
name: "NotSupported outcome",
wantOutcome: OutcomeNotSupported,
args: args{
n: &yaml.Node{
Kind: yaml.ScalarNode,
Expand All @@ -255,8 +255,8 @@ func TestOutcome_UnmarshalYAML(t *testing.T) {
wantErr: false,
},
{
name: "Unknown error",
o: OutcomeError,
name: "Unknown error",
wantOutcome: OutcomeError,
args: args{
n: &yaml.Node{
Kind: yaml.ScalarNode,
Expand All @@ -277,9 +277,15 @@ func TestOutcome_UnmarshalYAML(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
if err := tt.o.UnmarshalYAML(tt.args.n); (err != nil) != tt.wantErr {
t.Errorf("UnmarshalYAML() error = %v, wantErr %v", err, tt.wantErr)
t.Parallel()
var v Outcome
if err := v.UnmarshalYAML(tt.args.n); (err != nil) != tt.wantErr {
t.Errorf("Outcome.UnmarshalYAML() error = %v, wantErr %v", err, tt.wantErr)
}
if diff := cmp.Diff(tt.wantOutcome, v); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down

0 comments on commit 5e64e17

Please sign in to comment.