2021-10-07 20:59:27 +03:00
|
|
|
package micro
|
|
|
|
|
|
|
|
import (
|
2022-04-24 11:08:38 +03:00
|
|
|
"context"
|
2022-05-03 00:23:43 +03:00
|
|
|
"reflect"
|
2021-10-07 20:59:27 +03:00
|
|
|
"testing"
|
2022-04-24 11:08:38 +03:00
|
|
|
|
|
|
|
"go.unistack.org/micro/v3/auth"
|
|
|
|
"go.unistack.org/micro/v3/broker"
|
|
|
|
"go.unistack.org/micro/v3/client"
|
|
|
|
"go.unistack.org/micro/v3/config"
|
|
|
|
"go.unistack.org/micro/v3/logger"
|
|
|
|
"go.unistack.org/micro/v3/meter"
|
|
|
|
"go.unistack.org/micro/v3/register"
|
|
|
|
"go.unistack.org/micro/v3/router"
|
|
|
|
"go.unistack.org/micro/v3/server"
|
|
|
|
"go.unistack.org/micro/v3/store"
|
|
|
|
"go.unistack.org/micro/v3/tracer"
|
2021-10-07 20:59:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type testItem struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ti *testItem) Name() string {
|
|
|
|
return ti.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetNameIndex(t *testing.T) {
|
|
|
|
item1 := &testItem{name: "first"}
|
|
|
|
item2 := &testItem{name: "second"}
|
|
|
|
items := []interface{}{item1, item2}
|
|
|
|
if idx := getNameIndex("second", items); idx != 1 {
|
|
|
|
t.Fatalf("getNameIndex func error, item not found")
|
|
|
|
}
|
|
|
|
}
|
2022-04-24 11:08:38 +03:00
|
|
|
|
|
|
|
func TestRegisterHandler(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
s server.Server
|
|
|
|
h interface{}
|
|
|
|
opts []server.HandlerOption
|
|
|
|
}
|
|
|
|
h := struct{}{}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "RegisterHandler",
|
|
|
|
args: args{
|
|
|
|
s: server.DefaultServer,
|
|
|
|
h: h,
|
|
|
|
opts: nil,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if err := RegisterHandler(tt.args.s, tt.args.h, tt.args.opts...); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("RegisterHandler() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisterSubscriber(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
topic string
|
|
|
|
s server.Server
|
|
|
|
h interface{}
|
|
|
|
opts []server.SubscriberOption
|
|
|
|
}
|
|
|
|
h := func(_ context.Context, _ interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "RegisterSubscriber",
|
|
|
|
args: args{
|
|
|
|
topic: "test",
|
|
|
|
s: server.DefaultServer,
|
|
|
|
h: h,
|
|
|
|
opts: nil,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if err := RegisterSubscriber(tt.args.topic, tt.args.s, tt.args.h, tt.args.opts...); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("RegisterSubscriber() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewService(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
opts []Option
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want Service
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "NewService",
|
2022-05-03 00:23:43 +03:00
|
|
|
args: args{
|
2022-04-24 11:08:38 +03:00
|
|
|
opts: []Option{Name("test")},
|
|
|
|
},
|
|
|
|
want: NewService(Name("test")),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := NewService(tt.args.opts...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("NewService() = %v, want %v", got.Options().Name, tt.want.Options().Name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Name(t *testing.T) {
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test_service_Name",
|
2022-05-03 00:23:43 +03:00
|
|
|
fields: fields{
|
2022-04-24 11:08:38 +03:00
|
|
|
opts: Options{Name: "test"},
|
|
|
|
},
|
|
|
|
want: "test",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Name(); got != tt.want {
|
|
|
|
t.Errorf("service.Name() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Init(t *testing.T) {
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
opts []Option
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "service.Init()",
|
|
|
|
fields: fields{
|
|
|
|
opts: Options{},
|
|
|
|
},
|
|
|
|
args: args{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: []Option{},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if err := s.Init(tt.args.opts...); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("service.Init() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Options(t *testing.T) {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts := Options{Name: "test"}
|
2022-04-24 11:08:38 +03:00
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want Options
|
|
|
|
}{
|
2022-05-03 00:23:43 +03:00
|
|
|
{
|
|
|
|
name: "service.Options",
|
|
|
|
fields: fields{
|
|
|
|
opts: opts,
|
|
|
|
},
|
|
|
|
want: opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Options(); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Options() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Broker(t *testing.T) {
|
|
|
|
b := broker.NewBroker()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want broker.Broker
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Broker",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Brokers: []broker.Broker{b}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: b,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Broker(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Broker() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 00:23:43 +03:00
|
|
|
/*
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
2022-04-24 11:08:38 +03:00
|
|
|
|
|
|
|
func Test_service_Tracer(t *testing.T) {
|
|
|
|
tr := tracer.NewTracer()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want tracer.Tracer
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Tracer",
|
|
|
|
fields: fields{
|
2022-04-24 11:08:38 +03:00
|
|
|
opts: Options{Tracers: []tracer.Tracer{tr}},
|
2022-05-03 00:23:43 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: tr,
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Tracer(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Tracer() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Config(t *testing.T) {
|
|
|
|
c := config.NewConfig()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want config.Config
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Config",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Configs: []config.Config{c}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Config(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Config() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Client(t *testing.T) {
|
|
|
|
c := client.NewClient()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want client.Client
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Client",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Clients: []client.Client{c}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Client(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Client() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Server(t *testing.T) {
|
|
|
|
s := server.NewServer()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want server.Server
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Server",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Servers: []server.Server{s}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: s,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Server(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Server() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Store(t *testing.T) {
|
|
|
|
s := store.NewStore()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want store.Store
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Store",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Stores: []store.Store{s}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: s,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Store(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Store() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Register(t *testing.T) {
|
|
|
|
r := register.NewRegister()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want register.Register
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Register",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Registers: []register.Register{r}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: r,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Register(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Register() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Logger(t *testing.T) {
|
|
|
|
l := logger.NewLogger()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want logger.Logger
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Logger",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Loggers: []logger.Logger{l}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: l,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Logger(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Logger() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Auth(t *testing.T) {
|
|
|
|
a := auth.NewAuth()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want auth.Auth
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Auth",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Auths: []auth.Auth{a}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: a,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Auth(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Auth() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Router(t *testing.T) {
|
|
|
|
r := router.NewRouter()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want router.Router
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Router",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Routers: []router.Router{r}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: r,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Router(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Router() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Meter(t *testing.T) {
|
|
|
|
m := meter.NewMeter()
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
names []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
want meter.Meter
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.Meter",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Meters: []meter.Meter{m}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
|
|
|
want: m,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.Meter(tt.args.names...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("service.Meter() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_String(t *testing.T) {
|
|
|
|
type fields struct {
|
2022-05-03 00:23:43 +03:00
|
|
|
opts Options
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
2022-05-03 00:23:43 +03:00
|
|
|
name: "service.String",
|
2022-04-24 11:08:38 +03:00
|
|
|
fields: fields{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: Options{Name: "noop"},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
want: "noop",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
2022-05-03 00:23:43 +03:00
|
|
|
opts: tt.fields.opts,
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
if got := s.String(); got != tt.want {
|
|
|
|
t.Errorf("service.String() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func Test_service_Start(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
RWMutex sync.RWMutex
|
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
// TODO: Add test cases.
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
|
|
|
RWMutex: tt.fields.RWMutex,
|
|
|
|
opts: tt.fields.opts,
|
|
|
|
}
|
|
|
|
if err := s.Start(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("service.Start() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Stop(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
RWMutex sync.RWMutex
|
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
// TODO: Add test cases.
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
|
|
|
RWMutex: tt.fields.RWMutex,
|
|
|
|
opts: tt.fields.opts,
|
|
|
|
}
|
|
|
|
if err := s.Stop(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("service.Stop() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_service_Run(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
RWMutex sync.RWMutex
|
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
// TODO: Add test cases.
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &service{
|
|
|
|
RWMutex: tt.fields.RWMutex,
|
|
|
|
opts: tt.fields.opts,
|
|
|
|
}
|
|
|
|
if err := s.Run(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("service.Run() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_getNameIndex(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
n string
|
|
|
|
ifaces interface{}
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want int
|
|
|
|
}{
|
|
|
|
// TODO: Add test cases.
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := getNameIndex(tt.args.n, tt.args.ifaces); got != tt.want {
|
|
|
|
t.Errorf("getNameIndex() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|