summaryrefslogtreecommitdiffstats
path: root/modules/process/manager_test.go
diff options
context:
space:
mode:
authorMatthias Loibl <mail@matthiasloibl.com>2017-01-17 06:58:58 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-17 13:58:58 +0800
commitd1006150fb3a82a8dd6e418578dc44474191bfd0 (patch)
tree99d13e24a1be0d118686106c1f6bbbe4dbaf6793 /modules/process/manager_test.go
parent6dd096b7f08799ff27d9e34356fb1163ca10f388 (diff)
downloadgitea-d1006150fb3a82a8dd6e418578dc44474191bfd0.tar.gz
gitea-d1006150fb3a82a8dd6e418578dc44474191bfd0.zip
Refactor process package and introduce ProcessManager{} with tests (#75)
* Add a process.Manager singleton with process.GetManager() * Use process.GetManager everywhere * Fix godoc comments for process module * Increment process counter id after locking the mutex
Diffstat (limited to 'modules/process/manager_test.go')
-rw-r--r--modules/process/manager_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/process/manager_test.go b/modules/process/manager_test.go
new file mode 100644
index 0000000000..e638264ce1
--- /dev/null
+++ b/modules/process/manager_test.go
@@ -0,0 +1,33 @@
+package process
+
+import (
+ "os/exec"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestManager_Add(t *testing.T) {
+ pm := Manager{Processes: make(map[int64]*Process)}
+
+ pid := pm.Add("foo", exec.Command("foo"))
+ assert.Equal(t, int64(1), pid, "expected to get pid 1 got %d", pid)
+
+ pid = pm.Add("bar", exec.Command("bar"))
+ assert.Equal(t, int64(2), pid, "expected to get pid 2 got %d", pid)
+}
+
+func TestManager_Remove(t *testing.T) {
+ pm := Manager{Processes: make(map[int64]*Process)}
+
+ pid1 := pm.Add("foo", exec.Command("foo"))
+ assert.Equal(t, int64(1), pid1, "expected to get pid 1 got %d", pid1)
+
+ pid2 := pm.Add("bar", exec.Command("bar"))
+ assert.Equal(t, int64(2), pid2, "expected to get pid 2 got %d", pid2)
+
+ pm.Remove(pid2)
+
+ _, exists := pm.Processes[pid2]
+ assert.False(t, exists, "PID %d is in the list but shouldn't", pid2)
+}