Skip to content

Commit

Permalink
Adding unit tests for memory_swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Paramadon committed Sep 30, 2024
1 parent cbe0c46 commit e4308f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion patches/gopsutil/v3/process/process_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (

type MemoryInfoExStat struct{}

type MemoryMapsStat struct{}
type MemoryMapsStat struct {
Swap uint64
}

func (p *Process) TgidWithContext(ctx context.Context) (int32, error) {
return 0, common.ErrNotImplementedError
Expand Down
19 changes: 9 additions & 10 deletions plugins/inputs/procstat/procstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ func (p *testProc) MemoryInfo() (*process.MemoryInfoStat, error) {
return &process.MemoryInfoStat{}, nil
}

func (p *testProc) MemoryMaps(bool) (*[]process.MemoryMapsStat, error) {
return &[]process.MemoryMapsStat{}, nil
func (p *testProc) MemoryMaps(_ bool) (*[]process.MemoryMapsStat, error) {
return &[]process.MemoryMapsStat{
{
Swap: 1024,
},
}, nil
}

func (p *testProc) Name() (string, error) {
return "test_proc", nil
}
Expand Down Expand Up @@ -459,19 +464,13 @@ func TestGather_MemorySwap(t *testing.T) {
Exe: exe,
Properties: []string{"mmap"},
createPIDFinder: pidFinder([]PID{pid}),
createProcess: func(pid PID) (Process, error) {
return &testProc{
pid: pid,
tags: map[string]string{
"memory_swap": "1024",
},
}, nil
},
createProcess: newTestProc,
}

require.NoError(t, acc.GatherError(p.Gather))

require.True(t, acc.HasIntField("procstat", "memory_swap"))

fields := acc.Metrics[0].Fields
require.Equal(t, int64(1024), fields["memory_swap"])
}

0 comments on commit e4308f8

Please sign in to comment.