(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestReadProcessStatus(t *testing.T) { |
| 28 | if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | want := 1 |
| 32 | fs, err := procfs.NewFS(*procPath) |
| 33 | if err != nil { |
| 34 | t.Errorf("failed to open procfs: %v", err) |
| 35 | } |
| 36 | c := processCollector{fs: fs, logger: slog.New(slog.NewTextHandler(io.Discard, nil))} |
| 37 | pids, states, threads, _, err := c.getAllocatedThreads() |
| 38 | if err != nil { |
| 39 | t.Fatalf("Cannot retrieve data from procfs getAllocatedThreads function: %v ", err) |
| 40 | } |
| 41 | if threads < want { |
| 42 | t.Fatalf("Current threads: %d Shouldn't be less than wanted %d", threads, want) |
| 43 | } |
| 44 | if states == nil { |
| 45 | |
| 46 | t.Fatalf("Process states cannot be nil %v:", states) |
| 47 | } |
| 48 | maxPid, err := readUintFromFile(procFilePath("sys/kernel/pid_max")) |
| 49 | if err != nil { |
| 50 | t.Fatalf("Unable to retrieve limit number of maximum pids allowed %v\n", err) |
| 51 | } |
| 52 | if uint64(pids) > maxPid || pids == 0 { |
| 53 | t.Fatalf("Total running pids cannot be greater than %d or equals to 0", maxPid) |
| 54 | } |
| 55 | } |
nothing calls this directly
no test coverage detected