From d982225a540a89c60a8708eec3a0631bc24be43f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 28 May 2018 15:40:28 +0100 Subject: [PATCH] restructure test --- function_test.go | 50 ++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/function_test.go b/function_test.go index d2c828e5..f2e83733 100644 --- a/function_test.go +++ b/function_test.go @@ -15,8 +15,8 @@ func TestFunction(t *testing.T) { // create service fn := NewFunction( - Name("test.function"), Registry(mock.NewRegistry()), + Name("test.function"), AfterStart(func() error { wg.Done() return nil @@ -26,31 +26,35 @@ func TestFunction(t *testing.T) { // we can't test fn.Init as it parses the command line // fn.Init() + ch := make(chan error, 2) + go func() { - // wait for start - wg.Wait() - - // test call debug - req := fn.Client().NewRequest( - "test.function", - "Debug.Health", - new(proto.HealthRequest), - ) - - rsp := new(proto.HealthResponse) - - err := fn.Client().Call(context.TODO(), req, rsp) - if err != nil { - t.Fatal(err) - } - - if rsp.Status != "ok" { - t.Fatalf("function response: %s", rsp.Status) - } + // run service + ch <- fn.Run() }() - // run service - if err := fn.Run(); err != nil { + // wait for start + wg.Wait() + + // test call debug + req := fn.Client().NewRequest( + "test.function", + "Debug.Health", + new(proto.HealthRequest), + ) + + rsp := new(proto.HealthResponse) + + err := fn.Client().Call(context.TODO(), req, rsp) + if err != nil { + t.Fatal(err) + } + + if rsp.Status != "ok" { + t.Fatalf("function response: %s", rsp.Status) + } + + if err := <-ch; err != nil { t.Fatal(err) } }