From 306182e2aea0c3cd906cfaf062ba8fd933bfc4c4 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Thu, 25 May 2017 18:55:41 +0900 Subject: [PATCH] Fix test cases --- models/cvecontents_test.go | 62 +++++++++++++++++++++----------------- models/packages_test.go | 58 ----------------------------------- 2 files changed, 34 insertions(+), 86 deletions(-) diff --git a/models/cvecontents_test.go b/models/cvecontents_test.go index dbafb037..5eabfb10 100644 --- a/models/cvecontents_test.go +++ b/models/cvecontents_test.go @@ -687,55 +687,61 @@ func TestSourceLinks(t *testing.T) { func TestVendorLink(t *testing.T) { type in struct { family string - cont CveContents + vinfo VulnInfo } var tests = []struct { in in - out CveContentStr + out map[string]string }{ { in: in{ - family: "redhat", - cont: CveContents{ - JVN: { - Type: JVN, - SourceLink: "https://jvn.jp/vu/JVNVU93610402/", - }, - RedHat: { - Type: RedHat, - SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", - }, - NVD: { - Type: NVD, - SourceLink: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", + family: "rhel", + vinfo: VulnInfo{ + CveID: "CVE-2017-6074", + CveContents: CveContents{ + JVN: { + Type: JVN, + SourceLink: "https://jvn.jp/vu/JVNVU93610402/", + }, + RedHat: { + Type: RedHat, + SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", + }, + NVD: { + Type: NVD, + SourceLink: "https://nvd.nist.gov/vuln/detail/CVE-2017-6074", + }, }, }, }, - out: CveContentStr{ - Type: RedHat, - Value: "https://access.redhat.com/security/cve/CVE-2017-6074", + out: map[string]string{ + "RHEL-CVE": "https://access.redhat.com/security/cve/CVE-2017-6074", }, }, { in: in{ family: "ubuntu", - cont: CveContents{ - RedHat: { - Type: RedHat, - SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", + vinfo: VulnInfo{ + CveID: "CVE-2017-6074", + CveContents: CveContents{ + RedHat: { + Type: Ubuntu, + SourceLink: "https://access.redhat.com/security/cve/CVE-2017-6074", + }, }, }, }, - out: CveContentStr{ - Type: Ubuntu, - Value: "", + out: map[string]string{ + "Ubuntu-CVE": "http://people.ubuntu.com/~ubuntu-security/cve/CVE-2017-6074", }, }, } for _, tt := range tests { - actual := tt.in.cont.VendorLink(tt.in.family) - if !reflect.DeepEqual(tt.out, actual) { - t.Errorf("\nexpected: %v\n actual: %v\n", tt.out, actual) + actual := tt.in.vinfo.VendorLinks(tt.in.family) + for k := range tt.out { + if tt.out[k] != actual[k] { + t.Errorf("\nexpected: %s\n actual: %s\n", tt.out[k], actual[k]) + } } } } diff --git a/models/packages_test.go b/models/packages_test.go index ae92e410..48eb99d8 100644 --- a/models/packages_test.go +++ b/models/packages_test.go @@ -87,61 +87,3 @@ func TestMerge(t *testing.T) { t.Errorf("expected %s, actual %s", e, a) } } - -func TestFormatVersionsFromTo(t *testing.T) { - var tests = []struct { - packs Packages - expected string - }{ - { - packs: Packages{ - "hoge": { - Name: "hoge", - Version: "1.0.0", - Release: "release1", - NewVersion: "1.0.1", - NewRelease: "release2", - }, - }, - expected: "hoge-1.0.0-release1 -> hoge-1.0.1-release2", - }, - { - packs: Packages{ - "hoge": { - Name: "hoge", - Version: "1.0.0", - Release: "", - NewVersion: "1.0.1", - NewRelease: "", - }, - }, - expected: "hoge-1.0.0 -> hoge-1.0.1", - }, - { - packs: Packages{ - "hoge": { - Name: "hoge", - Version: "1.0.0", - Release: "", - NewVersion: "1.0.1", - NewRelease: "", - }, - "fuga": { - Name: "fuga", - Version: "2.0.0", - Release: "", - NewVersion: "2.0.1", - NewRelease: "", - }, - }, - expected: "hoge-1.0.0 -> hoge-1.0.1\nfuga-2.0.0 -> fuga-2.0.1", - }, - } - - for _, tt := range tests { - actual := tt.packs.FormatVersionsFromTo() - if !reflect.DeepEqual(tt.expected, actual) { - t.Errorf("\nexpected: %v\n actual: %v\n", tt.expected, actual) - } - } -}