mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
🌱 Increase test coverage for finding outcomes (#3142)
* Increase test coverage for finding outcomes - Add tests for Outcome UnmarshalYAML function in `finding/finding_test.go` Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> * Updates based on Codereview - 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 <172697+naveensrinivasan@users.noreply.github.com> --------- Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
This commit is contained in:
parent
2734a0c841
commit
ab1c515c30
@ -21,6 +21,7 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/ossf/scorecard/v4/finding/probe"
|
||||
)
|
||||
@ -198,3 +199,95 @@ func Test_FromBytes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutcome_UnmarshalYAML(t *testing.T) {
|
||||
t.Parallel()
|
||||
type args struct {
|
||||
n *yaml.Node
|
||||
}
|
||||
tests := []struct { //nolint:govet
|
||||
name string
|
||||
wantOutcome Outcome
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "positive outcome",
|
||||
wantOutcome: OutcomePositive,
|
||||
args: args{
|
||||
n: &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "Positive",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "negative outcome",
|
||||
wantOutcome: OutcomeNegative,
|
||||
args: args{
|
||||
n: &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "Negative",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "NotAvailable outcome",
|
||||
wantOutcome: OutcomeNotAvailable,
|
||||
args: args{
|
||||
n: &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "NotAvailable",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "NotSupported outcome",
|
||||
wantOutcome: OutcomeNotSupported,
|
||||
args: args{
|
||||
n: &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "NotSupported",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Unknown error",
|
||||
wantOutcome: OutcomeError,
|
||||
args: args{
|
||||
n: &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "Error",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Unknown outcome",
|
||||
args: args{
|
||||
n: &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "Unknown",
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user