Skip to content

Commit

Permalink
add test, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry committed Oct 10, 2024
1 parent cd16b7e commit 18bb1df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ func newCGHandlerBuilder(handler testCGRsolver) processors.InitCgroupHandler {
}
}

func TestNilProcessor(t *testing.T) {
initCgroupPaths = func(rootfsMountpoint resolve.Resolver, ignoreRootCgroups bool) (processors.CGReader, error) {
return &processors.NilCGReader{}, nil
}

proc, err := newProcessMetadataProcessorWithProvider(defaultConfig(), &procCache, false)
require.NoError(t, err)

// make sure a nil cgroup reader doesn't blow anything up
unwrapped, _ := proc.(*addProcessMetadata)
metadata, err := unwrapped.provider.GetProcessMetadata(os.Getpid())
require.NoError(t, err)
require.NotNil(t, metadata)

}

func TestDefaultProcessorStartup(t *testing.T) {
// set initCgroupPaths to system non-test defaults
initCgroupPaths = func(rootfsMountpoint resolve.Resolver, ignoreRootCgroups bool) (processors.CGReader, error) {
Expand All @@ -67,7 +83,7 @@ func TestDefaultProcessorStartup(t *testing.T) {
unwrapped, _ := proc.(*addProcessMetadata)
metadata, err := unwrapped.provider.GetProcessMetadata(os.Getpid())
require.NoError(t, err)
require.NotNil(t, metadata)
require.NotNil(t, metadata.fields)
}

func TestAddProcessMetadata(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (p gosigarCidProvider) GetCid(pid int) (result string, err error) {

cgroups, err := p.getProcessCgroups(pid)
if err != nil {
p.log.Debugf("failed to get cgroups for pid=%v: %v", pid, err)
return "", fmt.Errorf("failed to get cgroups for pid=%v: %v", pid, err)

Check failure on line 58 in libbeat/processors/add_process_metadata/gosigar_cid_provider.go

View workflow job for this annotation

GitHub Actions / lint (linux)

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}

cid = p.getContainerID(cgroups)
Expand Down

0 comments on commit 18bb1df

Please sign in to comment.