From 0ce0b440604b90d939013daa595ef58951412a72 Mon Sep 17 00:00:00 2001 From: lwch Date: Fri, 9 Dec 2022 10:12:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3windows=E4=B8=8B=E6=9C=AA?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=9C=8D=E5=8A=A1=E6=97=A0=E6=B3=95=E9=87=8D?= =?UTF-8?q?=E5=90=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.go | 7 +++++++ agent_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 agent_test.go diff --git a/agent.go b/agent.go index f901478..242abe9 100644 --- a/agent.go +++ b/agent.go @@ -107,5 +107,12 @@ func Restart(app App) error { if err != nil { return err } + status, err := svc.Status() + if err != nil { + return err + } + if status == service.StatusStopped { + return svc.Start() + } return svc.Restart() } diff --git a/agent_test.go b/agent_test.go new file mode 100644 index 0000000..d827b70 --- /dev/null +++ b/agent_test.go @@ -0,0 +1,52 @@ +package agent + +import ( + "context" + "testing" + + "github.com/jkstack/anet" + "github.com/jkstack/libagent/conf" +) + +type agent struct{} + +func (a *agent) AgentName() string { + return "example-agent" +} + +func (a *agent) Version() string { + return "0.0.0" +} + +func (a *agent) ConfDir() string { + return "./conf" +} + +func (a *agent) Configure() *conf.Configure { + return &conf.Configure{} +} + +func (a *agent) OnRewriteConfigure() error { + return nil +} + +func (a *agent) OnConnect() { +} + +func (a *agent) OnDisconnect() { +} + +func (a *agent) OnReportMonitor() { +} + +func (a *agent) OnMessage(*anet.Msg) error { + return nil +} + +func (a *agent) LoopWrite(context.Context, chan *anet.Msg) error { + select {} +} + +func TestRestart(t *testing.T) { + Restart(&agent{}) +}