forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyclonedx_test.go
62 lines (59 loc) · 1.56 KB
/
cyclonedx_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
61
62
package report
import (
"os"
"path/filepath"
"testing"
"github.com/Checkmarx/kics/pkg/model"
"github.com/Checkmarx/kics/test"
"github.com/stretchr/testify/require"
)
// TestPrintCycloneDxReport prints the CycloneDX report
func TestPrintCycloneDxReport(t *testing.T) {
type args struct {
path string
filename string
body interface{}
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Test1 PrintCycloneDxReport", // Unable to get sha-256: reports no vulnerabilities
args: args{
path: "./testdir",
filename: "testout",
body: test.SummaryMock,
},
wantErr: false,
},
{
name: "Test2 PrintCycloneDxReport", // Able to get sha-256: reports vulnerabilities
args: args{
path: "./testdir",
filename: "testout",
body: test.ExampleSummaryMock,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
queries := tt.args.body.(model.Summary).Queries
for idx := range queries {
for i := range queries[idx].Files {
queries[idx].Files[i].FileName = filepath.Join("..", "..", queries[idx].Files[i].FileName)
}
}
if err := os.MkdirAll(tt.args.path, os.ModePerm); err != nil {
t.Fatal(err)
}
if err := PrintCycloneDxReport(tt.args.path, tt.args.filename, tt.args.body); (err != nil) != tt.wantErr {
t.Errorf("PrintCycloneDxReport() error = %v, wantErr %v", err, tt.wantErr)
}
require.FileExists(t, filepath.Join(tt.args.path, "cyclonedx-"+tt.args.filename+".xml"))
os.RemoveAll(tt.args.path)
})
}
}