Skip to content

Commit abbd43a

Browse files
committed
fix(rpc): update convert package + add test
1 parent 8ac22dc commit abbd43a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

pkg/rpc/convert.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func ConvertToRPCPkgs(pkgs []ftypes.Package) []*common.Package {
7575
Relationship: int32(pkg.Relationship),
7676
Indirect: pkg.Indirect,
7777
Maintainer: pkg.Maintainer,
78+
BuildInfo: ConvertToRPCBuildInfo(pkg.BuildInfo),
7879
})
7980
}
8081
return rpcPkgs
@@ -107,6 +108,17 @@ func ConvertToRPCLocations(pkgLocs []ftypes.Location) []*common.Location {
107108
return locations
108109
}
109110

111+
func ConvertToRPCBuildInfo(buildInfo *ftypes.BuildInfo) *common.BuildInfo {
112+
if buildInfo == nil {
113+
return nil
114+
}
115+
return &common.BuildInfo{
116+
ContentSets: buildInfo.ContentSets,
117+
Nvr: buildInfo.Nvr,
118+
Arch: buildInfo.Arch,
119+
}
120+
}
121+
110122
func ConvertToRPCCustomResources(resources []ftypes.CustomResource) []*common.CustomResource {
111123
var rpcResources []*common.CustomResource
112124
for _, r := range resources {
@@ -230,6 +242,7 @@ func ConvertFromRPCPkgs(rpcPkgs []*common.Package) []ftypes.Package {
230242
Relationship: ftypes.Relationship(pkg.Relationship),
231243
Indirect: pkg.Indirect,
232244
Maintainer: pkg.Maintainer,
245+
BuildInfo: ConvertFromRPCBuildInfo(pkg.BuildInfo),
233246
})
234247
}
235248
return pkgs
@@ -267,6 +280,18 @@ func ConvertFromRPCLocation(locs []*common.Location) []ftypes.Location {
267280
return pkgLocs
268281
}
269282

283+
// ConvertFromRPCBuildInfo converts *common.BuildInfo to *ftypes.BuildInfo
284+
func ConvertFromRPCBuildInfo(buildInfo *common.BuildInfo) *ftypes.BuildInfo {
285+
if buildInfo == nil {
286+
return nil
287+
}
288+
return &ftypes.BuildInfo{
289+
ContentSets: buildInfo.ContentSets,
290+
Nvr: buildInfo.Nvr,
291+
Arch: buildInfo.Arch,
292+
}
293+
}
294+
270295
// ConvertToRPCVulns returns common.Vulnerability
271296
func ConvertToRPCVulns(vulns []types.DetectedVulnerability) []*common.Vulnerability {
272297
var rpcVulns []*common.Vulnerability

pkg/rpc/convert_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ func TestConvertToRpcPkgs(t *testing.T) {
6262
Identifier: ftypes.PkgIdentifier{
6363
UID: "01",
6464
},
65+
BuildInfo: &ftypes.BuildInfo{
66+
ContentSets: []string{
67+
"rhel-8-for-x86_64-baseos-rpms",
68+
"rhel-8-for-x86_64-appstream-rpms",
69+
},
70+
// Nvr and arch are added for testing purposes only.
71+
// In real-world cases, buildInfo contains ContentSets or nvr+arch
72+
Nvr: "ubi8-container-8.3-227",
73+
Arch: "x86_64",
74+
},
6575
},
6676
},
6777
},
@@ -97,6 +107,16 @@ func TestConvertToRpcPkgs(t *testing.T) {
97107
Identifier: &common.PkgIdentifier{
98108
Uid: "01",
99109
},
110+
BuildInfo: &common.BuildInfo{
111+
ContentSets: []string{
112+
"rhel-8-for-x86_64-baseos-rpms",
113+
"rhel-8-for-x86_64-appstream-rpms",
114+
},
115+
// Nvr and arch are added for testing purposes only.
116+
// In real-world cases, buildInfo contains ContentSets or nvr+arch
117+
Nvr: "ubi8-container-8.3-227",
118+
Arch: "x86_64",
119+
},
100120
},
101121
},
102122
},
@@ -152,6 +172,12 @@ func TestConvertFromRpcPkgs(t *testing.T) {
152172
Identifier: &common.PkgIdentifier{
153173
Uid: "01",
154174
},
175+
BuildInfo: &common.BuildInfo{
176+
ContentSets: []string{
177+
"rhel-8-for-x86_64-baseos-rpms",
178+
"rhel-8-for-x86_64-appstream-rpms",
179+
},
180+
},
155181
},
156182
},
157183
},
@@ -187,6 +213,12 @@ func TestConvertFromRpcPkgs(t *testing.T) {
187213
Identifier: ftypes.PkgIdentifier{
188214
UID: "01",
189215
},
216+
BuildInfo: &ftypes.BuildInfo{
217+
ContentSets: []string{
218+
"rhel-8-for-x86_64-baseos-rpms",
219+
"rhel-8-for-x86_64-appstream-rpms",
220+
},
221+
},
190222
},
191223
},
192224
},
@@ -225,6 +257,10 @@ func TestConvertFromRpcPkgs(t *testing.T) {
225257
Uid: "63f8bef824b960e3",
226258
},
227259
Maintainer: "[email protected]",
260+
BuildInfo: &common.BuildInfo{
261+
Nvr: "ubi8-container-8.3-227",
262+
Arch: "x86_64",
263+
},
228264
},
229265
},
230266
},
@@ -261,6 +297,10 @@ func TestConvertFromRpcPkgs(t *testing.T) {
261297
UID: "63f8bef824b960e3",
262298
},
263299
Maintainer: "[email protected]",
300+
BuildInfo: &ftypes.BuildInfo{
301+
Nvr: "ubi8-container-8.3-227",
302+
Arch: "x86_64",
303+
},
264304
},
265305
},
266306
},

0 commit comments

Comments
 (0)