Browse Source

test service directory creation

tags/v0.7.2
AJ ONeal 5 months ago
parent
commit
2824ee4c62
2 changed files with 39 additions and 1 deletions
  1. 7
    1
      manager/start.go
  2. 32
    0
      manager/start_stop_test.go

+ 7
- 1
manager/start.go View File

@@ -3,6 +3,7 @@ package manager
3 3
 import (
4 4
 	"fmt"
5 5
 	"io/ioutil"
6
+	"os"
6 7
 	"os/exec"
7 8
 	"path/filepath"
8 9
 	"strings"
@@ -121,7 +122,12 @@ func getSystemSrvs() ([]string, error) {
121 122
 }
122 123
 
123 124
 func getUserSrvs(home string) ([]string, error) {
124
-	return getSrvs(filepath.Join(home, srvUserPath))
125
+	confDir := filepath.Join(home, srvUserPath)
126
+	err := os.MkdirAll(confDir, 0755)
127
+	if nil != err {
128
+		return nil, err
129
+	}
130
+	return getSrvs(confDir)
125 131
 }
126 132
 
127 133
 // "come.example.foo.plist" matches "foo"

+ 32
- 0
manager/start_stop_test.go View File

@@ -0,0 +1,32 @@
1
+package manager
2
+
3
+import (
4
+	"fmt"
5
+	"io/ioutil"
6
+	"os"
7
+	"path/filepath"
8
+	"testing"
9
+)
10
+
11
+func TestEmptyUserServicePath(t *testing.T) {
12
+	srvs, err := getUserSrvs("/tmp/fakeuser")
13
+	if nil != err {
14
+		t.Fatal(err)
15
+	}
16
+	if len(srvs) > 0 {
17
+		t.Fatal(fmt.Errorf("sanity fail: shouldn't get services from empty directory"))
18
+	}
19
+
20
+	dirs, err := ioutil.ReadDir(filepath.Join("/tmp/fakeuser", srvUserPath))
21
+	if nil != err {
22
+		t.Fatal(err)
23
+	}
24
+	if len(dirs) > 0 {
25
+		t.Fatal(fmt.Errorf("sanity fail: shouldn't get listing from empty directory"))
26
+	}
27
+
28
+	err = os.RemoveAll("/tmp/fakeuser")
29
+	if nil != err {
30
+		panic("couldn't remove /tmp/fakeuser")
31
+	}
32
+}

Loading…
Cancel
Save