-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
60 lines (46 loc) · 1.16 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"encoding/json"
"fmt"
"testing"
"github.com/aquasecurity/trivy/pkg/types"
)
var resultOne types.Result
var resultTwo types.Result
var vulnOne string = `[
{
"VulnerabilityID": "CVE-2023-52425"
},
{
"VulnerabilityID": "CVE-2024-28757"
},
{
"VulnerabilityID": "CVE-2023-52426"
}
]`
var vulnTwo string = `[
{
"VulnerabilityID": "CVE-2023-52425"
},
{
"VulnerabilityID": "CVE-2024-28757"
}
]`
func TestDifference(t *testing.T) {
json.Unmarshal([]byte(vulnOne), &resultOne.Vulnerabilities)
json.Unmarshal([]byte(vulnTwo), &resultTwo.Vulnerabilities)
expectedVulnID := "CVE-2023-52426"
diffResultIs, err := Difference(resultOne, resultTwo)
if err != nil {
fmt.Println("Error: \n", err)
}
if diffResultIs.Vulnerabilities == nil {
t.Errorf("No differences found between reports")
}
vulnOutputOne := diffResultIs.Vulnerabilities
if vulnOutputOne[0].VulnerabilityID != expectedVulnID || vulnOutputOne[0].VulnerabilityID == "" {
t.Errorf("The result don't match between what we have %q and what we want %q", vulnOutputOne[0].VulnerabilityID, expectedVulnID)
} else {
fmt.Printf("The test passed \n")
}
}