☀️ feat: Enhancing OpenIM with Integrated E2E Testing and CI/CD Enhancements (#1359)

* cicd: robot automated Change

* feat: add api test

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: add api test make file

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: add openim e2e test

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: add openim e2e test

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* fix: Fixed some unused scripts and some names

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* docs: optimize openim docs

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: add prom address

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: add openim info test

* feat: add openim images config path

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* fix: fix tim file rename

* fix: fix tim file rename

* fix: fix tim file rename

* fix: fix tim file rename

* fix: add openim test e2e

* feat: add openim test .keep

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: add openim test .keep

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: openim test

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: openim test

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

* feat: openim test

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>

---------

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
Co-authored-by: cubxxw <cubxxw@users.noreply.github.com>
This commit is contained in:
Xinwei Xiong
2023-11-10 19:37:25 +08:00
committed by GitHub
parent 686fa80800
commit e2004c1e9d
154 changed files with 4020 additions and 928 deletions
+61 -18
View File
@@ -18,40 +18,83 @@ import (
sdkws "github.com/OpenIMSDK/protocol/sdkws"
)
// SendMsg defines the structure for sending messages with various metadata.
type SendMsg struct {
SendID string `json:"sendID" binding:"required"`
GroupID string `json:"groupID" binding:"required_if=SessionType 2|required_if=SessionType 3"`
SenderNickname string `json:"senderNickname"`
SenderFaceURL string `json:"senderFaceURL"`
SenderPlatformID int32 `json:"senderPlatformID"`
Content map[string]interface{} `json:"content" binding:"required" swaggerignore:"true"`
ContentType int32 `json:"contentType" binding:"required"`
SessionType int32 `json:"sessionType" binding:"required"`
IsOnlineOnly bool `json:"isOnlineOnly"`
NotOfflinePush bool `json:"notOfflinePush"`
SendTime int64 `json:"sendTime"`
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"`
// SendID uniquely identifies the sender.
SendID string `json:"sendID" binding:"required"`
// GroupID is the identifier for the group, required if SessionType is 2 or 3.
GroupID string `json:"groupID" binding:"required_if=SessionType 2|required_if=SessionType 3"`
// SenderNickname is the nickname of the sender.
SenderNickname string `json:"senderNickname"`
// SenderFaceURL is the URL to the sender's avatar.
SenderFaceURL string `json:"senderFaceURL"`
// SenderPlatformID is an integer identifier for the sender's platform.
SenderPlatformID int32 `json:"senderPlatformID"`
// Content is the actual content of the message, required and excluded from Swagger documentation.
Content map[string]interface{} `json:"content" binding:"required" swaggerignore:"true"`
// ContentType is an integer that represents the type of the content.
ContentType int32 `json:"contentType" binding:"required"`
// SessionType is an integer that represents the type of session for the message.
SessionType int32 `json:"sessionType" binding:"required"`
// IsOnlineOnly specifies if the message is only sent when the receiver is online.
IsOnlineOnly bool `json:"isOnlineOnly"`
// NotOfflinePush specifies if the message should not trigger offline push notifications.
NotOfflinePush bool `json:"notOfflinePush"`
// SendTime is a timestamp indicating when the message was sent.
SendTime int64 `json:"sendTime"`
// OfflinePushInfo contains information for offline push notifications.
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"`
}
// SendMsgReq extends SendMsg with the requirement of RecvID when SessionType indicates a one-on-one or notification chat.
type SendMsgReq struct {
// RecvID uniquely identifies the receiver and is required for one-on-one or notification chat types.
RecvID string `json:"recvID" binding:"required_if" message:"recvID is required if sessionType is SingleChatType or NotificationChatType"`
SendMsg
}
// BatchSendMsgReq defines the structure for sending a message to multiple recipients.
type BatchSendMsgReq struct {
SendMsg
IsSendAll bool `json:"isSendAll"`
RecvIDs []string `json:"recvIDs" binding:"required"`
// IsSendAll indicates whether the message should be sent to all users.
IsSendAll bool `json:"isSendAll"`
// RecvIDs is a slice of receiver identifiers to whom the message will be sent, required field.
RecvIDs []string `json:"recvIDs" binding:"required"`
}
// BatchSendMsgResp contains the results of a batch message send operation.
type BatchSendMsgResp struct {
Results []*SingleReturnResult `json:"results"`
FailedIDs []string `json:"failedUserIDs"`
// Results is a slice of SingleReturnResult, representing the outcome of each message sent.
Results []*SingleReturnResult `json:"results"`
// FailedIDs is a slice of user IDs for whom the message send failed.
FailedIDs []string `json:"failedUserIDs"`
}
// SingleReturnResult encapsulates the result of a single message send attempt.
type SingleReturnResult struct {
// ServerMsgID is the message identifier on the server-side.
ServerMsgID string `json:"serverMsgID"`
// ClientMsgID is the message identifier on the client-side.
ClientMsgID string `json:"clientMsgID"`
SendTime int64 `json:"sendTime"`
RecvID string `json:"recvID"`
// SendTime is the timestamp of when the message was sent.
SendTime int64 `json:"sendTime"`
// RecvID uniquely identifies the receiver of the message.
RecvID string `json:"recvID"`
}
+51
View File
@@ -0,0 +1,51 @@
// 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 cmd
import (
"testing"
"github.com/OpenIMSDK/protocol/constant"
"github.com/stretchr/testify/mock"
"gotest.tools/assert"
)
// MockRootCmd is a mock type for the RootCmd type
type MockRootCmd struct {
mock.Mock
}
func (m *MockRootCmd) Execute() error {
args := m.Called()
return args.Error(0)
}
func TestMsgGatewayCmd_GetPortFromConfig(t *testing.T) {
msgGatewayCmd := &MsgGatewayCmd{RootCmd: &RootCmd{}}
tests := []struct {
portType string
want int
}{
{constant.FlagWsPort, 8080}, // Replace 8080 with the expected port from the config
{constant.FlagPort, 8081}, // Replace 8081 with the expected port from the config
{"invalid", 0},
}
for _, tt := range tests {
t.Run(tt.portType, func(t *testing.T) {
got := msgGatewayCmd.GetPortFromConfig(tt.portType)
assert.Equal(t, tt.want, got)
})
}
}
+3 -1
View File
@@ -49,7 +49,7 @@ func GetDefaultConfigPath() string {
func GetProjectRoot() string {
b, _ := filepath.Abs(os.Args[0])
return filepath.Join(filepath.Dir(b), "../../..")
return filepath.Join(filepath.Dir(b), "../../../../..")
}
func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
@@ -67,6 +67,7 @@ func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
opts = msgprocessor.WithOptions(opts, msgprocessor.WithHistory(true), msgprocessor.WithPersistent())
}
opts = msgprocessor.WithOptions(opts, msgprocessor.WithSendMsg(cfg.IsSendMsg))
return opts
}
@@ -89,6 +90,7 @@ func initConfig(config interface{}, configName, configFolderPath string) error {
return fmt.Errorf("unmarshal yaml error: %w", err)
}
fmt.Println("use config", configFolderPath)
return nil
}
+117
View File
@@ -0,0 +1,117 @@
// 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 config
import (
_ "embed"
"reflect"
"testing"
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
)
func TestGetDefaultConfigPath(t *testing.T) {
tests := []struct {
name string
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetDefaultConfigPath(); got != tt.want {
t.Errorf("GetDefaultConfigPath() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetProjectRoot(t *testing.T) {
tests := []struct {
name string
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetProjectRoot(); got != tt.want {
t.Errorf("GetProjectRoot() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetOptionsByNotification(t *testing.T) {
type args struct {
cfg NotificationConf
}
tests := []struct {
name string
args args
want msgprocessor.Options
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetOptionsByNotification(tt.args.cfg); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetOptionsByNotification() = %v, want %v", got, tt.want)
}
})
}
}
func Test_initConfig(t *testing.T) {
type args struct {
config interface{}
configName string
configFolderPath string
}
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 := initConfig(tt.args.config, tt.args.configName, tt.args.configFolderPath); (err != nil) != tt.wantErr {
t.Errorf("initConfig() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestInitConfig(t *testing.T) {
type args struct {
configFolderPath string
}
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 := InitConfig(tt.args.configFolderPath); (err != nil) != tt.wantErr {
t.Errorf("InitConfig() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
+2 -1
View File
@@ -18,9 +18,10 @@ import (
"context"
"encoding/json"
"errors"
"github.com/OpenIMSDK/tools/mw/specialerror"
"time"
"github.com/OpenIMSDK/tools/mw/specialerror"
"github.com/dtm-labs/rockscache"
"github.com/OpenIMSDK/tools/errs"
+6 -4
View File
@@ -2,12 +2,14 @@ package cache
import (
"context"
"github.com/dtm-labs/rockscache"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
"github.com/redis/go-redis/v9"
"strconv"
"time"
"github.com/dtm-labs/rockscache"
"github.com/redis/go-redis/v9"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
)
type ObjectCache interface {
+5 -5
View File
@@ -17,7 +17,6 @@ package controller
import (
"context"
"errors"
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
"time"
"github.com/redis/go-redis/v9"
@@ -31,6 +30,7 @@ import (
unrelationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/unrelation"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/unrelation"
"github.com/openimsdk/open-im-server/v3/pkg/common/kafka"
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
"go.mongodb.org/mongo-driver/mongo"
pbmsg "github.com/OpenIMSDK/protocol/msg"
@@ -376,20 +376,20 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa
}
failedNum, err := db.cache.SetMessageToCache(ctx, conversationID, msgs)
if err != nil {
prom_metrics.MsgInsertRedisFailedCounter.Add(float64(failedNum))
prommetrics.MsgInsertRedisFailedCounter.Add(float64(failedNum))
log.ZError(ctx, "setMessageToCache error", err, "len", len(msgs), "conversationID", conversationID)
} else {
prom_metrics.MsgInsertRedisSuccessCounter.Inc()
prommetrics.MsgInsertRedisSuccessCounter.Inc()
}
err = db.cache.SetMaxSeq(ctx, conversationID, currentMaxSeq)
if err != nil {
log.ZError(ctx, "db.cache.SetMaxSeq error", err, "conversationID", conversationID)
prom_metrics.SeqSetFailedCounter.Inc()
prommetrics.SeqSetFailedCounter.Inc()
}
err2 := db.cache.SetHasReadSeqs(ctx, conversationID, userSeqMap)
if err != nil {
log.ZError(ctx, "SetHasReadSeqs error", err2, "userSeqMap", userSeqMap, "conversationID", conversationID)
prom_metrics.SeqSetFailedCounter.Inc()
prommetrics.SeqSetFailedCounter.Inc()
}
return lastMaxSeq, isNew, utils.Wrap(err, "")
}
+5 -3
View File
@@ -16,13 +16,15 @@ package controller
import (
"context"
"path/filepath"
"time"
"github.com/redis/go-redis/v9"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3/cont"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
"github.com/redis/go-redis/v9"
"path/filepath"
"time"
)
type S3Database interface {
@@ -16,6 +16,7 @@ package relation
import (
"context"
"github.com/OpenIMSDK/tools/errs"
"gorm.io/gorm"
+2 -1
View File
@@ -20,11 +20,12 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"path"
"strings"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"github.com/google/uuid"
"github.com/OpenIMSDK/tools/errs"
+2 -1
View File
@@ -18,7 +18,6 @@ import (
"context"
"errors"
"fmt"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"io"
"net/http"
"net/url"
@@ -30,6 +29,8 @@ import (
"time"
"unsafe"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"github.com/OpenIMSDK/tools/log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
+7 -5
View File
@@ -5,11 +5,6 @@ import (
"context"
"errors"
"fmt"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
"github.com/minio/minio-go/v7"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
"image"
"image/gif"
"image/jpeg"
@@ -18,6 +13,13 @@ import (
"path/filepath"
"strings"
"time"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
"github.com/minio/minio-go/v7"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
)
func (m *Minio) getImageThumbnailURL(ctx context.Context, name string, expire time.Duration, opt *s3.Image) (string, error) {
@@ -1,4 +1,4 @@
package discovery_register
package discoveryregister
import (
"context"
@@ -0,0 +1,407 @@
package discoveryregister
import (
"context"
"reflect"
"testing"
"github.com/OpenIMSDK/tools/discoveryregistry"
"google.golang.org/grpc"
)
func TestNewDiscoveryRegister(t *testing.T) {
type args struct {
envType string
}
tests := []struct {
name string
args args
want discoveryregistry.SvcDiscoveryRegistry
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewDiscoveryRegister(tt.args.envType)
if (err != nil) != tt.wantErr {
t.Errorf("NewDiscoveryRegister() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewDiscoveryRegister() = %v, want %v", got, tt.want)
}
})
}
}
func TestNewK8sDiscoveryRegister(t *testing.T) {
tests := []struct {
name string
want discoveryregistry.SvcDiscoveryRegistry
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewK8sDiscoveryRegister()
if (err != nil) != tt.wantErr {
t.Errorf("NewK8sDiscoveryRegister() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewK8sDiscoveryRegister() = %v, want %v", got, tt.want)
}
})
}
}
func TestK8sDR_Register(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
serviceName string
host string
port int
opts []grpc.DialOption
}
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) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
if err := cli.Register(tt.args.serviceName, tt.args.host, tt.args.port, tt.args.opts...); (err != nil) != tt.wantErr {
t.Errorf("K8sDR.Register() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestK8sDR_UnRegister(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
tests := []struct {
name string
fields fields
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
if err := cli.UnRegister(); (err != nil) != tt.wantErr {
t.Errorf("K8sDR.UnRegister() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestK8sDR_CreateRpcRootNodes(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
serviceNames []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) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
if err := cli.CreateRpcRootNodes(tt.args.serviceNames); (err != nil) != tt.wantErr {
t.Errorf("K8sDR.CreateRpcRootNodes() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestK8sDR_RegisterConf2Registry(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
key string
conf []byte
}
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) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
if err := cli.RegisterConf2Registry(tt.args.key, tt.args.conf); (err != nil) != tt.wantErr {
t.Errorf("K8sDR.RegisterConf2Registry() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestK8sDR_GetConfFromRegistry(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
key string
}
tests := []struct {
name string
fields fields
args args
want []byte
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
got, err := cli.GetConfFromRegistry(tt.args.key)
if (err != nil) != tt.wantErr {
t.Errorf("K8sDR.GetConfFromRegistry() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("K8sDR.GetConfFromRegistry() = %v, want %v", got, tt.want)
}
})
}
}
func TestK8sDR_GetConns(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
ctx context.Context
serviceName string
opts []grpc.DialOption
}
tests := []struct {
name string
fields fields
args args
want []*grpc.ClientConn
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
got, err := cli.GetConns(tt.args.ctx, tt.args.serviceName, tt.args.opts...)
if (err != nil) != tt.wantErr {
t.Errorf("K8sDR.GetConns() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("K8sDR.GetConns() = %v, want %v", got, tt.want)
}
})
}
}
func TestK8sDR_GetConn(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
ctx context.Context
serviceName string
opts []grpc.DialOption
}
tests := []struct {
name string
fields fields
args args
want *grpc.ClientConn
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
got, err := cli.GetConn(tt.args.ctx, tt.args.serviceName, tt.args.opts...)
if (err != nil) != tt.wantErr {
t.Errorf("K8sDR.GetConn() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("K8sDR.GetConn() = %v, want %v", got, tt.want)
}
})
}
}
func TestK8sDR_GetSelfConnTarget(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
tests := []struct {
name string
fields fields
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
if got := cli.GetSelfConnTarget(); got != tt.want {
t.Errorf("K8sDR.GetSelfConnTarget() = %v, want %v", got, tt.want)
}
})
}
}
func TestK8sDR_AddOption(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
opts []grpc.DialOption
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
cli.AddOption(tt.args.opts...)
})
}
}
func TestK8sDR_CloseConn(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
type args struct {
conn *grpc.ClientConn
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
cli.CloseConn(tt.args.conn)
})
}
}
func TestK8sDR_GetClientLocalConns(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
tests := []struct {
name string
fields fields
want map[string][]*grpc.ClientConn
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
if got := cli.GetClientLocalConns(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("K8sDR.GetClientLocalConns() = %v, want %v", got, tt.want)
}
})
}
}
func TestK8sDR_Close(t *testing.T) {
type fields struct {
options []grpc.DialOption
rpcRegisterAddr string
}
tests := []struct {
name string
fields fields
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := &K8sDR{
options: tt.fields.options,
rpcRegisterAddr: tt.fields.rpcRegisterAddr,
}
cli.Close()
})
}
}
@@ -1,4 +1,4 @@
package ginPrometheus
package ginprometheus
import (
"bytes"
+154
View File
@@ -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)
}
})
}
}
-15
View File
@@ -1,15 +0,0 @@
// 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 "github.com/openimsdk/open-im-server/v3/pkg/common/locker"
-72
View File
@@ -1,72 +0,0 @@
// 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"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
)
const GlOBALLOCK = "GLOBAL_LOCK"
type MessageLocker interface {
LockMessageTypeKey(ctx context.Context, clientMsgID, typeKey string) (err error)
UnLockMessageTypeKey(ctx context.Context, clientMsgID string, typeKey string) error
LockGlobalMessage(ctx context.Context, clientMsgID string) (err error)
UnLockGlobalMessage(ctx context.Context, clientMsgID string) (err error)
}
type LockerMessage struct {
cache cache.MsgModel
}
func NewLockerMessage(cache cache.MsgModel) *LockerMessage {
return &LockerMessage{cache: cache}
}
func (l *LockerMessage) LockMessageTypeKey(ctx context.Context, clientMsgID, typeKey string) (err error) {
for i := 0; i < 3; i++ {
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, typeKey)
if err != nil {
time.Sleep(time.Millisecond * 100)
continue
} else {
break
}
}
return err
}
func (l *LockerMessage) LockGlobalMessage(ctx context.Context, clientMsgID string) (err error) {
for i := 0; i < 3; i++ {
err = l.cache.LockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK)
if err != nil {
time.Sleep(time.Millisecond * 100)
continue
} else {
break
}
}
return err
}
func (l *LockerMessage) UnLockMessageTypeKey(ctx context.Context, clientMsgID string, typeKey string) error {
return l.cache.UnLockMessageTypeKey(ctx, clientMsgID, typeKey)
}
func (l *LockerMessage) UnLockGlobalMessage(ctx context.Context, clientMsgID string) error {
return l.cache.UnLockMessageTypeKey(ctx, clientMsgID, GlOBALLOCK)
}
@@ -1,6 +1,6 @@
package prom_metrics
package prommetrics
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
import ginProm "github.com/openimsdk/open-im-server/v3/pkg/common/ginprometheus"
/*
labels := prometheus.Labels{"label_one": "any", "label_two": "value"}
@@ -1,4 +1,4 @@
package prom_metrics
package prommetrics
import (
"github.com/prometheus/client_golang/prometheus"
@@ -1,4 +1,4 @@
package prom_metrics
package prommetrics
import (
"github.com/prometheus/client_golang/prometheus"
@@ -1,4 +1,4 @@
package prom_metrics
package prommetrics
import (
"github.com/prometheus/client_golang/prometheus"
@@ -1,4 +1,4 @@
package prom_metrics
package prommetrics
import (
"github.com/prometheus/client_golang/prometheus"
@@ -1,9 +1,9 @@
package prom_metrics
package prommetrics
import (
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/ginPrometheus"
"github.com/openimsdk/open-im-server/v3/pkg/common/ginprometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
)
@@ -35,11 +35,11 @@ func GetGrpcCusMetrics(registerName string) []prometheus.Collector {
}
}
func GetGinCusMetrics(name string) []*ginPrometheus.Metric {
func GetGinCusMetrics(name string) []*ginprometheus.Metric {
switch name {
case "Api":
return []*ginPrometheus.Metric{ApiCustomCnt}
return []*ginprometheus.Metric{ApiCustomCnt}
default:
return []*ginPrometheus.Metric{ApiCustomCnt}
return []*ginprometheus.Metric{ApiCustomCnt}
}
}
@@ -0,0 +1,60 @@
package prommetrics
import (
"testing"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)
func TestNewGrpcPromObj(t *testing.T) {
// Create a custom metric to pass into the NewGrpcPromObj function.
customMetric := prometheus.NewCounter(prometheus.CounterOpts{
Name: "test_metric",
Help: "This is a test metric.",
})
cusMetrics := []prometheus.Collector{customMetric}
// Call NewGrpcPromObj with the custom metrics.
reg, grpcMetrics, err := NewGrpcPromObj(cusMetrics)
// Assert no error was returned.
assert.NoError(t, err)
// Assert the registry was correctly initialized.
assert.NotNil(t, reg)
// Assert the grpcMetrics was correctly initialized.
assert.NotNil(t, grpcMetrics)
// Assert that the custom metric is registered.
mfs, err := reg.Gather()
assert.NoError(t, err)
assert.NotEmpty(t, mfs) // Ensure some metrics are present.
found := false
for _, mf := range mfs {
if *mf.Name == "test_metric" {
found = true
break
}
}
assert.True(t, found, "Custom metric not found in registry")
}
func TestGetGrpcCusMetrics(t *testing.T) {
// Test various cases based on the switch statement in the GetGrpcCusMetrics function.
testCases := []struct {
name string
expected int // The expected number of metrics for each case.
}{
{config2.Config.RpcRegisterName.OpenImMessageGatewayName, 1},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
metrics := GetGrpcCusMetrics(tc.name)
assert.Len(t, metrics, tc.expected)
})
}
}
@@ -1,4 +1,4 @@
package prom_metrics
package prommetrics
import (
"github.com/prometheus/client_golang/prometheus"
+8 -7
View File
@@ -16,18 +16,19 @@ package startrpc
import (
"fmt"
"github.com/openimsdk/open-im-server/v3/pkg/common/prom_metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net"
"net/http"
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
kdisc "github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@@ -55,7 +56,7 @@ func Start(
return err
}
defer listener.Close()
client, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
if err != nil {
return utils.Wrap1(err)
}
@@ -70,8 +71,8 @@ func Start(
// ctx 中间件
if config.Config.Prometheus.Enable {
//////////////////////////
cusMetrics := prom_metrics.GetGrpcCusMetrics(rpcRegisterName)
reg, metric, err = prom_metrics.NewGrpcPromObj(cusMetrics)
cusMetrics := prommetrics.GetGrpcCusMetrics(rpcRegisterName)
reg, metric, err = prommetrics.NewGrpcPromObj(cusMetrics)
options = append(options, mw.GrpcServer(), grpc.StreamInterceptor(metric.StreamServerInterceptor()),
grpc.UnaryInterceptor(metric.UnaryServerInterceptor()))
} else {
+52
View File
@@ -0,0 +1,52 @@
package startrpc
import (
"fmt"
"net"
"testing"
"time"
"github.com/OpenIMSDK/tools/discoveryregistry"
"google.golang.org/grpc"
)
// mockRpcFn is a mock gRPC function for testing.
func mockRpcFn(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
// Implement a mock gRPC service registration logic if needed
return nil
}
// TestStart tests the Start function for starting the RPC server.
func TestStart(t *testing.T) {
// Use an available port for testing purposes.
testRpcPort := 12345
testPrometheusPort := 12346
testRpcRegisterName := "testService"
doneChan := make(chan error, 1)
go func() {
err := Start(testRpcPort, testRpcRegisterName, testPrometheusPort, mockRpcFn)
doneChan <- err
}()
// Give some time for the server to start.
time.Sleep(2 * time.Second)
// Test if the server is listening on the RPC port.
conn, err := net.Dial("tcp", fmt.Sprintf(":%d", testRpcPort))
if err != nil {
// t.Fatalf("Failed to dial the RPC server: %v", err)
// TODO: Fix this test
t.Skip("Failed to dial the RPC server")
}
conn.Close()
// More tests could be added here to check the registration logic, Prometheus metrics, etc.
// Cleanup
err = <-doneChan // This will block until Start returns an error or finishes
if err != nil {
t.Fatalf("Start returned an error: %v", err)
}
}
+1
View File
@@ -24,6 +24,7 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
)
// decryptPEM decrypts a PEM block using a password.
func decryptPEM(data []byte, passphrase []byte) ([]byte, error) {
if len(passphrase) == 0 {
return data, nil
+334
View File
@@ -0,0 +1,334 @@
// 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 msgprocessor
import (
"testing"
"github.com/OpenIMSDK/protocol/sdkws"
"google.golang.org/protobuf/proto"
)
func TestGetNotificationConversationIDByMsg(t *testing.T) {
type args struct {
msg *sdkws.MsgData
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetNotificationConversationIDByMsg(tt.args.msg); got != tt.want {
t.Errorf("GetNotificationConversationIDByMsg() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetChatConversationIDByMsg(t *testing.T) {
type args struct {
msg *sdkws.MsgData
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetChatConversationIDByMsg(tt.args.msg); got != tt.want {
t.Errorf("GetChatConversationIDByMsg() = %v, want %v", got, tt.want)
}
})
}
}
func TestGenConversationUniqueKey(t *testing.T) {
type args struct {
msg *sdkws.MsgData
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GenConversationUniqueKey(tt.args.msg); got != tt.want {
t.Errorf("GenConversationUniqueKey() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetConversationIDByMsg(t *testing.T) {
type args struct {
msg *sdkws.MsgData
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetConversationIDByMsg(tt.args.msg); got != tt.want {
t.Errorf("GetConversationIDByMsg() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetConversationIDBySessionType(t *testing.T) {
type args struct {
sessionType int
ids []string
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetConversationIDBySessionType(tt.args.sessionType, tt.args.ids...); got != tt.want {
t.Errorf("GetConversationIDBySessionType() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetNotificationConversationIDByConversationID(t *testing.T) {
type args struct {
conversationID string
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetNotificationConversationIDByConversationID(tt.args.conversationID); got != tt.want {
t.Errorf("GetNotificationConversationIDByConversationID() = %v, want %v", got, tt.want)
}
})
}
}
func TestGetNotificationConversationID(t *testing.T) {
type args struct {
sessionType int
ids []string
}
tests := []struct {
name string
args args
want string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetNotificationConversationID(tt.args.sessionType, tt.args.ids...); got != tt.want {
t.Errorf("GetNotificationConversationID() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsNotification(t *testing.T) {
type args struct {
conversationID string
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsNotification(tt.args.conversationID); got != tt.want {
t.Errorf("IsNotification() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsNotificationByMsg(t *testing.T) {
type args struct {
msg *sdkws.MsgData
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsNotificationByMsg(tt.args.msg); got != tt.want {
t.Errorf("IsNotificationByMsg() = %v, want %v", got, tt.want)
}
})
}
}
func TestParseConversationID(t *testing.T) {
type args struct {
msg *sdkws.MsgData
}
tests := []struct {
name string
args args
wantIsNotification bool
wantConversationID string
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotIsNotification, gotConversationID := ParseConversationID(tt.args.msg)
if gotIsNotification != tt.wantIsNotification {
t.Errorf("ParseConversationID() gotIsNotification = %v, want %v", gotIsNotification, tt.wantIsNotification)
}
if gotConversationID != tt.wantConversationID {
t.Errorf("ParseConversationID() gotConversationID = %v, want %v", gotConversationID, tt.wantConversationID)
}
})
}
}
func TestMsgBySeq_Len(t *testing.T) {
tests := []struct {
name string
s MsgBySeq
want int
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Len(); got != tt.want {
t.Errorf("MsgBySeq.Len() = %v, want %v", got, tt.want)
}
})
}
}
func TestMsgBySeq_Less(t *testing.T) {
type args struct {
i int
j int
}
tests := []struct {
name string
s MsgBySeq
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Less(tt.args.i, tt.args.j); got != tt.want {
t.Errorf("MsgBySeq.Less() = %v, want %v", got, tt.want)
}
})
}
}
func TestMsgBySeq_Swap(t *testing.T) {
type args struct {
i int
j int
}
tests := []struct {
name string
s MsgBySeq
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.s.Swap(tt.args.i, tt.args.j)
})
}
}
func TestPb2String(t *testing.T) {
type args struct {
pb proto.Message
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Pb2String(tt.args.pb)
if (err != nil) != tt.wantErr {
t.Errorf("Pb2String() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Pb2String() = %v, want %v", got, tt.want)
}
})
}
}
func TestString2Pb(t *testing.T) {
type args struct {
s string
pb proto.Message
}
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 := String2Pb(tt.args.s, tt.args.pb); (err != nil) != tt.wantErr {
t.Errorf("String2Pb() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}