Skip to content

Commit

Permalink
feat: cyclonedx kbom support
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan committed Jun 6, 2023
1 parent 1946c3d commit cd90a14
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/k8s/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scanner

import (
"context"
"sort"
"testing"

cdx "github.com/CycloneDX/cyclonedx-go"
Expand All @@ -27,7 +28,7 @@ func TestK8sClusterInfoReport(t *testing.T) {
want *core.Component
}{
{
name: "test custer info with resources",
name: "test cluster info with resources",
clusterName: "test-cluster",
artifacts: []*artifacts.Artifact{
{
Expand Down Expand Up @@ -181,7 +182,31 @@ func TestK8sClusterInfoReport(t *testing.T) {
assert.NoError(t, err)
scanner := NewScanner(tt.clusterName, runner, flagOpts)
got, err := scanner.Scan(ctx, tt.artifacts)
sortNodeComponents(got.RootComponent)
sortNodeComponents(tt.want)
assert.Equal(t, tt.want, got.RootComponent)
})
}
}

type coreComponents []*core.Component

func (a coreComponents) Len() int { return len(a) }
func (a coreComponents) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a coreComponents) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func sortNodeComponents(component *core.Component) {
nodeComp := findComponentByName(component, "node-core-components")
sort.Sort(coreComponents(nodeComp.Components))
}

func findComponentByName(component *core.Component, compName string) *core.Component {
if component.Name == compName {
return component
}
var fComp *core.Component
for _, comp := range component.Components {
fComp = findComponentByName(comp, compName)
}
return fComp
}

0 comments on commit cd90a14

Please sign in to comment.