psgo_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2021 Jeffrey H. Johnson <trnsz@pobox.com>
  2. // Copyright 2018 psgo authors.
  3. // Copyright 2021 Gridfinity, LLC.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. package gfpsgo // import "github.com/johnsonjh/gfpsgo"
  17. import (
  18. "testing"
  19. "github.com/johnsonjh/gfpsgo/internal/proc"
  20. "github.com/johnsonjh/gfpsgo/internal/process"
  21. u "github.com/johnsonjh/leaktestfe"
  22. "github.com/stretchr/testify/assert"
  23. )
  24. func TestProcessARGS(t *testing.T) {
  25. u.Leakplug(t)
  26. p := process.Process{
  27. Status: proc.Status{
  28. Name: "foo-bar",
  29. },
  30. CmdLine: []string{""},
  31. }
  32. ctx := new(psContext)
  33. comm, err := processARGS(&p, ctx)
  34. assert.Nil(t, err)
  35. assert.Equal(t, "[foo-bar]", comm)
  36. p = process.Process{
  37. CmdLine: []string{"/usr/bin/foo-bar -flag1 -flag2"},
  38. }
  39. comm, err = processARGS(&p, ctx)
  40. assert.Nil(t, err)
  41. assert.Equal(t, "/usr/bin/foo-bar -flag1 -flag2", comm)
  42. }
  43. func TestProcessCOMM(t *testing.T) {
  44. u.Leakplug(t)
  45. p := process.Process{
  46. Stat: proc.Stat{
  47. Comm: "foo-bar",
  48. },
  49. CmdLine: []string{""},
  50. }
  51. ctx := new(psContext)
  52. comm, err := processCOMM(&p, ctx)
  53. assert.Nil(t, err)
  54. assert.Equal(t, "foo-bar", comm)
  55. p = process.Process{
  56. Stat: proc.Stat{
  57. Comm: "foo-bar",
  58. },
  59. CmdLine: []string{"/usr/bin/foo-bar"},
  60. }
  61. comm, err = processCOMM(&p, ctx)
  62. assert.Nil(t, err)
  63. assert.Equal(t, "foo-bar", comm)
  64. }