Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>v3.4.0-rc.1
parent
d28df4cbbb
commit
a029bdc0ca
@ -0,0 +1,128 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/OpenIMSDK/protocol/sdkws"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
)
|
||||
|
||||
func TestFriendPb2DB(t *testing.T) {
|
||||
type args struct {
|
||||
friend *sdkws.FriendInfo
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *relation.FriendModel
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := FriendPb2DB(tt.args.friend); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("FriendPb2DB() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFriendDB2Pb(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
friendDB *relation.FriendModel
|
||||
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *sdkws.FriendInfo
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := FriendDB2Pb(tt.args.ctx, tt.args.friendDB, tt.args.getUsers)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FriendDB2Pb() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("FriendDB2Pb() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFriendsDB2Pb(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
friendsDB []*relation.FriendModel
|
||||
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantFriendsPb []*sdkws.FriendInfo
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotFriendsPb, err := FriendsDB2Pb(tt.args.ctx, tt.args.friendsDB, tt.args.getUsers)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FriendsDB2Pb() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(gotFriendsPb, tt.wantFriendsPb) {
|
||||
t.Errorf("FriendsDB2Pb() = %v, want %v", gotFriendsPb, tt.wantFriendsPb)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFriendRequestDB2Pb(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
friendRequests []*relation.FriendRequestModel
|
||||
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []*sdkws.FriendRequest
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := FriendRequestDB2Pb(tt.args.ctx, tt.args.friendRequests, tt.args.getUsers)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FriendRequestDB2Pb() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("FriendRequestDB2Pb() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
type args struct {
|
||||
url string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantResponse []byte
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotResponse, err := Get(tt.args.url)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(gotResponse, tt.wantResponse) {
|
||||
t.Errorf("Get() = %v, want %v", gotResponse, tt.wantResponse)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPost(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
url string
|
||||
header map[string]string
|
||||
data interface{}
|
||||
timeout int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantContent []byte
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotContent, err := Post(tt.args.ctx, tt.args.url, tt.args.header, tt.args.data, tt.args.timeout)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Post() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(gotContent, tt.wantContent) {
|
||||
t.Errorf("Post() = %v, want %v", gotContent, tt.wantContent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostReturn(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
url string
|
||||
header map[string]string
|
||||
input interface{}
|
||||
output interface{}
|
||||
timeOutSecond int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := PostReturn(tt.args.ctx, tt.args.url, tt.args.header, tt.args.input, tt.args.output, tt.args.timeOutSecond); (err != nil) != tt.wantErr {
|
||||
t.Errorf("PostReturn() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_callBackPostReturn(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
url string
|
||||
command string
|
||||
input interface{}
|
||||
output callbackstruct.CallbackResp
|
||||
callbackConfig config.CallBackConfig
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := callBackPostReturn(tt.args.ctx, tt.args.url, tt.args.command, tt.args.input, tt.args.output, tt.args.callbackConfig); (err != nil) != tt.wantErr {
|
||||
t.Errorf("callBackPostReturn() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallBackPostReturn(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
url string
|
||||
req callbackstruct.CallbackReq
|
||||
resp callbackstruct.CallbackResp
|
||||
callbackConfig config.CallBackConfig
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := CallBackPostReturn(tt.args.ctx, tt.args.url, tt.args.req, tt.args.resp, tt.args.callbackConfig); (err != nil) != tt.wantErr {
|
||||
t.Errorf("CallBackPostReturn() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package discovery_register
|
||||
package kdisc
|
||||
|
||||
import (
|
||||
"context"
|
@ -0,0 +1,157 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package locker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||
)
|
||||
|
||||
func TestNewLockerMessage(t *testing.T) {
|
||||
type args struct {
|
||||
cache cache.MsgModel
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *LockerMessage
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewLockerMessage(tt.args.cache); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewLockerMessage() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockerMessage_LockMessageTypeKey(t *testing.T) {
|
||||
type fields struct {
|
||||
cache cache.MsgModel
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
clientMsgID string
|
||||
typeKey string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
l := &LockerMessage{
|
||||
cache: tt.fields.cache,
|
||||
}
|
||||
if err := l.LockMessageTypeKey(tt.args.ctx, tt.args.clientMsgID, tt.args.typeKey); (err != nil) != tt.wantErr {
|
||||
t.Errorf("LockerMessage.LockMessageTypeKey() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockerMessage_LockGlobalMessage(t *testing.T) {
|
||||
type fields struct {
|
||||
cache cache.MsgModel
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
clientMsgID string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
l := &LockerMessage{
|
||||
cache: tt.fields.cache,
|
||||
}
|
||||
if err := l.LockGlobalMessage(tt.args.ctx, tt.args.clientMsgID); (err != nil) != tt.wantErr {
|
||||
t.Errorf("LockerMessage.LockGlobalMessage() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockerMessage_UnLockMessageTypeKey(t *testing.T) {
|
||||
type fields struct {
|
||||
cache cache.MsgModel
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
clientMsgID string
|
||||
typeKey string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
l := &LockerMessage{
|
||||
cache: tt.fields.cache,
|
||||
}
|
||||
if err := l.UnLockMessageTypeKey(tt.args.ctx, tt.args.clientMsgID, tt.args.typeKey); (err != nil) != tt.wantErr {
|
||||
t.Errorf("LockerMessage.UnLockMessageTypeKey() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockerMessage_UnLockGlobalMessage(t *testing.T) {
|
||||
type fields struct {
|
||||
cache cache.MsgModel
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
clientMsgID string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
l := &LockerMessage{
|
||||
cache: tt.fields.cache,
|
||||
}
|
||||
if err := l.UnLockGlobalMessage(tt.args.ctx, tt.args.clientMsgID); (err != nil) != tt.wantErr {
|
||||
t.Errorf("LockerMessage.UnLockGlobalMessage() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package prom_metrics
|
||||
|
||||
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
|
||||
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||
|
||||
/*
|
||||
labels := prometheus.Labels{"label_one": "any", "label_two": "value"}
|
@ -0,0 +1,80 @@
|
||||
package prom_metrics
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/ginprom"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func TestNewGrpcPromObj(t *testing.T) {
|
||||
type args struct {
|
||||
cusMetrics []prometheus.Collector
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *prometheus.Registry
|
||||
want1 *grpc_prometheus.ServerMetrics
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, got1, err := NewGrpcPromObj(tt.args.cusMetrics)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("NewGrpcPromObj() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewGrpcPromObj() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if !reflect.DeepEqual(got1, tt.want1) {
|
||||
t.Errorf("NewGrpcPromObj() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGrpcCusMetrics(t *testing.T) {
|
||||
type args struct {
|
||||
registerName string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []prometheus.Collector
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetGrpcCusMetrics(tt.args.registerName); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetGrpcCusMetrics() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetGinCusMetrics(t *testing.T) {
|
||||
type args struct {
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []*ginprom.Metric
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetGinCusMetrics(tt.args.name); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetGinCusMetrics() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in new issue