The public tree and its history contain only the listed paths. Earlier projection history remains preserved internally. Source-Sha: 913fde029b935671833254797f0f20f1eb9fabba Policy-Sha: 913fde029b935671833254797f0f20f1eb9fabba Tree-Digest: 180ae530c1058a2a5c89837bdce2d323ae83e669e38590ca72e75b8d92b7262f
39 lines
889 B
Go
39 lines
889 B
Go
package system
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetTopProcesses(t *testing.T) {
|
|
procs, err := GetTopProcesses(5)
|
|
if err != nil {
|
|
t.Fatalf("GetTopProcesses(5) error: %v", err)
|
|
}
|
|
if len(procs) == 0 {
|
|
t.Fatal("expected at least one process")
|
|
}
|
|
|
|
t.Logf("Top %d processes (on %s):", len(procs), runtime.GOOS)
|
|
for i, p := range procs {
|
|
t.Logf(" %d. %s (pid=%d) cpu=%.1f%% mem=%.1f%%", i+1, p.Name, p.PID, p.CPU, p.Mem)
|
|
if p.Name == "" {
|
|
t.Errorf("process %d has empty name", p.PID)
|
|
}
|
|
if p.PID == 0 {
|
|
t.Error("process has zero PID")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetTopProcessesLimit(t *testing.T) {
|
|
for _, limit := range []int{1, 3, 10} {
|
|
procs, err := GetTopProcesses(limit)
|
|
if err != nil {
|
|
t.Fatalf("GetTopProcesses(%d) error: %v", limit, err)
|
|
}
|
|
if len(procs) > limit {
|
|
t.Errorf("GetTopProcesses(%d) returned %d processes", limit, len(procs))
|
|
}
|
|
}
|
|
}
|