github.com/quay/claircore@v1.5.28/pkg/ovalutil/rpm_test.go (about) 1 package ovalutil 2 3 import ( 4 "testing" 5 6 "github.com/quay/goval-parser/oval" 7 ) 8 9 type definitionTypeTestCase struct { 10 name string 11 want DefinitionType 12 def oval.Definition 13 err bool 14 } 15 16 func TestGetDefinitionType(t *testing.T) { 17 testCases := []definitionTypeTestCase{ 18 { 19 def: oval.Definition{ID: "oval:com.redhat.cve:def:20162166"}, 20 want: CVEDefinition, 21 err: false, 22 name: "CVE", 23 }, 24 { 25 def: oval.Definition{ID: "oval:com.redhat.unaffected:def:202014340"}, 26 want: UnaffectedDefinition, 27 err: false, 28 name: "unaffected", 29 }, 30 { 31 def: oval.Definition{ID: "oval:com.redhat.rhsa:def:20190966"}, 32 want: RHSADefinition, 33 err: false, 34 name: "RHSA", 35 }, 36 { 37 def: oval.Definition{ID: "oval:com.redhat.rhba:def:20193384"}, 38 want: RHBADefinition, 39 err: false, 40 name: "RHBA", 41 }, 42 { 43 def: oval.Definition{ID: "oval:com.redhat.rhea:def:20193845"}, 44 want: RHEADefinition, 45 err: false, 46 name: "RHEA", 47 }, 48 { 49 def: oval.Definition{ID: "oval:com.redhat.rhea::20193845"}, 50 want: "", 51 err: true, 52 name: "malformed definition", 53 }, 54 { 55 def: oval.Definition{ID: ""}, 56 want: "", 57 err: true, 58 name: "empty ID", 59 }, 60 } 61 62 for _, tc := range testCases { 63 got, err := GetDefinitionType(tc.def) 64 if !tc.err && err != nil { 65 t.Errorf("%q returned error while it shouldn't", tc.name) 66 } 67 if tc.err && err == nil { 68 t.Errorf("%q didn't return error while it should", tc.name) 69 } 70 if tc.want != got { 71 t.Errorf("%q failed: want %q, got %q", tc.name, tc.want, got) 72 } 73 } 74 }