add more cover stuff #127

Merged
vtolstov merged 1 commits from cover into v3 2022-05-03 00:26:13 +03:00
13 changed files with 101 additions and 106 deletions

View File

@ -9,7 +9,7 @@ import (
)
// DefaultBroker default memory broker
var DefaultBroker Broker = NewBroker()
var DefaultBroker = NewBroker()
var (
// ErrNotConnected returns when broker used but not connected yet

View File

@ -34,7 +34,6 @@ func TestSetOption(t *testing.T) {
}
}
func TestSetSaveOption(t *testing.T) {
type key struct{}
o := SetSaveOption(key{}, "test")
@ -46,8 +45,6 @@ func TestSetSaveOption(t *testing.T) {
}
}
func TestSetLoadOption(t *testing.T) {
type key struct{}
o := SetLoadOption(key{}, "test")
@ -59,8 +56,6 @@ func TestSetLoadOption(t *testing.T) {
}
}
func TestSetWatchOption(t *testing.T) {
type key struct{}
o := SetWatchOption(key{}, "test")

View File

@ -97,7 +97,6 @@ func TestErrors(t *testing.T) {
}
}
func TestCodeIn(t *testing.T) {
err := InternalServerError("id", "%s", "msg")

View File

@ -70,7 +70,7 @@ func HookAfter(fns ...HookAfterFunc) Option {
}
// StateFunc called on state transition and return next step and error
type StateFunc func(ctx context.Context, args interface{}, opts...StateOption) (string, interface{}, error)
type StateFunc func(ctx context.Context, args interface{}, opts ...StateOption) (string, interface{}, error)
// FSM is a finite state machine
type FSM struct {

View File

@ -41,7 +41,6 @@ func TestFromOutgoingContext(t *testing.T) {
}
}
func TestSetIncomingContext(t *testing.T) {
md := New(1)
md.Set("key", "val")
@ -72,7 +71,6 @@ func TestSetOutgoingContext(t *testing.T) {
}
}
func TestNewIncomingContext(t *testing.T) {
md := New(1)
md.Set("key", "val")
@ -95,17 +93,16 @@ func TestNewOutgoingContext(t *testing.T) {
}
}
func TestAppendIncomingContext(t *testing.T) {
md := New(1)
md.Set("key1", "val1")
ctx := AppendIncomingContext(context.TODO(), "key2","val2")
ctx := AppendIncomingContext(context.TODO(), "key2", "val2")
nmd, ok := FromIncomingContext(ctx)
if nmd == nil || !ok {
t.Fatal("AppendIncomingContext not works")
}
if v, ok := nmd.Get("key2"); !ok || v != "val2"{
if v, ok := nmd.Get("key2"); !ok || v != "val2" {
t.Fatal("AppendIncomingContext not works")
}
}
@ -113,13 +110,13 @@ func TestAppendIncomingContext(t *testing.T) {
func TestAppendOutgoingContext(t *testing.T) {
md := New(1)
md.Set("key1", "val1")
ctx := AppendOutgoingContext(context.TODO(), "key2","val2")
ctx := AppendOutgoingContext(context.TODO(), "key2", "val2")
nmd, ok := FromOutgoingContext(ctx)
if nmd == nil || !ok {
t.Fatal("AppendOutgoingContext not works")
}
if v, ok := nmd.Get("key2"); !ok || v != "val2"{
if v, ok := nmd.Get("key2"); !ok || v != "val2" {
t.Fatal("AppendOutgoingContext not works")
}
}

View File

@ -33,4 +33,3 @@ func TestSetOption(t *testing.T) {
t.Fatal("SetOption not works")
}
}

View File

@ -33,4 +33,3 @@ func TestSetOption(t *testing.T) {
t.Fatal("SetOption not works")
}
}

View File

@ -33,4 +33,3 @@ func TestSetOption(t *testing.T) {
t.Fatal("SetOption not works")
}
}

View File

@ -8,9 +8,9 @@ import (
"go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/codec"
"go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/metadata"
"go.unistack.org/micro/v3/server"
"go.unistack.org/micro/v3/logger"
)
type TestHandler struct {

View File

@ -58,6 +58,8 @@ type Service interface {
Run() error
// Start the service
Start() error
// Stop the service
Stop() error
// The service implementation
String() string
}

View File

@ -1,8 +1,8 @@
package micro
import (
"reflect"
"context"
"reflect"
"testing"
"go.unistack.org/micro/v3/auth"
@ -101,7 +101,6 @@ func TestRegisterSubscriber(t *testing.T) {
}
}
func TestNewService(t *testing.T) {
type args struct {
opts []Option
@ -113,7 +112,7 @@ func TestNewService(t *testing.T) {
}{
{
name: "NewService",
args: args {
args: args{
opts: []Option{Name("test")},
},
want: NewService(Name("test")),
@ -128,7 +127,6 @@ func TestNewService(t *testing.T) {
}
}
func Test_service_Name(t *testing.T) {
type fields struct {
opts Options
@ -140,7 +138,7 @@ func Test_service_Name(t *testing.T) {
}{
{
name: "Test_service_Name",
fields: fields {
fields: fields{
opts: Options{Name: "test"},
},
want: "test",
@ -158,7 +156,6 @@ func Test_service_Name(t *testing.T) {
}
}
func Test_service_Init(t *testing.T) {
type fields struct {
opts Options
@ -178,7 +175,7 @@ func Test_service_Init(t *testing.T) {
opts: Options{},
},
args: args{
opts: []Option{},
opts: []Option{},
},
wantErr: false,
},
@ -195,9 +192,8 @@ opts: []Option{},
}
}
func Test_service_Options(t *testing.T) {
opts := Options{Name:"test"}
opts := Options{Name: "test"}
type fields struct {
opts Options
}
@ -208,8 +204,8 @@ func Test_service_Options(t *testing.T) {
}{
{
name: "service.Options",
fields:fields{
opts: opts,
fields: fields{
opts: opts,
},
want: opts,
},
@ -226,7 +222,6 @@ opts: opts,
}
}
func Test_service_Broker(t *testing.T) {
b := broker.NewBroker()
type fields struct {
@ -242,7 +237,7 @@ func Test_service_Broker(t *testing.T) {
want broker.Broker
}{
{
name:"service.Broker",
name: "service.Broker",
fields: fields{
opts: Options{Brokers: []broker.Broker{b}},
},
@ -264,6 +259,24 @@ func Test_service_Broker(t *testing.T) {
}
}
/*
func TestServiceBroker(t *testing.T) {
b := broker.NewBroker(broker.Name("test"))
srv := server.NewServer()
svc := NewService(Server(srv),Broker(b))
if err := svc.Init(); err != nil {
t.Fatalf("failed to init service")
}
if brk := svc.Server().Options().Broker; brk.Name() != "test" {
t.Fatalf("server broker not set: %v", svc.Server().Options().Broker)
}
}
*/
func Test_service_Tracer(t *testing.T) {
tr := tracer.NewTracer()
@ -280,7 +293,7 @@ func Test_service_Tracer(t *testing.T) {
want tracer.Tracer
}{
{
name:"service.Tracer",
name: "service.Tracer",
fields: fields{
opts: Options{Tracers: []tracer.Tracer{tr}},
},
@ -317,7 +330,7 @@ func Test_service_Config(t *testing.T) {
want config.Config
}{
{
name:"service.Config",
name: "service.Config",
fields: fields{
opts: Options{Configs: []config.Config{c}},
},
@ -339,7 +352,6 @@ func Test_service_Config(t *testing.T) {
}
}
func Test_service_Client(t *testing.T) {
c := client.NewClient()
type fields struct {
@ -355,7 +367,7 @@ func Test_service_Client(t *testing.T) {
want client.Client
}{
{
name:"service.Client",
name: "service.Client",
fields: fields{
opts: Options{Clients: []client.Client{c}},
},
@ -377,7 +389,6 @@ func Test_service_Client(t *testing.T) {
}
}
func Test_service_Server(t *testing.T) {
s := server.NewServer()
type fields struct {
@ -393,7 +404,7 @@ func Test_service_Server(t *testing.T) {
want server.Server
}{
{
name:"service.Server",
name: "service.Server",
fields: fields{
opts: Options{Servers: []server.Server{s}},
},
@ -415,7 +426,6 @@ func Test_service_Server(t *testing.T) {
}
}
func Test_service_Store(t *testing.T) {
s := store.NewStore()
type fields struct {
@ -431,7 +441,7 @@ func Test_service_Store(t *testing.T) {
want store.Store
}{
{
name:"service.Store",
name: "service.Store",
fields: fields{
opts: Options{Stores: []store.Store{s}},
},
@ -453,7 +463,6 @@ func Test_service_Store(t *testing.T) {
}
}
func Test_service_Register(t *testing.T) {
r := register.NewRegister()
type fields struct {
@ -469,7 +478,7 @@ func Test_service_Register(t *testing.T) {
want register.Register
}{
{
name:"service.Register",
name: "service.Register",
fields: fields{
opts: Options{Registers: []register.Register{r}},
},
@ -506,7 +515,7 @@ func Test_service_Logger(t *testing.T) {
want logger.Logger
}{
{
name:"service.Logger",
name: "service.Logger",
fields: fields{
opts: Options{Loggers: []logger.Logger{l}},
},
@ -528,7 +537,6 @@ func Test_service_Logger(t *testing.T) {
}
}
func Test_service_Auth(t *testing.T) {
a := auth.NewAuth()
type fields struct {
@ -544,7 +552,7 @@ func Test_service_Auth(t *testing.T) {
want auth.Auth
}{
{
name:"service.Auth",
name: "service.Auth",
fields: fields{
opts: Options{Auths: []auth.Auth{a}},
},
@ -581,7 +589,7 @@ func Test_service_Router(t *testing.T) {
want router.Router
}{
{
name:"service.Router",
name: "service.Router",
fields: fields{
opts: Options{Routers: []router.Router{r}},
},
@ -618,7 +626,7 @@ func Test_service_Meter(t *testing.T) {
want meter.Meter
}{
{
name:"service.Meter",
name: "service.Meter",
fields: fields{
opts: Options{Meters: []meter.Meter{m}},
},
@ -640,7 +648,6 @@ func Test_service_Meter(t *testing.T) {
}
}
func Test_service_String(t *testing.T) {
type fields struct {
opts Options
@ -651,7 +658,7 @@ func Test_service_String(t *testing.T) {
want string
}{
{
name:"service.String",
name: "service.String",
fields: fields{
opts: Options{Name: "noop"},
},

View File

@ -33,4 +33,3 @@ func TestSetOption(t *testing.T) {
t.Fatal("SetOption not works")
}
}

View File

@ -6,7 +6,7 @@ import (
)
func TestFromContext(t *testing.T) {
ctx := context.WithValue(context.TODO(),tracerKey{}, NewTracer())
ctx := context.WithValue(context.TODO(), tracerKey{}, NewTracer())
c, ok := FromContext(ctx)
if c == nil || !ok {
@ -22,4 +22,3 @@ func TestNewContext(t *testing.T) {
t.Fatal("NewContext not works")
}
}