Skip to content

Commit

Permalink
Set NotFixedYet for Ubuntu Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
kotakanbe committed Aug 17, 2017
1 parent 6129ac7 commit de65073
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
9 changes: 8 additions & 1 deletion oval/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
49 changes: 49 additions & 0 deletions oval/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package oval

import (
"reflect"
"sort"
"testing"

"github.com/future-architect/vuls/models"
ovalmodels "github.com/kotakanbe/goval-dictionary/models"
)

Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit de65073

Please sign in to comment.