feat: add verbose mode for cves for image listing (#2308)

Signed-off-by: Vishwas Rajashekar <vrajashe@cisco.com>
This commit is contained in:
Vishwas R
2024-03-13 02:08:48 +05:30
committed by GitHub
parent 413514c0d4
commit c7472a2dda
4 changed files with 214 additions and 9 deletions
+37
View File
@@ -213,6 +213,43 @@ func TestSearchCVECmd(t *testing.T) {
So(err, ShouldBeNil)
})
Convey("Test CVE by image name - in text format - in verbose mode", t, func() {
args := []string{"list", "dummyImageName:tag", "--url", baseURL, "--verbose"}
configPath := makeConfigFile(`{"configs":[{"_name":"cvetest","showspinner":false}]}`)
defer os.Remove(configPath)
cveCmd := NewCVECommand(new(mockService))
buff := bytes.NewBufferString("")
cveCmd.SetOut(buff)
cveCmd.SetErr(buff)
cveCmd.SetArgs(args)
err := cveCmd.Execute()
outputLines := strings.Split(buff.String(), "\n")
expected := []string{
"CRITICAL 0, HIGH 1, MEDIUM 0, LOW 0, UNKNOWN 0, TOTAL 1",
"",
"dummyCVEID",
"Severity: HIGH",
"Title: Title of that CVE",
"Description:",
"Description of the CVE",
"",
"Vulnerable Packages:",
" Package Name: packagename",
" Package Path: ",
" Installed Version: installedver",
" Fixed Version: fixedver",
"",
"",
}
for index, expectedLine := range expected {
So(outputLines[index], ShouldEqual, expectedLine)
}
So(err, ShouldBeNil)
})
Convey("Test CVE by image name - in json format", t, func() {
args := []string{"list", "dummyImageName:tag", "--url", baseURL, "-f", "json"}
configPath := makeConfigFile(`{"configs":[{"_name":"cvetest","showspinner":false}]}`)