github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zutil/daemon/daemon_test.go (about) 1 package daemon 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/sohaha/zlsgo" 8 ) 9 10 type ss struct { 11 I int 12 } 13 14 func (p *ss) Start(s ServiceIface) error { 15 p.run() 16 return nil 17 } 18 19 func (p *ss) run() { 20 fmt.Println("run") 21 p.I = p.I + 1 22 } 23 24 func (p *ss) Stop(s ServiceIface) error { 25 return nil 26 } 27 28 func TestDaemon(t *testing.T) { 29 o := &ss{ 30 I: 1, 31 } 32 s, err := New(o, &Config{ 33 Name: "zlsgo_daemon_test", 34 Options: map[string]interface{}{"UserService": false}, 35 }) 36 if err != nil { 37 return 38 } 39 t.Log(o.I) 40 t.Log(err) 41 _ = s.Install() 42 err = s.Start() 43 t.Log(err) 44 _ = s.Stop() 45 _ = s.Restart() 46 t.Log(s.Status()) 47 _ = s.Uninstall() 48 t.Log(s.String()) 49 t.Log(o.I) 50 } 51 52 func TestUtil(t *testing.T) { 53 tt := zlsgo.NewTest(t) 54 tt.Equal(IsPermissionError(ErrNotAnAdministrator), IsPermissionError(ErrNotAnRootUser)) 55 _ = isSudo() 56 }