Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
64
plugins/inputs/system/system_test.go
Normal file
64
plugins/inputs/system/system_test.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/host"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUniqueUsers(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
expected int
|
||||
data []host.UserStat
|
||||
}{
|
||||
{
|
||||
name: "single entry",
|
||||
expected: 1,
|
||||
data: []host.UserStat{
|
||||
{User: "root"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty entry",
|
||||
expected: 0,
|
||||
},
|
||||
{
|
||||
name: "all duplicates",
|
||||
expected: 1,
|
||||
data: []host.UserStat{
|
||||
{User: "root"},
|
||||
{User: "root"},
|
||||
{User: "root"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "all unique",
|
||||
expected: 3,
|
||||
data: []host.UserStat{
|
||||
{User: "root"},
|
||||
{User: "ubuntu"},
|
||||
{User: "ec2-user"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "mix of dups",
|
||||
expected: 3,
|
||||
data: []host.UserStat{
|
||||
{User: "root"},
|
||||
{User: "ubuntu"},
|
||||
{User: "ubuntu"},
|
||||
{User: "ubuntu"},
|
||||
{User: "ec2-user"},
|
||||
{User: "ec2-user"},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
actual := findUniqueUsers(tt.data)
|
||||
require.Equal(t, tt.expected, actual, tt.name)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue