代码拉取完成,页面将自动刷新
同步操作将从 傲笑红尘/Kratos 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package kratos
import (
"context"
"log"
"net/url"
"os"
"reflect"
"testing"
"time"
xlog "github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
"github.com/go-kratos/kratos/v2/transport"
)
func TestID(t *testing.T) {
o := &options{}
v := "123"
ID(v)(o)
if !reflect.DeepEqual(v, o.id) {
t.Fatalf("o.id:%s is not equal to v:%s", o.id, v)
}
}
func TestName(t *testing.T) {
o := &options{}
v := "abc"
Name(v)(o)
if !reflect.DeepEqual(v, o.name) {
t.Fatalf("o.name:%s is not equal to v:%s", o.name, v)
}
}
func TestVersion(t *testing.T) {
o := &options{}
v := "123"
Version(v)(o)
if !reflect.DeepEqual(v, o.version) {
t.Fatalf("o.version:%s is not equal to v:%s", o.version, v)
}
}
func TestMetadata(t *testing.T) {
o := &options{}
v := map[string]string{
"a": "1",
"b": "2",
}
Metadata(v)(o)
if !reflect.DeepEqual(v, o.metadata) {
t.Fatalf("o.metadata:%s is not equal to v:%s", o.metadata, v)
}
}
func TestEndpoint(t *testing.T) {
o := &options{}
v := []*url.URL{
{Host: "example.com"},
{Host: "foo.com"},
}
Endpoint(v...)(o)
if !reflect.DeepEqual(v, o.endpoints) {
t.Fatalf("o.endpoints:%s is not equal to v:%s", o.endpoints, v)
}
}
func TestContext(t *testing.T) {
type ctxKey = struct{}
o := &options{}
v := context.WithValue(context.TODO(), ctxKey{}, "b")
Context(v)(o)
if !reflect.DeepEqual(v, o.ctx) {
t.Fatalf("o.ctx:%s is not equal to v:%s", o.ctx, v)
}
}
func TestLogger(t *testing.T) {
o := &options{}
v := xlog.NewStdLogger(log.Writer())
Logger(v)(o)
if !reflect.DeepEqual(v, o.logger) {
t.Fatalf("o.logger:%v is not equal to xlog.NewHelper(v):%v", o.logger, xlog.NewHelper(v))
}
}
type mockServer struct{}
func (m *mockServer) Start(ctx context.Context) error { return nil }
func (m *mockServer) Stop(ctx context.Context) error { return nil }
func TestServer(t *testing.T) {
o := &options{}
v := []transport.Server{
&mockServer{}, &mockServer{},
}
Server(v...)(o)
if !reflect.DeepEqual(v, o.servers) {
t.Fatalf("o.servers:%s is not equal to xlog.NewHelper(v):%s", o.servers, v)
}
}
type mockSignal struct{}
func (m *mockSignal) String() string { return "sig" }
func (m *mockSignal) Signal() {}
func TestSignal(t *testing.T) {
o := &options{}
v := []os.Signal{
&mockSignal{}, &mockSignal{},
}
Signal(v...)(o)
if !reflect.DeepEqual(v, o.sigs) {
t.Fatal("o.sigs is not equal to v")
}
}
type mockRegistrar struct{}
func (m *mockRegistrar) Register(ctx context.Context, service *registry.ServiceInstance) error {
return nil
}
func (m *mockRegistrar) Deregister(ctx context.Context, service *registry.ServiceInstance) error {
return nil
}
func TestRegistrar(t *testing.T) {
o := &options{}
v := &mockRegistrar{}
Registrar(v)(o)
if !reflect.DeepEqual(v, o.registrar) {
t.Fatal("o.registrar is not equal to v")
}
}
func TestRegistrarTimeout(t *testing.T) {
o := &options{}
v := time.Duration(123)
RegistrarTimeout(v)(o)
if !reflect.DeepEqual(v, o.registrarTimeout) {
t.Fatal("o.registrarTimeout is not equal to v")
}
}
func TestStopTimeout(t *testing.T) {
o := &options{}
v := time.Duration(123)
StopTimeout(v)(o)
if !reflect.DeepEqual(v, o.stopTimeout) {
t.Fatal("o.stopTimeout is not equal to v")
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。