鏡像自
				https://github.com/therootcompany/serviceman.git
				synced 2025-11-04 06:42:47 +00:00 
			
		
		
		
	test service directory creation
This commit is contained in:
		
							父節點
							
								
									e7a02191d8
								
							
						
					
					
						當前提交
						2824ee4c62
					
				@ -3,6 +3,7 @@ package manager
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
@ -121,7 +122,12 @@ func getSystemSrvs() ([]string, error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getUserSrvs(home string) ([]string, error) {
 | 
			
		||||
	return getSrvs(filepath.Join(home, srvUserPath))
 | 
			
		||||
	confDir := filepath.Join(home, srvUserPath)
 | 
			
		||||
	err := os.MkdirAll(confDir, 0755)
 | 
			
		||||
	if nil != err {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return getSrvs(confDir)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// "come.example.foo.plist" matches "foo"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										32
									
								
								manager/start_stop_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								manager/start_stop_test.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
package manager
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestEmptyUserServicePath(t *testing.T) {
 | 
			
		||||
	srvs, err := getUserSrvs("/tmp/fakeuser")
 | 
			
		||||
	if nil != err {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	if len(srvs) > 0 {
 | 
			
		||||
		t.Fatal(fmt.Errorf("sanity fail: shouldn't get services from empty directory"))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	dirs, err := ioutil.ReadDir(filepath.Join("/tmp/fakeuser", srvUserPath))
 | 
			
		||||
	if nil != err {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	if len(dirs) > 0 {
 | 
			
		||||
		t.Fatal(fmt.Errorf("sanity fail: shouldn't get listing from empty directory"))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = os.RemoveAll("/tmp/fakeuser")
 | 
			
		||||
	if nil != err {
 | 
			
		||||
		panic("couldn't remove /tmp/fakeuser")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		載入中…
	
	
			
			x
			
			
		
	
		新增問題並參考
	
	Block a user