first commit
This commit is contained in:
124
pkg/common/netease/ImClient_test.go
Normal file
124
pkg/common/netease/ImClient_test.go
Normal file
@ -0,0 +1,124 @@
|
||||
package Netease
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// 测试获取IM用户信息
|
||||
func TestImClient_GetImUserInfo(t *testing.T) {
|
||||
type fields struct {
|
||||
AppKey string
|
||||
AppSecret string
|
||||
}
|
||||
type args struct {
|
||||
userId string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test",
|
||||
fields: fields{
|
||||
AppKey: "543b1a440b940b170fccdf494839efc01",
|
||||
AppSecret: "41134093938f1",
|
||||
},
|
||||
args: args{
|
||||
// 2251bae8a0514e6892f0374f5dd260d4
|
||||
// b8af4bebe2064435974ba2340d852055
|
||||
userId: "fcda23bc00e641f5ae17492503b566ed",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
client := &ImClient{
|
||||
AppKey: tt.fields.AppKey,
|
||||
AppSecret: tt.fields.AppSecret,
|
||||
}
|
||||
if err := client.GetImUserInfo(tt.args.userId); (err != nil) != tt.wantErr {
|
||||
t.Errorf("GetImUserInfo() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 测试注册IM用户
|
||||
func TestImClient_CreateImUser(t *testing.T) {
|
||||
type fields struct {
|
||||
AppKey string
|
||||
AppSecret string
|
||||
}
|
||||
type args struct {
|
||||
userId string
|
||||
nickname string
|
||||
avatar string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test",
|
||||
fields: fields{
|
||||
AppKey: "543b1a440b940b170fccdf494839efc01",
|
||||
AppSecret: "41134093938f1",
|
||||
},
|
||||
args: args{
|
||||
// 2251bae8a0514e6892f0374f5dd260d4
|
||||
// b8af4bebe2064435974ba2340d852055
|
||||
userId: "fcda23bc00e641f5ae17492503b566ed",
|
||||
nickname: "杏",
|
||||
avatar: "https://photo-app.ddegame.cn/upload/19986a27-3bae-49f7-9643-cd18cda87557.jpg",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
client := &ImClient{
|
||||
AppKey: tt.fields.AppKey,
|
||||
AppSecret: tt.fields.AppSecret,
|
||||
}
|
||||
if err := client.CreateImUser(tt.args.userId, tt.args.nickname, tt.args.avatar); (err != nil) != tt.wantErr {
|
||||
t.Errorf("GetImUserInfo() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 测试注册IM用户
|
||||
func TestImClient_CreateImUserOne(t *testing.T) {
|
||||
client := &ImClient{
|
||||
AppKey: "543b1a440b940b170fccdf494839efc01",
|
||||
AppSecret: "41134093938f1",
|
||||
}
|
||||
client.CreateImUser("fcda23bc00e641f5ae17492503b566ed", "杏", "https://photo-app.ddegame.cn/upload/19986a27-3bae-49f7-9643-cd18cda87557.jpg")
|
||||
}
|
||||
|
||||
func TestImClient_CreateChatGroup(t *testing.T) {
|
||||
client := &ImClient{
|
||||
AppKey: "543b1a440b940b170fccdf494839efc01",
|
||||
AppSecret: "41134093938f1",
|
||||
}
|
||||
groupId, err := client.CreateChatGroup(context.Background(), "e1fbefbbd77a402e8c2101a0ebe15f5d", "测试群", []string{"e1fbefbbd77a402e8c2101a0ebe15f5d"})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
println(groupId)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// viper.SetConfigName("dev.yaml")
|
||||
// viper.AddConfigPath("../../../configs/admin/")
|
||||
// viper.SetConfigType("yaml")
|
||||
// _ = viper.ReadInConfig()
|
||||
// log.Init()
|
||||
// datasource.InitMySQlMaster()
|
||||
}
|
||||
Reference in New Issue
Block a user