From 12c2d3cbc67b42d2d3c1c566f9ca76487d087919 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Sat, 6 May 2017 03:30:01 +0900 Subject: [PATCH] Fix test cases --- models/models.go | 11 ++--------- models/models_test.go | 9 ++++++++- scan/redhat_test.go | 11 +++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/models/models.go b/models/models.go index 726435c2..c7aa23aa 100644 --- a/models/models.go +++ b/models/models.go @@ -564,15 +564,8 @@ func (ps PackageInfoList) UniqByName() (distincted PackageInfoList) { for _, p := range ps { set[p.Name] = p } - //sort by key - keys := []string{} - for key := range set { - keys = append(keys, key) - } - //TODO remove - // sort.Strings(keys) - for _, key := range keys { - distincted = append(distincted, set[key]) + for _, v := range set { + distincted = append(distincted, v) } return } diff --git a/models/models_test.go b/models/models_test.go index 9c7dcb34..206d89e4 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -19,6 +19,7 @@ package models import ( "reflect" + "sort" "testing" "github.com/k0kubun/pp" @@ -51,8 +52,14 @@ func TestPackageInfoListUniqByName(t *testing.T) { } actual := test.in.UniqByName() + sort.Slice(actual, func(i, j int) bool { + return actual[i].Name < actual[j].Name + }) + sort.Slice(test.out, func(i, j int) bool { + return test.out[i].Name < test.out[j].Name + }) for i, ePack := range test.out { - if actual[i].Name == ePack.Name { + if actual[i].Name != ePack.Name { t.Errorf("expected %#v, actual %#v", ePack.Name, actual[i].Name) } } diff --git a/scan/redhat_test.go b/scan/redhat_test.go index 9eb78133..d63b7ef6 100644 --- a/scan/redhat_test.go +++ b/scan/redhat_test.go @@ -19,6 +19,7 @@ package scan import ( "reflect" + "sort" "testing" "time" @@ -653,6 +654,8 @@ Description : Package updates are available for Amazon Linux AMI that fix the for _, tt := range tests { actual, _ := r.parseYumUpdateinfo(tt.in) for i, advisoryCveIDs := range actual { + sort.Strings(tt.out[i].CveIDs) + sort.Strings(actual[i].CveIDs) if !reflect.DeepEqual(tt.out[i], advisoryCveIDs) { e := pp.Sprintf("%v", tt.out[i]) a := pp.Sprintf("%v", advisoryCveIDs) @@ -1115,7 +1118,7 @@ func TestGetChangelogCVELines(t *testing.T) { { models.PackageInfo{ Name: "dhclient", - NewVersion: "4.1.1", + NewVersion: "12:4.1.1", NewRelease: "51.P1.el6.centos", }, `- TESTSTRING CVE-1111-1111 @@ -1124,7 +1127,7 @@ func TestGetChangelogCVELines(t *testing.T) { { models.PackageInfo{ Name: "dhcp-common", - NewVersion: "4.1.1", + NewVersion: "12:4.1.1", NewRelease: "51.P1.el6.centos", }, `- TESTSTRING CVE-1111-1111 @@ -1234,7 +1237,7 @@ func TestGetChangelogCVELines(t *testing.T) { { models.PackageInfo{ Name: "bind-libs", - NewVersion: "9.3.6", + NewVersion: "30:9.3.6", NewRelease: "25.P1.el5_11.8", }, `- Fix issue with patch for CVE-2016-1285 and CVE-2016-1286 found by test suite @@ -1246,7 +1249,7 @@ func TestGetChangelogCVELines(t *testing.T) { { models.PackageInfo{ Name: "bind-utils", - NewVersion: "9.3.6", + NewVersion: "30:9.3.6", NewRelease: "25.P1.el5_11.8", }, `- Fix issue with patch for CVE-2016-1285 and CVE-2016-1286 found by test suite