proc_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package proc
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "github.com/stretchr/testify/require"
  5. "inet.af/netaddr"
  6. "testing"
  7. )
  8. func init() {
  9. SetRoot("fixtures")
  10. }
  11. func TestListPids(t *testing.T) {
  12. res, err := ListPids()
  13. require.NoError(t, err)
  14. assert.Equal(t, []uint32{123}, res)
  15. }
  16. func TestGetMountInfo(t *testing.T) {
  17. res := GetMountInfo(123)
  18. assert.Equal(t, map[string]MountInfo{
  19. "3125": {MajorMinor: "259:2", MountPoint: "/dev/termination-log"},
  20. "3126": {MajorMinor: "259:2", MountPoint: "/bitnami/kafka"},
  21. "3127": {MajorMinor: "259:2", MountPoint: "/scripts/setup.sh"},
  22. "3128": {MajorMinor: "259:2", MountPoint: "/etc/resolv.conf"},
  23. "3129": {MajorMinor: "259:2", MountPoint: "/etc/hostname"},
  24. "3130": {MajorMinor: "259:2", MountPoint: "/etc/hosts"},
  25. }, res)
  26. }
  27. func TestGetFdInfo(t *testing.T) {
  28. res := GetFdInfo(123, 4)
  29. assert.Equal(t, FdInfo{
  30. MntId: "1965",
  31. Flags: int(0100002),
  32. Dest: "/var/lib/postgresql/data/pg_wal/000000010000000000000001",
  33. }, *res)
  34. }
  35. func TestGetSockets(t *testing.T) {
  36. res, err := GetSockets(123)
  37. require.NoError(t, err)
  38. ipp := func(s string) netaddr.IPPort {
  39. res, err := netaddr.ParseIPPort(s)
  40. require.NoError(t, err)
  41. return res
  42. }
  43. assert.Equal(t, []Sock{
  44. {Inode: "8039432", SAddr: ipp("0.0.0.0:5432"), DAddr: ipp("0.0.0.0:0"), Listen: true},
  45. {Inode: "8134154", SAddr: ipp("172.17.0.3:5432"), DAddr: ipp("172.17.0.4:36332"), Listen: false},
  46. {Inode: "8039433", SAddr: ipp("[::]:5432"), DAddr: ipp("[::]:0"), Listen: true},
  47. }, res)
  48. }