-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
80 lines (77 loc) · 1.96 KB
/
main_test.go
File metadata and controls
80 lines (77 loc) · 1.96 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"encoding/json"
"os"
"testing"
)
func TestParseDockerScoutReport(t *testing.T) {
type args struct {
file string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "valid nginx report",
args: args{file: "testdata/nginx-epss.json"},
wantErr: false,
},
{
name: "invalid file path",
args: args{file: "testdata/nonexistent.json"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data, err := os.ReadFile(tt.args.file)
if err != nil && !tt.wantErr {
t.Errorf("Failed to read test file: %v", err)
return
}
got, err := parse(data)
if (err != nil) != tt.wantErr {
t.Errorf("parse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr {
// Verify the output is valid JSON and has the expected structure
var manifest UpdateManifest
if err := json.Unmarshal([]byte(got), &manifest); err != nil {
t.Errorf("parse() output is not valid JSON: %v", err)
return
}
// Verify required fields
if manifest.APIVersion != "v1alpha1" {
t.Errorf("parse() output has wrong API version: got %s, want v1alpha1", manifest.APIVersion)
}
if manifest.Metadata.OS.Type == "" {
t.Error("parse() output missing OS type")
}
if manifest.Metadata.OS.Version == "" {
t.Error("parse() output missing OS version")
}
if manifest.Metadata.Config.Arch == "" {
t.Error("parse() output missing architecture")
}
if len(manifest.Updates) == 0 {
t.Error("parse() output has no updates")
}
// Verify update structure
for i, update := range manifest.Updates {
if update.Name == "" {
t.Errorf("Update %d missing name", i)
}
if update.InstalledVersion == "" {
t.Errorf("Update %d missing installed version", i)
}
if update.VulnerabilityID == "" {
t.Errorf("Update %d missing vulnerability ID", i)
}
}
}
})
}
}