/
processes_and_endpoints.go
76 lines (61 loc) · 2.72 KB
/
processes_and_endpoints.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
package suites
import (
"time"
"github.com/stackrox/collector/integration-tests/pkg/collector"
"github.com/stackrox/collector/integration-tests/pkg/common"
"github.com/stackrox/collector/integration-tests/pkg/config"
"github.com/stackrox/collector/integration-tests/pkg/types"
"github.com/stretchr/testify/assert"
)
type ProcessesAndEndpointsTestSuite struct {
IntegrationTestSuiteBase
container string
Executable string
Args []string
ExpectedEndpoints []types.EndpointInfo
ExpectedProcesses []types.ProcessInfo
ContainerName string
}
func (s *ProcessesAndEndpointsTestSuite) SetupSuite() {
s.RegisterCleanup(s.ContainerName)
s.StartContainerStats()
collectorOptions := collector.StartupOptions{
Env: map[string]string{
"ROX_PROCESSES_LISTENING_ON_PORT": "true",
},
Config: map[string]any{
"turnOffScrape": false,
},
}
s.StartCollector(false, &collectorOptions)
image := config.Images().QaImageByKey("qa-plop")
cmd := []string{"--entrypoint", s.Executable, image}
cmd = append(cmd, s.Args...)
containerID, err := s.launchContainer(s.ContainerName, cmd...)
s.Require().NoError(err)
s.container = common.ContainerShortID(containerID)
}
func (s *ProcessesAndEndpointsTestSuite) TearDownSuite() {
s.StopCollector()
s.cleanupContainers(s.ContainerName)
s.WritePerfResults()
}
func (s *ProcessesAndEndpointsTestSuite) TestProcessesAndEndpoints() {
processes := s.Sensor().ExpectProcessesN(s.T(), s.container, 20*time.Second, len(s.ExpectedProcesses))
endpoints := s.Sensor().ExpectEndpointsN(s.T(), s.container, 20*time.Second, len(s.ExpectedEndpoints))
assert.Equal(s.T(), len(s.ExpectedEndpoints), len(endpoints))
assert.Equal(s.T(), len(s.ExpectedProcesses), len(processes))
minEndpoints := common.Min(len(s.ExpectedEndpoints), len(endpoints))
types.SortEndpoints(endpoints)
for idx := 0; idx < minEndpoints; idx++ {
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Protocol, endpoints[idx].Protocol)
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Address.AddressData, endpoints[idx].Address.AddressData)
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Address.Port, endpoints[idx].Address.Port)
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Address.IpNetwork, endpoints[idx].Address.IpNetwork)
assert.Equal(s.T(), s.ExpectedEndpoints[idx].IsActive(), endpoints[idx].IsActive())
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Originator.ProcessName, endpoints[idx].Originator.ProcessName)
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Originator.ProcessExecFilePath, endpoints[idx].Originator.ProcessExecFilePath)
assert.Equal(s.T(), s.ExpectedEndpoints[idx].Originator.ProcessArgs, endpoints[idx].Originator.ProcessArgs)
}
assert.ElementsMatch(s.T(), s.ExpectedProcesses, processes)
}