Add test
This commit is contained in:
parent
3c1c7c738c
commit
bef84a0176
@ -67,7 +67,7 @@ func (fm *FriendsMgr) searchFriends(searchKeyword string) []*User {
|
||||
}
|
||||
}
|
||||
|
||||
listFriend := make([]*User, 10)
|
||||
var listFriend []*User
|
||||
lowercaseQuery := strings.ToLower(searchKeyword)
|
||||
for _, u := range fm.users {
|
||||
if strings.Contains(strings.ToLower(u.Username), lowercaseQuery) {
|
||||
@ -174,7 +174,7 @@ func (fm *FriendsMgr) rejectFriendRequest(user1Id string, user2Id string) error
|
||||
// CMListFriend 我的好友列表
|
||||
func (fm *FriendsMgr) listFriend(accountId string) []*User {
|
||||
// By default, Users member data count:10
|
||||
users := make([]*User, 10)
|
||||
var users []*User
|
||||
for _, friendship := range fm.friendships[accountId] {
|
||||
if friendship.User1.AccountId != accountId {
|
||||
uEntity := &User{
|
||||
@ -218,7 +218,7 @@ func (fm *FriendsMgr) loadUsersFromDB(conn *q5.Mysql) {
|
||||
// Load DB users to struct FriendsMgr.user
|
||||
rows, err := conn.Query("select account_id, name from t_user")
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("mysql error", err)
|
||||
f5.GetSysLog().Info("mysql error:%s\n", err)
|
||||
return
|
||||
}
|
||||
fm.users = make(map[string]*User)
|
||||
@ -237,7 +237,7 @@ func (fm *FriendsMgr) loadFriendshipsFromDB(conn *q5.Mysql) {
|
||||
// Load DB t_friend_ships to struct FriendsMgr.friendship
|
||||
rows, err := conn.Query("select account1_id, account2_id from t_friend_ships;")
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("mysql error", err)
|
||||
f5.GetSysLog().Info("mysql error:%s\n", err)
|
||||
return
|
||||
}
|
||||
fm.friendships = make(map[string][]*Friendship)
|
||||
@ -261,7 +261,7 @@ func (fm *FriendsMgr) loadFriendshipsFromDB(conn *q5.Mysql) {
|
||||
func (fm *FriendsMgr) loadPendingRequestsFromDB(conn *q5.Mysql) {
|
||||
rows, err := conn.Query("select sender_account_id, receiver_account_id, flag from t_pending_friend_requests;")
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("mysql error", err)
|
||||
f5.GetSysLog().Info("mysql error:%s\n", err)
|
||||
return
|
||||
}
|
||||
pendingReqs := make(map[string]map[string]bool, 10)
|
||||
|
33
server/imserver/friendsmgr_test.go
Normal file
33
server/imserver/friendsmgr_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRegisterUser(t *testing.T) {
|
||||
fm := &FriendsMgr{}
|
||||
|
||||
// init
|
||||
fm.users = make(map[string]*User, 10)
|
||||
fm.searchCaches = make(map[string]SearchCache, 10)
|
||||
fm.friendships = make(map[string][]*Friendship, 10)
|
||||
fm.pendingReqs = make(map[string]map[string]bool, 10)
|
||||
|
||||
// Register users
|
||||
fm.registerUser("1", "google")
|
||||
fm.registerUser("2", "apple")
|
||||
fm.registerUser("3", "sony")
|
||||
fm.registerUser("4", "panasonic")
|
||||
fmt.Printf("users: %d \n", len(fm.users))
|
||||
|
||||
// Search users
|
||||
searchResult := fm.searchFriends("a")
|
||||
fmt.Printf("search result count: %d \n", len(searchResult))
|
||||
|
||||
// Add friend request
|
||||
// google 申请添加 apple 好友
|
||||
fmt.Printf("after: pendingReqs count: %d \n", len(fm.pendingReqs))
|
||||
fm.addFriendRequest("1", "2")
|
||||
fmt.Printf("before: pendingReqs count: %d \n", len(fm.pendingReqs))
|
||||
}
|
@ -51,7 +51,7 @@ func (this *PlayerMgr) init() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
f5.GetSysLog().Info("mysql error", err)
|
||||
f5.GetSysLog().Info("mysql error:%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.Htt
|
||||
}{}
|
||||
err := json.Unmarshal([]byte(rsp.GetRawData()), &resObj)
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("Api服务器JSON 解析错误:", err)
|
||||
f5.GetSysLog().Info("Api服务器JSON 解析错误:%s\n", err)
|
||||
return
|
||||
}
|
||||
if resObj.Errcode != 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user