forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbom_test.go
80 lines (73 loc) · 1.88 KB
/
bom_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package dtrack
import (
"context"
"encoding/base64"
"github.com/stretchr/testify/require"
"testing"
)
func TestBOMService_Upload(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionBOMUpload,
PermissionProjectCreationUpload,
PermissionViewPortfolio,
},
})
_, err := client.BOM.Upload(context.Background(), BOMUploadRequest{
ProjectName: "acme-app",
ProjectVersion: "1.2.3",
ProjectTags: []Tag{
{Name: "foo"},
{Name: "bar"},
},
IsLatest: OptionalBoolOf(true),
AutoCreate: true,
BOM: base64.StdEncoding.EncodeToString([]byte(`
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"components": []
}`)),
})
require.NoError(t, err)
project, err := client.Project.Lookup(context.Background(), "acme-app", "1.2.3")
require.NoError(t, err)
require.Contains(t, project.Tags, Tag{Name: "foo"})
require.Contains(t, project.Tags, Tag{Name: "bar"})
require.NotNil(t, project.IsLatest)
require.True(t, *project.IsLatest)
}
func TestBOMService_PostBom(t *testing.T) {
client := setUpContainer(t, testContainerOptions{
APIPermissions: []string{
PermissionBOMUpload,
PermissionProjectCreationUpload,
PermissionViewPortfolio,
},
})
_, err := client.BOM.PostBom(context.Background(), BOMUploadRequest{
ProjectName: "acme-app",
ProjectVersion: "1.2.3",
ProjectTags: []Tag{
{Name: "foo"},
{Name: "bar"},
},
IsLatest: OptionalBoolOf(true),
AutoCreate: true,
BOM: `
{
"bomFormat": "CycloneDX",
"specVersion": "1.4",
"version": 1,
"components": []
}`,
})
require.NoError(t, err)
project, err := client.Project.Lookup(context.Background(), "acme-app", "1.2.3")
require.NoError(t, err)
require.Contains(t, project.Tags, Tag{Name: "foo"})
require.Contains(t, project.Tags, Tag{Name: "bar"})
require.NotNil(t, project.IsLatest)
require.True(t, *project.IsLatest)
}