1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00
go-micro/function_test.go

55 lines
869 B
Go
Raw Normal View History

2017-06-01 13:11:52 +02:00
package micro
import (
2018-03-03 13:53:52 +02:00
"context"
2017-06-01 13:11:52 +02:00
"sync"
"testing"
"github.com/micro/go-micro/registry/mock"
proto "github.com/micro/go-micro/server/debug/proto"
)
func TestFunction(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
// create service
fn := NewFunction(
Name("test.function"),
Registry(mock.NewRegistry()),
AfterStart(func() error {
wg.Done()
return nil
}),
)
// we can't test fn.Init as it parses the command line
// fn.Init()
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
fn.Run()
}