-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathnode.go
More file actions
58 lines (52 loc) · 1.73 KB
/
node.go
File metadata and controls
58 lines (52 loc) · 1.73 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
package fixtures
import (
"fmt"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/fixtures/fixtureconsts"
"github.com/stackrox/rox/pkg/protocompat"
)
// GetNode returns a mock *storage.Node
func GetNode() *storage.Node {
componentCount := 50
components := make([]*storage.EmbeddedNodeScanComponent, 0, componentCount)
for i := 0; i < componentCount; i++ {
components = append(components, &storage.EmbeddedNodeScanComponent{
Name: "name",
Version: "1.2.3.4",
Vulns: getVulnsPerComponent(i, 5, storage.EmbeddedVulnerability_NODE_VULNERABILITY),
})
}
return getNodeWithComponents(components)
}
// GetNodeWithUniqueComponents returns a mock Node where each component is unique
func GetNodeWithUniqueComponents(numComponents, numVulns int) *storage.Node {
components := make([]*storage.EmbeddedNodeScanComponent, 0, numComponents)
for i := 0; i < numComponents; i++ {
components = append(components, &storage.EmbeddedNodeScanComponent{
Name: fmt.Sprintf("name-%d", i),
Version: fmt.Sprintf("%d.2.3.4", i),
Vulns: getVulnsPerComponent(i, numVulns, storage.EmbeddedVulnerability_NODE_VULNERABILITY),
})
}
return getNodeWithComponents(components)
}
func getNodeWithComponents(components []*storage.EmbeddedNodeScanComponent) *storage.Node {
return &storage.Node{
Id: fixtureconsts.Node1,
Name: "name",
Scan: &storage.NodeScan{
ScanTime: protocompat.TimestampNow(),
Components: components,
},
SetComponents: &storage.Node_Components{
Components: int32(len(components)),
},
}
}
// GetScopedNode returns a mock Node belonging to the input scope.
func GetScopedNode(ID string, clusterID string) *storage.Node {
return &storage.Node{
Id: ID,
ClusterId: clusterID,
}
}