You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
855 B

  1. package process
  2. import (
  3. "os/exec"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestManager_Add(t *testing.T) {
  8. pm := Manager{Processes: make(map[int64]*Process)}
  9. pid := pm.Add("foo", exec.Command("foo"))
  10. assert.Equal(t, int64(1), pid, "expected to get pid 1 got %d", pid)
  11. pid = pm.Add("bar", exec.Command("bar"))
  12. assert.Equal(t, int64(2), pid, "expected to get pid 2 got %d", pid)
  13. }
  14. func TestManager_Remove(t *testing.T) {
  15. pm := Manager{Processes: make(map[int64]*Process)}
  16. pid1 := pm.Add("foo", exec.Command("foo"))
  17. assert.Equal(t, int64(1), pid1, "expected to get pid 1 got %d", pid1)
  18. pid2 := pm.Add("bar", exec.Command("bar"))
  19. assert.Equal(t, int64(2), pid2, "expected to get pid 2 got %d", pid2)
  20. pm.Remove(pid2)
  21. _, exists := pm.Processes[pid2]
  22. assert.False(t, exists, "PID %d is in the list but shouldn't", pid2)
  23. }