restructure test

This commit is contained in:
Asim Aslam 2018-05-28 15:40:28 +01:00
parent 070cebd605
commit d982225a54

View File

@ -15,8 +15,8 @@ func TestFunction(t *testing.T) {
// create service // create service
fn := NewFunction( fn := NewFunction(
Name("test.function"),
Registry(mock.NewRegistry()), Registry(mock.NewRegistry()),
Name("test.function"),
AfterStart(func() error { AfterStart(func() error {
wg.Done() wg.Done()
return nil return nil
@ -26,31 +26,35 @@ func TestFunction(t *testing.T) {
// we can't test fn.Init as it parses the command line // we can't test fn.Init as it parses the command line
// fn.Init() // fn.Init()
ch := make(chan error, 2)
go func() { go func() {
// wait for start // run service
wg.Wait() ch <- fn.Run()
// 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 // wait for start
if err := fn.Run(); err != nil { 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) t.Fatal(err)
} }
} }