rename redundant test function names, such as TestCPU in cpu package

pull/1628/head
shirou 1 year ago
parent 85f5f3a8e2
commit e9591b5b01

@ -10,7 +10,7 @@ import (
"github.com/shoenig/go-m1cpu"
)
func Test_CpuInfo_AppleSilicon(t *testing.T) {
func TestInfo_AppleSilicon(t *testing.T) {
if !m1cpu.IsAppleSilicon() {
t.Skip("wrong cpu type")
}

@ -21,7 +21,7 @@ func TestTimesEmpty(t *testing.T) {
}
}
func TestCPUparseStatLine_424(t *testing.T) {
func TestParseStatLine_424(t *testing.T) {
t.Setenv("HOST_PROC", "testdata/linux/424/proc")
{
l, err := Times(true)
@ -39,7 +39,7 @@ func TestCPUparseStatLine_424(t *testing.T) {
}
}
func TestCPUCountsAgainstLscpu(t *testing.T) {
func TestCountsAgainstLscpu(t *testing.T) {
cmd := exec.Command("lscpu")
cmd.Env = []string{"LC_ALL=C"}
out, err := cmd.Output()
@ -94,7 +94,7 @@ func TestCPUCountsAgainstLscpu(t *testing.T) {
}
}
func TestCPUCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/shirou/gopsutil/issues/1037
func TestCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/shirou/gopsutil/issues/1037
t.Setenv("HOST_PROC", "testdata/linux/1037/proc")
count, err := Counts(true)

@ -20,7 +20,7 @@ func skipIfNotImplementedErr(t *testing.T, err error) {
}
}
func TestCpu_times(t *testing.T) {
func TestTimes(t *testing.T) {
v, err := Times(false)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -78,7 +78,7 @@ func TestCpu_times(t *testing.T) {
}
}
func TestCpu_counts(t *testing.T) {
func TestCounts(t *testing.T) {
v, err := Counts(true)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -99,7 +99,7 @@ func TestCpu_counts(t *testing.T) {
t.Logf("physical cores: %d", v)
}
func TestCPUTimeStat_String(t *testing.T) {
func TestTimeStat_String(t *testing.T) {
v := TimesStat{
CPU: "cpu0",
User: 100.1,
@ -112,7 +112,7 @@ func TestCPUTimeStat_String(t *testing.T) {
}
}
func TestCpuInfo(t *testing.T) {
func TestInfo(t *testing.T) {
v, err := Info()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -128,7 +128,7 @@ func TestCpuInfo(t *testing.T) {
}
}
func testCPUPercent(t *testing.T, percpu bool) {
func testPercent(t *testing.T, percpu bool) {
numcpu := runtime.NumCPU()
testCount := 3
@ -162,7 +162,7 @@ func testCPUPercent(t *testing.T, percpu bool) {
}
}
func testCPUPercentLastUsed(t *testing.T, percpu bool) {
func testPercentLastUsed(t *testing.T, percpu bool) {
numcpu := runtime.NumCPU()
testCount := 10
@ -196,18 +196,18 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
}
}
func TestCPUPercent(t *testing.T) {
testCPUPercent(t, false)
func TestPercent(t *testing.T) {
testPercent(t, false)
}
func TestCPUPercentPerCpu(t *testing.T) {
testCPUPercent(t, true)
func TestPercentPerCpu(t *testing.T) {
testPercent(t, true)
}
func TestCPUPercentIntervalZero(t *testing.T) {
testCPUPercentLastUsed(t, false)
func TestPercentIntervalZero(t *testing.T) {
testPercentLastUsed(t, false)
}
func TestCPUPercentIntervalZeroPerCPU(t *testing.T) {
testCPUPercentLastUsed(t, true)
func TestPercentIntervalZeroPerCPU(t *testing.T) {
testPercentLastUsed(t, true)
}

@ -17,7 +17,7 @@ func skipIfNotImplementedErr(t *testing.T, err error) {
}
}
func TestDisk_usage(t *testing.T) {
func TestUsage(t *testing.T) {
path := "/"
if runtime.GOOS == "windows" {
path = "C:"
@ -32,7 +32,7 @@ func TestDisk_usage(t *testing.T) {
}
}
func TestDisk_partitions(t *testing.T) {
func TestPartitions(t *testing.T) {
ret, err := Partitions(false)
skipIfNotImplementedErr(t, err)
if err != nil || len(ret) == 0 {
@ -50,7 +50,7 @@ func TestDisk_partitions(t *testing.T) {
}
}
func TestDisk_io_counters(t *testing.T) {
func TestIOCounters(t *testing.T) {
ret, err := IOCounters()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -69,7 +69,7 @@ func TestDisk_io_counters(t *testing.T) {
}
// https://github.com/shirou/gopsutil/issues/560 regression test
func TestDisk_io_counters_concurrency_on_darwin_cgo(t *testing.T) {
func TestIOCounters_concurrency_on_darwin_cgo(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("darwin only")
}
@ -85,7 +85,7 @@ func TestDisk_io_counters_concurrency_on_darwin_cgo(t *testing.T) {
wg.Wait()
}
func TestDiskUsageStat_String(t *testing.T) {
func TestUsageStat_String(t *testing.T) {
v := UsageStat{
Path: "/",
Total: 1000,
@ -104,7 +104,7 @@ func TestDiskUsageStat_String(t *testing.T) {
}
}
func TestDiskPartitionStat_String(t *testing.T) {
func TestPartitionStat_String(t *testing.T) {
v := PartitionStat{
Device: "sd01",
Mountpoint: "/",
@ -117,7 +117,7 @@ func TestDiskPartitionStat_String(t *testing.T) {
}
}
func TestDiskIOCountersStat_String(t *testing.T) {
func TestIOCountersStat_String(t *testing.T) {
v := IOCountersStat{
Name: "sd01",
ReadCount: 100,

@ -64,7 +64,7 @@ func TestGetRedhatishPlatform(t *testing.T) {
}
}
func Test_getlsbStruct(t *testing.T) {
func TestGetlsbStruct(t *testing.T) {
cases := []struct {
root string
id string

@ -17,7 +17,7 @@ func skipIfNotImplementedErr(t *testing.T, err error) {
}
}
func TestHostInfo(t *testing.T) {
func TestInfo(t *testing.T) {
v, err := Info()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -48,7 +48,7 @@ func TestUptime(t *testing.T) {
}
}
func TestBoot_time(t *testing.T) {
func TestBootTime(t *testing.T) {
if os.Getenv("CI") == "true" {
t.Skip("Skip CI")
}
@ -94,7 +94,7 @@ func TestUsers(t *testing.T) {
}
}
func TestHostInfoStat_String(t *testing.T) {
func TestInfoStat_String(t *testing.T) {
v := InfoStat{
Hostname: "test",
Uptime: 3000,
@ -124,7 +124,7 @@ func TestUserStat_String(t *testing.T) {
}
}
func TestHostGuid(t *testing.T) {
func TestGuid(t *testing.T) {
id, err := HostID()
skipIfNotImplementedErr(t, err)
if err != nil {

@ -15,7 +15,7 @@ func skipIfNotImplementedErr(t testing.TB, err error) {
}
}
func TestLoad(t *testing.T) {
func TestAvg(t *testing.T) {
v, err := Avg()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -29,7 +29,7 @@ func TestLoad(t *testing.T) {
t.Log(v)
}
func TestLoadAvgStat_String(t *testing.T) {
func TestAvgStat_String(t *testing.T) {
v := AvgStat{
Load1: 10.1,
Load5: 20.1,

@ -18,7 +18,7 @@ func skipIfNotImplementedErr(t *testing.T, err error) {
}
}
func TestVirtual_memory(t *testing.T) {
func TestVirtualMemory(t *testing.T) {
if runtime.GOOS == "solaris" || runtime.GOOS == "illumos" {
t.Skip("Only .Total .Available are supported on Solaris/illumos")
}
@ -67,7 +67,7 @@ func TestVirtual_memory(t *testing.T) {
"UsedPercent should be how many percent of Total is Used: %v", v)
}
func TestSwap_memory(t *testing.T) {
func TestSwapMemory(t *testing.T) {
v, err := SwapMemory()
skipIfNotImplementedErr(t, err)
if err != nil {

@ -26,7 +26,7 @@ func TestAddrString(t *testing.T) {
}
}
func TestNetIOCountersStatString(t *testing.T) {
func TestIOCountersStatString(t *testing.T) {
v := IOCountersStat{
Name: "test",
BytesSent: 100,
@ -37,7 +37,7 @@ func TestNetIOCountersStatString(t *testing.T) {
}
}
func TestNetProtoCountersStatString(t *testing.T) {
func TestProtoCountersStatString(t *testing.T) {
v := ProtoCountersStat{
Protocol: "tcp",
Stats: map[string]int64{
@ -52,7 +52,7 @@ func TestNetProtoCountersStatString(t *testing.T) {
}
}
func TestNetConnectionStatString(t *testing.T) {
func TestConnectionStatString(t *testing.T) {
v := ConnectionStat{
Fd: 10,
Family: 10,
@ -65,7 +65,7 @@ func TestNetConnectionStatString(t *testing.T) {
}
}
func TestNetIOCountersAll(t *testing.T) {
func TestIOCountersAll(t *testing.T) {
v, err := IOCounters(false)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -103,7 +103,7 @@ func TestNetIOCountersAll(t *testing.T) {
}
}
func TestNetIOCountersPerNic(t *testing.T) {
func TestIOCountersPerNic(t *testing.T) {
v, err := IOCounters(true)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -152,7 +152,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
}
}
func TestNetInterfaces(t *testing.T) {
func TestInterfaces(t *testing.T) {
v, err := Interfaces()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -168,7 +168,7 @@ func TestNetInterfaces(t *testing.T) {
}
}
func TestNetProtoCountersStatsAll(t *testing.T) {
func TestProtoCountersStatsAll(t *testing.T) {
v, err := ProtoCounters(nil)
skipIfNotImplementedErr(t, err)
if err != nil {
@ -187,7 +187,7 @@ func TestNetProtoCountersStatsAll(t *testing.T) {
}
}
func TestNetProtoCountersStats(t *testing.T) {
func TestProtoCountersStats(t *testing.T) {
v, err := ProtoCounters([]string{"tcp", "ip"})
skipIfNotImplementedErr(t, err)
if err != nil {
@ -209,8 +209,8 @@ func TestNetProtoCountersStats(t *testing.T) {
}
}
func TestNetConnections(t *testing.T) {
if ci := os.Getenv("CI"); ci != "" { // skip if test on drone.io
func TestConnections(t *testing.T) {
if ci := os.Getenv("CI"); ci != "" { // skip if test on CI
return
}
@ -229,8 +229,8 @@ func TestNetConnections(t *testing.T) {
}
}
func TestNetFilterCounters(t *testing.T) {
if ci := os.Getenv("CI"); ci != "" { // skip if test on drone.io
func TestFilterCounters(t *testing.T) {
if ci := os.Getenv("CI"); ci != "" { // skip if test on CI
return
}

@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
)
func Test_Process_splitProcStat(t *testing.T) {
func TestSplitProcStat(t *testing.T) {
expectedFieldsNum := 53
statLineContent := make([]string, expectedFieldsNum-1)
for i := 0; i < expectedFieldsNum-1; i++ {
@ -56,7 +56,7 @@ func Test_Process_splitProcStat(t *testing.T) {
}
}
func Test_Process_splitProcStat_fromFile(t *testing.T) {
func TestSplitProcStat_fromFile(t *testing.T) {
pids, err := os.ReadDir("testdata/linux/")
if err != nil {
t.Error(err)
@ -92,7 +92,7 @@ func Test_Process_splitProcStat_fromFile(t *testing.T) {
}
}
func Test_fillFromCommWithContext(t *testing.T) {
func TestFillFromCommWithContext(t *testing.T) {
pids, err := os.ReadDir("testdata/linux/")
if err != nil {
t.Error(err)
@ -113,7 +113,7 @@ func Test_fillFromCommWithContext(t *testing.T) {
}
}
func Test_fillFromStatusWithContext(t *testing.T) {
func TestFillFromStatusWithContext(t *testing.T) {
pids, err := os.ReadDir("testdata/linux/")
if err != nil {
t.Error(err)
@ -152,7 +152,7 @@ func Benchmark_fillFromStatusWithContext(b *testing.B) {
}
}
func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) {
func TestFillFromTIDStatWithContext_lx_brandz(t *testing.T) {
pids, err := os.ReadDir("testdata/lx_brandz/")
if err != nil {
t.Error(err)

@ -8,7 +8,7 @@ import (
"testing"
)
func Test_Process_Ppid_Race(t *testing.T) {
func TestPpid_Race(t *testing.T) {
wg := sync.WaitGroup{}
testCount := 10
p := testGetProcess()

@ -39,7 +39,7 @@ func testGetProcess() Process {
return *ret
}
func Test_Pids(t *testing.T) {
func TestPids(t *testing.T) {
ret, err := Pids()
skipIfNotImplementedErr(t, err)
if err != nil {
@ -50,7 +50,7 @@ func Test_Pids(t *testing.T) {
}
}
func Test_Pid_exists(t *testing.T) {
func TestPid_exists(t *testing.T) {
checkPid := os.Getpid()
ret, err := PidExists(int32(checkPid))
@ -64,7 +64,7 @@ func Test_Pid_exists(t *testing.T) {
}
}
func Test_NewProcess(t *testing.T) {
func TestNewProcess(t *testing.T) {
checkPid := os.Getpid()
ret, err := NewProcess(int32(checkPid))
@ -80,7 +80,7 @@ func Test_NewProcess(t *testing.T) {
}
}
func Test_Process_memory_maps(t *testing.T) {
func TestMemoryMaps(t *testing.T) {
checkPid := os.Getpid()
ret, err := NewProcess(int32(checkPid))
@ -116,7 +116,7 @@ func Test_Process_memory_maps(t *testing.T) {
}
}
func Test_Process_MemoryInfo(t *testing.T) {
func TestMemoryInfo(t *testing.T) {
p := testGetProcess()
v, err := p.MemoryInfo()
@ -130,7 +130,7 @@ func Test_Process_MemoryInfo(t *testing.T) {
}
}
func Test_Process_CmdLine(t *testing.T) {
func TestCmdLine(t *testing.T) {
p := testGetProcess()
v, err := p.Cmdline()
@ -143,7 +143,7 @@ func Test_Process_CmdLine(t *testing.T) {
}
}
func Test_Process_CmdLineSlice(t *testing.T) {
func TestCmdLineSlice(t *testing.T) {
p := testGetProcess()
v, err := p.CmdlineSlice()
@ -156,7 +156,7 @@ func Test_Process_CmdLineSlice(t *testing.T) {
}
}
func Test_Process_Ppid(t *testing.T) {
func TestPpid(t *testing.T) {
p := testGetProcess()
v, err := p.Ppid()
@ -173,7 +173,7 @@ func Test_Process_Ppid(t *testing.T) {
}
}
func Test_Process_Status(t *testing.T) {
func TestStatus(t *testing.T) {
p := testGetProcess()
v, err := p.Status()
@ -189,7 +189,7 @@ func Test_Process_Status(t *testing.T) {
}
}
func Test_Process_Terminal(t *testing.T) {
func TestTerminal(t *testing.T) {
p := testGetProcess()
_, err := p.Terminal()
@ -199,7 +199,7 @@ func Test_Process_Terminal(t *testing.T) {
}
}
func Test_Process_IOCounters(t *testing.T) {
func TestIOCounters(t *testing.T) {
p := testGetProcess()
v, err := p.IOCounters()
@ -214,7 +214,7 @@ func Test_Process_IOCounters(t *testing.T) {
}
}
func Test_Process_NumCtx(t *testing.T) {
func TestNumCtx(t *testing.T) {
p := testGetProcess()
_, err := p.NumCtxSwitches()
@ -225,7 +225,7 @@ func Test_Process_NumCtx(t *testing.T) {
}
}
func Test_Process_Nice(t *testing.T) {
func TestNice(t *testing.T) {
p := testGetProcess()
// https://github.com/shirou/gopsutil/issues/1532
@ -243,7 +243,7 @@ func Test_Process_Nice(t *testing.T) {
}
}
func Test_Process_Groups(t *testing.T) {
func TestGroups(t *testing.T) {
p := testGetProcess()
v, err := p.Groups()
@ -259,7 +259,7 @@ func Test_Process_Groups(t *testing.T) {
}
}
func Test_Process_NumThread(t *testing.T) {
func TestNumThread(t *testing.T) {
p := testGetProcess()
n, err := p.NumThreads()
@ -272,7 +272,7 @@ func Test_Process_NumThread(t *testing.T) {
}
}
func Test_Process_Threads(t *testing.T) {
func TestThreads(t *testing.T) {
p := testGetProcess()
n, err := p.NumThreads()
@ -294,7 +294,7 @@ func Test_Process_Threads(t *testing.T) {
}
}
func Test_Process_Name(t *testing.T) {
func TestName(t *testing.T) {
p := testGetProcess()
n, err := p.Name()
@ -307,7 +307,7 @@ func Test_Process_Name(t *testing.T) {
}
}
func Test_Process_Long_Name_With_Spaces(t *testing.T) {
func TestLong_Name_With_Spaces(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
@ -353,7 +353,7 @@ func Test_Process_Long_Name_With_Spaces(t *testing.T) {
cmd.Process.Kill()
}
func Test_Process_Long_Name(t *testing.T) {
func TestLong_Name(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
@ -399,7 +399,7 @@ func Test_Process_Long_Name(t *testing.T) {
cmd.Process.Kill()
}
func Test_Process_Name_Against_Python(t *testing.T) {
func TestName_Against_Python(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("only applies to posix")
}
@ -455,7 +455,7 @@ func Test_Process_Name_Against_Python(t *testing.T) {
}
}
func Test_Process_Exe(t *testing.T) {
func TestExe(t *testing.T) {
p := testGetProcess()
n, err := p.Exe()
@ -468,7 +468,7 @@ func Test_Process_Exe(t *testing.T) {
}
}
func Test_Process_CpuPercent(t *testing.T) {
func TestCpuPercent(t *testing.T) {
p := testGetProcess()
_, err := p.Percent(0)
skipIfNotImplementedErr(t, err)
@ -489,7 +489,7 @@ func Test_Process_CpuPercent(t *testing.T) {
}
}
func Test_Process_CpuPercentLoop(t *testing.T) {
func TestCpuPercentLoop(t *testing.T) {
p := testGetProcess()
numcpu := runtime.NumCPU()
@ -507,7 +507,7 @@ func Test_Process_CpuPercentLoop(t *testing.T) {
}
}
func Test_Process_CreateTime(t *testing.T) {
func TestCreateTime(t *testing.T) {
if os.Getenv("CI") == "true" {
t.Skip("Skip CI")
}
@ -532,7 +532,7 @@ func Test_Process_CreateTime(t *testing.T) {
}
}
func Test_Parent(t *testing.T) {
func TestParent(t *testing.T) {
p := testGetProcess()
c, err := p.Parent()
@ -548,7 +548,7 @@ func Test_Parent(t *testing.T) {
}
}
func Test_Connections(t *testing.T) {
func TestConnections(t *testing.T) {
p := testGetProcess()
addr, err := net.ResolveTCPAddr("tcp", "localhost:0") // dynamically get a random open port from OS
@ -631,7 +631,7 @@ func Test_Connections(t *testing.T) {
}
}
func Test_Children(t *testing.T) {
func TestChildren(t *testing.T) {
p := testGetProcess()
var cmd *exec.Cmd
@ -663,7 +663,7 @@ func Test_Children(t *testing.T) {
}
}
func Test_Username(t *testing.T) {
func TestUsername(t *testing.T) {
myPid := os.Getpid()
currentUser, _ := user.Current()
myUsername := currentUser.Username
@ -676,7 +676,7 @@ func Test_Username(t *testing.T) {
t.Log(pidUsername)
}
func Test_CPUTimes(t *testing.T) {
func TestCPUTimes(t *testing.T) {
pid := os.Getpid()
process, err := NewProcess(int32(pid))
skipIfNotImplementedErr(t, err)
@ -708,7 +708,7 @@ func Test_CPUTimes(t *testing.T) {
assert.True(t, measuredElapsed < float64(spinSeconds)*5, message)
}
func Test_OpenFiles(t *testing.T) {
func TestOpenFiles(t *testing.T) {
fp, err := os.Open("process_test.go")
assert.Nil(t, err)
defer func() {
@ -731,7 +731,7 @@ func Test_OpenFiles(t *testing.T) {
}
}
func Test_Kill(t *testing.T) {
func TestKill(t *testing.T) {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("ping", "localhost", "-n", "4")
@ -749,7 +749,7 @@ func Test_Kill(t *testing.T) {
cmd.Wait()
}
func Test_IsRunning(t *testing.T) {
func TestIsRunning(t *testing.T) {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("ping", "localhost", "-n", "2")
@ -779,7 +779,7 @@ func Test_IsRunning(t *testing.T) {
}
}
func Test_Process_Environ(t *testing.T) {
func TestEnviron(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("unable to create temp dir %v", err)
@ -833,7 +833,7 @@ func Test_Process_Environ(t *testing.T) {
}
}
func Test_Process_Cwd(t *testing.T) {
func TestCwd(t *testing.T) {
myPid := os.Getpid()
currentWorkingDirectory, _ := os.Getwd()

Loading…
Cancel
Save