2021-10-07 20:59:27 +03:00
|
|
|
package micro
|
|
|
|
|
|
|
|
import (
|
2024-02-28 23:51:05 +03:00
|
|
|
"go.unistack.org/micro/v4/register/memory"
|
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
|
|
|
|
2023-04-11 22:20:37 +03:00
|
|
|
"go.unistack.org/micro/v4/broker"
|
|
|
|
"go.unistack.org/micro/v4/client"
|
|
|
|
"go.unistack.org/micro/v4/config"
|
|
|
|
"go.unistack.org/micro/v4/logger"
|
|
|
|
"go.unistack.org/micro/v4/meter"
|
2023-07-29 00:40:58 +03:00
|
|
|
"go.unistack.org/micro/v4/options"
|
2023-04-11 22:20:37 +03:00
|
|
|
"go.unistack.org/micro/v4/register"
|
|
|
|
"go.unistack.org/micro/v4/router"
|
|
|
|
"go.unistack.org/micro/v4/server"
|
|
|
|
"go.unistack.org/micro/v4/store"
|
|
|
|
"go.unistack.org/micro/v4/tracer"
|
2021-10-07 20:59:27 +03:00
|
|
|
)
|
|
|
|
|
2023-11-13 08:23:22 +03:00
|
|
|
func TestClient(t *testing.T) {
|
|
|
|
c1 := client.NewClient(options.Name("test1"))
|
|
|
|
c2 := client.NewClient(options.Name("test2"))
|
2021-10-07 20:59:27 +03:00
|
|
|
|
2023-11-13 08:23:22 +03:00
|
|
|
svc := NewService(Client(c1, c2))
|
|
|
|
if err := svc.Init(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-10-07 20:59:27 +03:00
|
|
|
|
2023-11-13 08:23:22 +03:00
|
|
|
x1 := svc.Client("test2")
|
|
|
|
if x1.Name() != "test2" {
|
|
|
|
t.Fatal("invalid client")
|
2021-10-07 20:59:27 +03:00
|
|
|
}
|
|
|
|
}
|
2022-04-24 11:08:38 +03:00
|
|
|
|
|
|
|
func TestRegisterHandler(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
s server.Server
|
|
|
|
h interface{}
|
2023-07-29 00:40:58 +03:00
|
|
|
opts []options.Option
|
2022-04-24 11:08:38 +03:00
|
|
|
}
|
|
|
|
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 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) {
|
|
|
|
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{
|
2023-05-09 20:04:15 +03:00
|
|
|
opts: Options{Brokers: []broker.Broker{broker.DefaultBroker}},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
names: []string{"noop"},
|
|
|
|
},
|
2023-05-09 20:04:15 +03:00
|
|
|
want: broker.DefaultBroker,
|
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.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) {
|
2024-02-28 23:51:05 +03:00
|
|
|
r := memory.NewRegister()
|
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
|
|
|
}
|
|
|
|
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{
|
2024-02-29 18:02:12 +03:00
|
|
|
names: []string{"memory"},
|
2022-04-24 11:08:38 +03:00
|
|
|
},
|
|
|
|
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_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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|