forked from optiopay/klar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
36 lines (29 loc) · 885 Bytes
/
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
package main
import (
"fmt"
"reflect"
"testing"
"github.com/optiopay/klar/clair"
)
func TestFilterWhitelist(t *testing.T) {
image := "fluent/fluent-bit"
whitelist := &vulnerabilitiesWhitelist{
map[string]bool{"CVE-3": true},
map[string]map[string]bool{image: {"CVE-4": true}},
}
vs := make([]*clair.Vulnerability, 5)
for i := range vs {
vs[i] = mockVulnerability(fmt.Sprintf("CVE-%d", i))
}
expected := make([]*clair.Vulnerability, 3)
for i := range expected {
expected[i] = mockVulnerability(fmt.Sprintf("CVE-%d", i))
}
filtered := filterWhitelist(whitelist, vs, image)
if !reflect.DeepEqual(filtered, expected) {
t.Fatalf("Actual filtered vulnerabilities %s did not match expected ones %s.", filtered, expected)
}
}
func mockVulnerability(name string) *clair.Vulnerability {
return &clair.Vulnerability{name, "", "", "", "", nil, "", nil, "", ""}
}