github.com/mier85/go-sensor@v1.30.1-0.20220920111756-9bf41b3bc7e0/process/stats_reader_linux_test.go (about)

     1  // (c) Copyright IBM Corp. 2021
     2  // (c) Copyright Instana Inc. 2020
     3  
     4  //go:build linux
     5  // +build linux
     6  
     7  package process_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/instana/testify/assert"
    13  	"github.com/instana/testify/require"
    14  	"github.com/mier85/go-sensor/process"
    15  )
    16  
    17  func TestStats_Memory(t *testing.T) {
    18  	rdr := process.Stats()
    19  	rdr.ProcPath = "testdata"
    20  
    21  	stats, err := rdr.Memory()
    22  	require.NoError(t, err)
    23  	assert.Equal(t, process.MemStats{
    24  		Total:  1 * 4 << 10,
    25  		Rss:    2 * 4 << 10,
    26  		Shared: 3 * 4 << 10,
    27  	}, stats)
    28  }
    29  
    30  func TestStats_CPU(t *testing.T) {
    31  	rdr := process.Stats()
    32  	rdr.ProcPath = "testdata"
    33  	rdr.Command = "Hello, brave new world"
    34  
    35  	stats, tick, err := rdr.CPU()
    36  	require.NoError(t, err)
    37  	assert.Equal(t, 71695348, tick)
    38  	assert.Equal(t, process.CPUStats{
    39  		User:   14,
    40  		System: 15,
    41  	}, stats)
    42  }
    43  
    44  func TestStats_Limits(t *testing.T) {
    45  	rdr := process.Stats()
    46  	rdr.ProcPath = "testdata"
    47  
    48  	limits, err := rdr.Limits()
    49  	require.NoError(t, err)
    50  	assert.Equal(t, process.ResourceLimits{
    51  		OpenFiles: process.LimitedResource{
    52  			Current: 4,
    53  			Max:     1024,
    54  		},
    55  	}, limits)
    56  }