1 Star 0 Fork 0

github__fork/go-micro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
function_test.go 1018 Bytes
一键复制 编辑 原始数据 按行查看 历史
Asim Aslam 提交于 2021-01-20 13:54 . v3 (#2104)
package micro
import (
"context"
"sync"
"testing"
proto "github.com/asim/go-micro/v3/debug/proto"
"github.com/asim/go-micro/v3/registry"
"github.com/asim/go-micro/v3/util/test"
)
func TestFunction(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
r := registry.NewMemoryRegistry(registry.Services(test.Data))
// create service
fn := NewFunction(
Registry(r),
Name("test.function"),
AfterStart(func() error {
wg.Done()
return nil
}),
)
// we can't test fn.Init as it parses the command line
// fn.Init()
ch := make(chan error, 2)
go func() {
// run service
ch <- fn.Run()
}()
// 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)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/github__fork/go-micro.git
git@gitee.com:github__fork/go-micro.git
github__fork
go-micro
go-micro
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385