Merge pull request #127 from unistack-org/cover

add more cover stuff
This commit is contained in:
Василий Толстов 2022-05-03 00:26:13 +03:00 committed by GitHub
commit 289aadb28e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 101 additions and 106 deletions

View File

@ -9,7 +9,7 @@ import (
) )
// DefaultBroker default memory broker // DefaultBroker default memory broker
var DefaultBroker Broker = NewBroker() var DefaultBroker = NewBroker()
var ( var (
// ErrNotConnected returns when broker used but not connected yet // 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) { func TestSetSaveOption(t *testing.T) {
type key struct{} type key struct{}
o := SetSaveOption(key{}, "test") o := SetSaveOption(key{}, "test")
@ -46,8 +45,6 @@ func TestSetSaveOption(t *testing.T) {
} }
} }
func TestSetLoadOption(t *testing.T) { func TestSetLoadOption(t *testing.T) {
type key struct{} type key struct{}
o := SetLoadOption(key{}, "test") o := SetLoadOption(key{}, "test")
@ -59,8 +56,6 @@ func TestSetLoadOption(t *testing.T) {
} }
} }
func TestSetWatchOption(t *testing.T) { func TestSetWatchOption(t *testing.T) {
type key struct{} type key struct{}
o := SetWatchOption(key{}, "test") o := SetWatchOption(key{}, "test")

View File

@ -97,7 +97,6 @@ func TestErrors(t *testing.T) {
} }
} }
func TestCodeIn(t *testing.T) { func TestCodeIn(t *testing.T) {
err := InternalServerError("id", "%s", "msg") 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 // 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 // FSM is a finite state machine
type FSM struct { type FSM struct {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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