Skip to content

Commit

Permalink
tetragon: Add GetDefaultSensorsWithBase function
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Sep 23, 2024
1 parent 8b9dd6c commit 9959201
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/observer/observertesthelper/observer_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,22 @@ func GetDefaultObserverWithFile(tb testing.TB, ctx context.Context, file, lib st
return GetDefaultObserverWithWatchers(tb, ctx, b, opts...)
}

func GetDefaultSensorsWithBase(tb testing.TB, b *sensors.Sensor, file, lib string, opts ...TestOption) ([]*sensors.Sensor, error) {
opts = append(opts, WithConfig(file))
opts = append(opts, WithLib(lib))

return getDefaultSensors(tb, b, opts...)
}

func GetDefaultSensorsWithFile(tb testing.TB, file, lib string, opts ...TestOption) ([]*sensors.Sensor, error) {
opts = append(opts, WithConfig(file))
opts = append(opts, WithLib(lib))

b := base.GetInitialSensor()
return getDefaultSensors(tb, b, opts...)
}

func getDefaultSensors(tb testing.TB, initialSensor *sensors.Sensor, opts ...TestOption) ([]*sensors.Sensor, error) {
option.Config.BpfDir = bpf.MapPrefixPath()

testutils.CaptureLog(tb, logger.GetLogger().(*logrus.Logger))
Expand Down Expand Up @@ -327,13 +339,11 @@ func GetDefaultSensorsWithFile(tb testing.TB, file, lib string, opts ...TestOpti
}
}

base := base.GetInitialSensor()

if err = loadSensors(tb, base, sens); err != nil {
if err = loadSensors(tb, initialSensor, sens); err != nil {
return nil, err
}

sens = append(sens, base)
sens = append(sens, initialSensor)
ret := make([]*sensors.Sensor, 0, len(sens))
for _, si := range sens {
if s, ok := si.(*sensors.Sensor); ok {
Expand Down

0 comments on commit 9959201

Please # to comment.