proc_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package procutils
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func Test_parseProcCmdline(t *testing.T) {
  20. tests := []struct {
  21. name string
  22. content []byte
  23. want []string
  24. }{
  25. {
  26. name: "",
  27. content: []byte{0x2f, 0x75, 0x73, 0x72, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x70, 0x79, 0x74, 0x68, 0x6f, 0x6e, 0x0, 0x2f, 0x75, 0x73, 0x72, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x65, 0x2d, 0x67, 0x6e, 0x6f, 0x6d, 0x65, 0x2d, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x0, 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x65, 0x2d, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x2f, 0x2f, 0x67, 0x70, 0x68, 0x68, 0x61, 0x70, 0x6d, 0x65, 0x6a, 0x6f, 0x62, 0x69, 0x6a, 0x62, 0x62, 0x68, 0x67, 0x70, 0x6a, 0x68, 0x63, 0x6a, 0x6f, 0x67, 0x6e, 0x6c, 0x61, 0x68, 0x62, 0x6c, 0x65, 0x70, 0x2f, 0x0},
  28. want: []string{
  29. "/usr/bin/python",
  30. "/usr/bin/chrome-gnome-shell",
  31. "chrome-extension://gphhapmejobijbbhgpjhcjognlahblep/",
  32. },
  33. },
  34. }
  35. for _, tt := range tests {
  36. t.Run(tt.name, func(t *testing.T) {
  37. if got := parseProcCmdline(tt.content); !reflect.DeepEqual(got, tt.want) {
  38. t.Errorf("parseProcCmdline() = %v, want %v", got, tt.want)
  39. }
  40. })
  41. }
  42. }