From de65073f614692751e0c2003dde62087d84b1dc0 Mon Sep 17 00:00:00 2001 From: kota kanbe Date: Thu, 17 Aug 2017 15:32:22 +0900 Subject: [PATCH] Set NotFixedYet for Ubuntu Scan --- oval/util.go | 9 ++++++++- oval/util_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/oval/util.go b/oval/util.go index bbbf671d..ca2b553a 100644 --- a/oval/util.go +++ b/oval/util.go @@ -45,8 +45,15 @@ type defPacks struct { } func (e defPacks) toPackStatuses() (ps models.PackageStatuses) { + packNotFixedYet := map[string]bool{} + for _, p := range e.def.AffectedPacks { + packNotFixedYet[p.Name] = p.NotFixedYet + } for k := range e.actuallyAffectedPackNames { - ps = append(ps, models.PackageStatus{Name: k}) + ps = append(ps, models.PackageStatus{ + Name: k, + NotFixedYet: packNotFixedYet[k], + }) } return } diff --git a/oval/util_test.go b/oval/util_test.go index 48ef395b..6c8879ef 100644 --- a/oval/util_test.go +++ b/oval/util_test.go @@ -2,8 +2,10 @@ package oval import ( "reflect" + "sort" "testing" + "github.com/future-architect/vuls/models" ovalmodels "github.com/kotakanbe/goval-dictionary/models" ) @@ -96,3 +98,50 @@ func TestUpsert(t *testing.T) { } } } + +func TestDefpacksToPackStatuses(t *testing.T) { + var tests = []struct { + in defPacks + out models.PackageStatuses + }{ + { + in: defPacks{ + def: ovalmodels.Definition{ + AffectedPacks: []ovalmodels.Package{ + { + Name: "a", + NotFixedYet: true, + }, + { + Name: "b", + NotFixedYet: false, + }, + }, + }, + actuallyAffectedPackNames: map[string]bool{ + "a": true, + "b": false, + }, + }, + out: models.PackageStatuses{ + { + Name: "a", + NotFixedYet: true, + }, + { + Name: "b", + NotFixedYet: false, + }, + }, + }, + } + for i, tt := range tests { + actual := tt.in.toPackStatuses() + sort.Slice(actual, func(i, j int) bool { + return actual[i].Name < actual[j].Name + }) + if !reflect.DeepEqual(actual, tt.out) { + t.Errorf("[%d]\nexpected: %v\n actual: %v\n", i, tt.out, actual) + } + } +}