pids.bats 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bats
  2. @test "Get process information of one process only (init)" {
  3. pid="1"
  4. run ./bin/gfpsgo -pids "${pid:?}" -format "user,pid,ppid"
  5. [ "${status:-}" -eq 0 ]
  6. [[ ${lines[0]} =~ ^USER\ +PID\ +PPID$ ]]
  7. [[ ${lines[1]} =~ ^root\ +${pid:?}\ +0$ ]]
  8. }
  9. @test "Get process information of a set of running containers" {
  10. nCtrs=5
  11. pidsList=()
  12. ctridList=()
  13. for ((i = 1; i <= nCtrs; i++)); do
  14. ctridList[${i:?}]="$(docker run -d busybox sleep 60)"
  15. pidsList[${i:?}]="$(docker inspect --format '{{.State.Pid}}' "${ctridList[${i:?}]:?}")"
  16. done
  17. pids="$(tr ' ' ',' <<< "${pidsList[@]:?}")"
  18. run ./bin/gfpsgo -pids "${pids:?}" -format "pid,comm"
  19. [ "${status:-}" -eq 0 ]
  20. [[ ${lines[0]} =~ ^PID\ +COMMAND$ ]]
  21. for ((i = 1; i <= nCtrs; i++)); do
  22. [[ ${lines[${i:?}]} =~ ^${pidsList[${i:?}]}\ +sleep$ ]]
  23. docker rm -f "${ctridList[${i:?}]:?}"
  24. done
  25. }
  26. @test "Return error on both --pid and --pids options" {
  27. run ./bin/gfpsgo -pid 1 --pids 1,2,3
  28. [[ ! ${status:-} -eq 0 ]]
  29. }
  30. @test "Process information with --pids vs all processes" {
  31. nCtrs=5
  32. pidsList=()
  33. ctridList=()
  34. for ((i = 1; i <= nCtrs; i++)); do
  35. ctridList[${i:?}]="$(docker run -d busybox sleep 60)"
  36. pidsList[${i:?}]="$(docker inspect --format '{{.State.Pid}}' "${ctridList[${i:?}]:?}")"
  37. done
  38. pids="$(tr ' ' ',' <<< "${pidsList[@]:?}")"
  39. run ./bin/gfpsgo --pids "${pids:?}" -format "user,group,pid,ppid,tty,nice,capeff"
  40. [ "${status:-}" -eq 0 ]
  41. [[ ${lines[0]} =~ ^USER\ +GROUP\ +PID\ +PPID\ +TTY\ +NI\ +EFFECTIVE\ CAPS$ ]]
  42. run ./bin/gfpsgo -format "user,group,pid,ppid,tty,nice,capeff"
  43. [ "${status:-}" -eq 0 ]
  44. [[ ${lines[0]} =~ ^USER\ +GROUP\ +PID\ +PPID\ +TTY\ +NI\ +EFFECTIVE\ CAPS$ ]]
  45. for ((i = 1; i <= nCtrs; i++)); do
  46. docker rm -f "${ctridList[${i:?}]:?}"
  47. done
  48. }