Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"http.go",
"mc.go",
"mysql.go",
],
importpath = "go-common/app/service/main/member/dao/block",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/member/conf:go_default_library",
"//app/service/main/member/model/block:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/time:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"http_test.go",
"mc_test.go",
"mysql_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/member/conf:go_default_library",
"//app/service/main/member/model/block:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/sql:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,97 @@
package block
import (
"context"
"math"
"math/rand"
"time"
"go-common/app/service/main/member/conf"
"go-common/library/cache/memcache"
"go-common/library/database/sql"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
xtime "go-common/library/time"
"github.com/pkg/errors"
)
type notifyFunc func(context.Context, int64, string) error
// Dao is
type Dao struct {
*cacheTTL
c *conf.Config
mc *memcache.Pool
db *sql.DB
client *bm.Client
NotifyPurgeCache notifyFunc
}
type cacheTTL struct {
UserTTL int32
UserMaxRate float64
UserT float64
}
// New is
func New(conf *conf.Config, db *sql.DB, mc *memcache.Pool, client *bm.Client, notifyFunc notifyFunc) *Dao {
d := &Dao{
c: conf,
mc: mc,
db: db,
client: client,
NotifyPurgeCache: notifyFunc,
}
d.cacheTTL = newCacheTTL(conf.BlockCacheTTL)
return d
}
// BeginTran is
func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
if tx, err = d.db.Begin(c); err != nil {
err = errors.WithStack(err)
}
return
}
func durationToSeconds(expire xtime.Duration) int32 {
return int32(time.Duration(expire) / time.Second)
}
func newCacheTTL(c *conf.BlockCacheTTL) *cacheTTL {
return &cacheTTL{
UserTTL: durationToSeconds(c.UserTTL),
UserMaxRate: c.UserMaxRate,
UserT: c.UserT,
}
}
func (ttl *cacheTTL) mcUserExpire(key string) (sec int32) {
if ttl.UserT == 0.0 {
return ttl.UserTTL
}
// rate = -log(1-x)/t
rate := -math.Log(1-rand.Float64()) / ttl.UserT
if rate <= 1.0 {
return ttl.UserTTL
}
if rate > ttl.UserMaxRate {
rate = ttl.UserMaxRate
}
sec = int32(rate * float64(ttl.UserTTL))
if rate >= 5.0 {
log.Info("mc hotkey : %s, expire rate : %.2f , time : %d", key, rate, sec)
}
return
}
// Close close the resource.
func (d *Dao) Close() {
if d.mc != nil {
d.mc.Close()
}
if d.db != nil {
d.db.Close()
}
}

View File

@@ -0,0 +1,43 @@
package block
import (
"flag"
"os"
"testing"
"go-common/app/service/main/member/conf"
"go-common/library/cache/memcache"
"go-common/library/database/sql"
bm "go-common/library/net/http/blademaster"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.account.member-service")
flag.Set("conf_token", "ef70dbff7ee115ce242c67e633b21c29")
flag.Set("tree_id", "2137")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
c := conf.Conf
d = New(c,
sql.NewMySQL(c.BlockMySQL),
memcache.NewPool(c.BlockMemcache),
bm.NewClient(c.HTTPClient),
nil,
)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,46 @@
package block
import (
"context"
"fmt"
"net/url"
"strings"
"go-common/library/ecode"
"github.com/pkg/errors"
)
// SendSysMsg send sys msg.
func (d *Dao) SendSysMsg(c context.Context, code string, mids []int64, title string, content string, remoteIP string) (err error) {
params := url.Values{}
params.Set("mc", code)
params.Set("title", title)
params.Set("data_type", "4")
params.Set("context", content)
params.Set("mid_list", midsToParam(mids))
var res struct {
Code int `json:"code"`
Data *struct {
Status int8 `json:"status"`
Remark string `json:"remark"`
} `json:"data"`
}
if err = d.client.Post(c, d.c.BlockProperty.MSGURL, remoteIP, params, &res); err != nil {
err = errors.WithStack(err)
return
}
if res.Code != 0 {
err = errors.WithStack(ecode.Int(res.Code))
return
}
return
}
func midsToParam(mids []int64) (str string) {
strs := make([]string, 0, len(mids))
for _, mid := range mids {
strs = append(strs, fmt.Sprintf("%d", mid))
}
return strings.Join(strs, ",")
}

View File

@@ -0,0 +1,41 @@
package block
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSendSysMsg(t *testing.T) {
convey.Convey("SendSysMsg", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{1, 2, 3}
content = "账号违规处理通知-test-content"
remoteIP = "127.0.0.1"
code = "2_3_2"
title = "账号违规处理通知-test"
)
ctx.Convey("When everything right", func(ctx convey.C) {
err := d.SendSysMsg(c, code, mids, title, content, remoteIP)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaomidsToParam(t *testing.T) {
convey.Convey("midsToParam", t, func(ctx convey.C) {
var (
mids = []int64{46333, 35858}
)
ctx.Convey("When everything right", func(ctx convey.C) {
str := midsToParam(mids)
ctx.Convey("Then str should equal mids[0],mids[1],....", func(ctx convey.C) {
ctx.So(str, convey.ShouldEqual, "46333,35858")
})
})
})
}

View File

@@ -0,0 +1,171 @@
package block
import (
"context"
"fmt"
model "go-common/app/service/main/member/model/block"
"go-common/library/cache/memcache"
"go-common/library/log"
"github.com/pkg/errors"
)
func userKey(mid int64) (key string) {
key = fmt.Sprintf("u_%d", mid)
return
}
func userDetailKey(mid int64) (key string) {
key = fmt.Sprintf("ud_%d", mid)
return
}
// UsersCache get block info by mids
func (d *Dao) UsersCache(c context.Context, mids []int64) (res map[int64]*model.MCBlockInfo, err error) {
res = make(map[int64]*model.MCBlockInfo, len(mids))
if len(mids) == 0 {
return
}
var (
keys = make([]string, 0, len(mids))
keyMap = make(map[string]int64, len(mids))
key string
conn = d.mc.Get(c)
rs map[string]*memcache.Item
)
defer conn.Close()
for _, mid := range mids {
key = userKey(mid)
if _, ok := keyMap[key]; !ok {
keyMap[key] = mid
keys = append(keys, key)
}
}
if rs, err = conn.GetMulti(keys); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
err = errors.Wrapf(err, "keys : %+v", keys)
return
}
for k, r := range rs {
info := &model.MCBlockInfo{}
if err = conn.Scan(r, info); err != nil {
err = errors.Wrapf(err, "key : %s", k)
log.Error("%+v", err)
err = nil
continue
}
res[keyMap[k]] = info
}
return
}
// SetUserCache set user block info to cache
func (d *Dao) SetUserCache(c context.Context, mid int64, status model.BlockStatus, startTime, endTime int64) (err error) {
var (
key = userKey(mid)
conn = d.mc.Get(c)
info = &model.MCBlockInfo{
BlockStatus: status,
StartTime: startTime,
EndTime: endTime,
}
)
log.Info("Set User Cache key (%s) obj (%+v)", key, info)
defer conn.Close()
if err = conn.Set(&memcache.Item{
Key: key,
Object: info,
Expiration: d.mcUserExpire(key),
Flags: memcache.FlagJSON,
}); err != nil {
err = (err)
return
}
return
}
// DeleteUserCache delete user cache
func (d *Dao) DeleteUserCache(c context.Context, mid int64) (err error) {
var (
key = userKey(mid)
conn = d.mc.Get(c)
)
defer conn.Close()
if err = conn.Delete(key); err != nil {
err = (err)
return
}
return
}
// SetUserDetailCache set user detail to cache
func (d *Dao) SetUserDetailCache(c context.Context, mid int64, detail *model.MCUserDetail) (err error) {
var (
key = userDetailKey(mid)
conn = d.mc.Get(c)
)
log.Info("Set User Detail Cache key (%s) obj (%+v)", key, detail)
defer conn.Close()
if err = conn.Set(&memcache.Item{
Key: key,
Object: detail,
Expiration: d.mcUserExpire(key),
Flags: memcache.FlagJSON,
}); err != nil {
return
}
return
}
// DeleteUserDetailCache delete user detail cache
func (d *Dao) DeleteUserDetailCache(c context.Context, mid int64) (err error) {
var (
key = userDetailKey(mid)
conn = d.mc.Get(c)
)
defer conn.Close()
err = conn.Delete(key)
return
}
// UserDetailsCache .
func (d *Dao) UserDetailsCache(c context.Context, mids []int64) (res map[int64]*model.MCUserDetail, err error) {
res = make(map[int64]*model.MCUserDetail)
if len(mids) == 0 {
return
}
var (
keys = make([]string, 0, len(mids))
keyMap = make(map[string]int64, len(mids))
key string
conn = d.mc.Get(c)
rs map[string]*memcache.Item
)
defer conn.Close()
for _, mid := range mids {
key = userDetailKey(mid)
if _, ok := keyMap[key]; !ok {
keyMap[key] = mid
keys = append(keys, key)
}
}
if rs, err = conn.GetMulti(keys); err != nil {
err = errors.Wrapf(err, "keys : %+v", keys)
return
}
for k, r := range rs {
detail := &model.MCUserDetail{}
if err = conn.Scan(r, detail); err != nil {
err = errors.Wrapf(err, "key : %+v", k)
log.Error("%+v", err)
err = nil
continue
}
res[keyMap[k]] = detail
}
return
}

View File

@@ -0,0 +1,99 @@
package block
import (
"context"
"testing"
"time"
"go-common/app/service/main/member/conf"
model "go-common/app/service/main/member/model/block"
"github.com/smartystreets/goconvey/convey"
)
func TestDaouserKey(t *testing.T) {
convey.Convey("userKey", t, func(ctx convey.C) {
var (
mid = int64(46333)
)
ctx.Convey("When everything right", func(ctx convey.C) {
key := userKey(mid)
ctx.Convey("Then key should equal u_mid.", func(ctx convey.C) {
ctx.So(key, convey.ShouldEqual, "u_46333")
})
})
})
}
func TestDaoSetUserCache(t *testing.T) {
convey.Convey("SetUserCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(46333)
status = model.BlockStatusForever
startTime = time.Now().Unix()
endTime = time.Now().Add(time.Minute).Unix()
)
ctx.Convey("When SetUserCache", func(ctx convey.C) {
err := d.SetUserCache(c, mid, status, startTime, endTime)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.Convey("When get UsersCache", func(ctx convey.C) {
res, err := d.UsersCache(c, []int64{mid})
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
ctx.Convey("When delete UsersCache", func(ctx convey.C) {
err := d.DeleteUserCache(c, mid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
})
})
}
func TestDaomcUserExpire(t *testing.T) {
convey.Convey("mcUserExpire", t, func(ctx convey.C) {
ctx.Convey("When everything right", func(ctx convey.C) {
sec := d.mcUserExpire("ut_key")
ctx.Convey("Then sec should >=mcUserExpireBase and <=mcUserExpireBase*conf.Conf.Memcache.Expire.UserMaxRate .", func(ctx convey.C) {
ctx.So(d.UserTTL, convey.ShouldBeGreaterThan, 0)
ctx.So(conf.Conf.BlockCacheTTL.UserMaxRate, convey.ShouldBeGreaterThan, 0)
ctx.So(sec, convey.ShouldBeGreaterThanOrEqualTo, d.UserTTL)
ctx.So(sec, convey.ShouldBeLessThanOrEqualTo, int32(conf.Conf.BlockCacheTTL.UserMaxRate*float64(d.UserTTL)))
})
})
})
}
func TestDaoSetUserDetailCache(t *testing.T) {
convey.Convey("SetUserDetailCache", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(46333)
)
ctx.Convey("When SetUserDetailCache", func(ctx convey.C) {
err := d.SetUserDetailCache(c, mid, &model.MCUserDetail{BlockCount: 12})
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.Convey("When get UserDetailCache", func(ctx convey.C) {
res, err := d.UserDetailsCache(c, []int64{mid})
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
ctx.Convey("When delete UsersDetailCache", func(ctx convey.C) {
err := d.DeleteUserDetailCache(c, mid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
})
})
}

View File

@@ -0,0 +1,184 @@
package block
import (
"context"
"fmt"
model "go-common/app/service/main/member/model/block"
xsql "go-common/library/database/sql"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_user = `SELECT id,mid,status,ctime,mtime FROM block_user WHERE mid=? LIMIT 1`
_upsertUser = `INSERT INTO block_user (mid,status) VALUES (?,?) ON DUPLICATE KEY UPDATE status=?`
_userStatusList = `SELECT id,mid FROM block_user WHERE status=? AND id >= 0 LIMIT ?`
_userStatusListWithMIDs = `SELECT mid FROM block_user WHERE status=? AND mid IN (%s)`
_userLastHistory = `SELECT id,mid,action,start_time,duration FROM block_history_%d WHERE mid=? ORDER BY id DESC LIMIT 1`
_addAddBlockCount = `INSERT INTO block_user_detail (mid,block_count) VALUES (?,1) ON DUPLICATE KEY UPDATE block_count=block_count+1`
_insertHistory = `INSERT INTO block_history_%d (mid,admin_id,admin_name,source,area,reason,comment,action,start_time,duration,notify) VALUES (?,?,?,?,?,?,?,?,?,?,?)`
_userDetails = `SELECT id,mid,block_count,ctime,mtime FROM block_user_detail WHERE mid IN (%s)`
)
func historyIdx(mid int64) int64 {
return mid % 10
}
// User get block user from db
func (d *Dao) User(c context.Context, mid int64) (user *model.DBUser, err error) {
user = &model.DBUser{}
row := d.db.QueryRow(c, _user, mid)
if err = row.Scan(&user.ID, &user.MID, &user.Status, &user.CTime, &user.MTime); err != nil {
if err == xsql.ErrNoRows {
err = nil
user = nil
return
}
err = errors.WithStack(err)
return
}
return
}
// UserLastHistory get lastest block history
func (d *Dao) UserLastHistory(c context.Context, mid int64) (his *model.DBHistory, err error) {
var (
sql = fmt.Sprintf(_userLastHistory, historyIdx(mid))
)
row := d.db.QueryRow(c, sql, mid)
his = &model.DBHistory{}
if err = row.Scan(&his.ID, &his.MID, &his.Action, &his.StartTime, &his.Duration); err != nil {
if err == xsql.ErrNoRows {
err = nil
his = nil
return
}
err = errors.WithStack(err)
return
}
return
}
// UserStatusList get user status list
func (d *Dao) UserStatusList(c context.Context, status model.BlockStatus, startID int64, limit int) (maxID int64, mids []int64, err error) {
var (
rows *xsql.Rows
)
if rows, err = d.db.Query(c, _userStatusList, status, startID, limit); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
var (
id, mid int64
)
if err = rows.Scan(&id, &mid); err != nil {
err = errors.WithStack(err)
return
}
if maxID < id {
maxID = id
}
mids = append(mids, mid)
}
if err = rows.Err(); err != nil {
err = errors.WithStack(err)
return
}
return
}
// UserStatusMapWithMIDs get user block status map by mids
func (d *Dao) UserStatusMapWithMIDs(c context.Context, status model.BlockStatus, mids []int64) (midMap map[int64]struct{}, err error) {
var (
rows *xsql.Rows
)
url := fmt.Sprintf(_userStatusListWithMIDs, xstr.JoinInts(mids))
if rows, err = d.db.Query(c, url, status); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
midMap = make(map[int64]struct{})
for rows.Next() {
var (
mid int64
)
if err = rows.Scan(&mid); err != nil {
err = errors.WithStack(err)
return
}
midMap[mid] = struct{}{}
}
if err = rows.Err(); err != nil {
err = errors.WithStack(err)
return
}
return
}
// TxUpdateUser is
func (d *Dao) TxUpdateUser(c context.Context, tx *xsql.Tx, mid int64, status model.BlockStatus) (err error) {
if _, err = tx.Exec(_upsertUser, mid, status, status); err != nil {
err = errors.WithStack(err)
return
}
return
}
// UpdateAddBlockCount is
func (d *Dao) UpdateAddBlockCount(c context.Context, mid int64) (err error) {
if _, err = d.db.Exec(c, _addAddBlockCount, mid); err != nil {
err = errors.WithStack(err)
return
}
return
}
// TxInsertHistory is
func (d *Dao) TxInsertHistory(c context.Context, tx *xsql.Tx, h *model.DBHistory) (err error) {
var (
sql = fmt.Sprintf(_insertHistory, historyIdx(h.MID))
)
if _, err = tx.Exec(sql, h.MID, h.AdminID, h.AdminName, h.Source, h.Area, h.Reason, h.Comment, h.Action, h.StartTime, h.Duration, h.Notify); err != nil {
err = errors.WithStack(err)
return
}
return
}
// UserDetails .
func (d *Dao) UserDetails(c context.Context, mids []int64) (midMap map[int64]*model.DBUserDetail, err error) {
var (
rows *xsql.Rows
)
sql := fmt.Sprintf(_userDetails, xstr.JoinInts(mids))
if rows, err = d.db.Query(c, sql); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
midMap = make(map[int64]*model.DBUserDetail, len(mids))
for rows.Next() {
detail := &model.DBUserDetail{}
if err = rows.Scan(&detail.ID, &detail.MID, &detail.BlockCount, &detail.CTime, &detail.MTime); err != nil {
err = errors.WithStack(err)
return
}
midMap[detail.MID] = detail
}
if err = rows.Err(); err != nil {
err = errors.WithStack(err)
return
}
return
}

View File

@@ -0,0 +1,150 @@
package block
import (
"context"
"testing"
"time"
model "go-common/app/service/main/member/model/block"
"github.com/smartystreets/goconvey/convey"
)
func TestDaohistoryIdx(t *testing.T) {
convey.Convey("historyIdx", t, func(ctx convey.C) {
var (
mid = int64(46333)
)
ctx.Convey("When everything right", func(ctx convey.C) {
shard := historyIdx(mid)
ctx.Convey("Then shard should equal mid % 10.", func(ctx convey.C) {
ctx.So(shard, convey.ShouldEqual, 3)
})
})
})
}
func TestDaoUser(t *testing.T) {
convey.Convey("User", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(46333)
)
ctx.Convey("When everything right", func(ctx convey.C) {
user, err := d.User(c, mid)
ctx.Convey("Then err should be nil.user should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(user, convey.ShouldNotBeNil)
ctx.So(user.MID, convey.ShouldEqual, mid)
})
})
})
}
func TestDaoTxInsertHistory(t *testing.T) {
convey.Convey("TxInsertHistory", t, func(ctx convey.C) {
var (
c = context.Background()
tx, _ = d.db.Begin(c)
his = &model.DBHistory{
MID: 46333,
AdminID: 2333,
AdminName: "ut",
Source: model.BlockSourceBlackHouse,
Area: model.BlockAreaAlbum,
Reason: "ut reason",
Comment: "ut comment",
Action: model.BlockActionLimit,
StartTime: time.Now(),
Duration: 60,
Notify: false,
CTime: time.Now(),
MTime: time.Now(),
}
)
ctx.Convey("When everything right", func(ctx convey.C) {
err := d.TxInsertHistory(c, tx, his)
ctx.So(err, convey.ShouldBeNil)
err = tx.Commit()
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.Convey("When get UserLastHistory", func(ctx convey.C) {
his2, err := d.UserLastHistory(c, his.MID)
ctx.Convey("Then err should be nil.his2 should resemble his.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(his2.MID, convey.ShouldEqual, his.MID)
ctx.So(his2.Action, convey.ShouldEqual, his.Action)
ctx.So(his2.StartTime.Unix(), convey.ShouldEqual, his.StartTime.Unix())
ctx.So(his2.Duration, convey.ShouldEqual, his.Duration)
})
})
})
})
})
}
func TestDaoTxUpdateUser(t *testing.T) {
var (
c = context.Background()
tx, _ = d.db.Begin(c)
mid = int64(46333)
status = model.BlockStatusFalse
)
convey.Convey("TxUpdateUser", t, func(ctx convey.C) {
ctx.Convey("When everything right", func(ctx convey.C) {
err := d.TxUpdateUser(c, tx, mid, status)
ctx.So(err, convey.ShouldBeNil)
err = tx.Commit()
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUserStatusMapWithMIDs(t *testing.T) {
convey.Convey("UserStatusMapWithMIDs", t, func(ctx convey.C) {
var (
c = context.Background()
status = model.BlockStatusFalse
mids = []int64{46333, 2, 35858}
)
ctx.Convey("When everything right", func(ctx convey.C) {
midMap, err := d.UserStatusMapWithMIDs(c, status, mids)
ctx.Convey("Then err should be nil.midMap should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(midMap, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoUpdateAddBlockCount(t *testing.T) {
convey.Convey("UpdateAddBlockCount", t, func(ctx convey.C) {
var (
c = context.TODO()
mid = int64(46333)
)
ctx.Convey("When everything right", func(ctx convey.C) {
err := d.UpdateAddBlockCount(c, mid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestUserDetails(t *testing.T) {
convey.Convey("get user details", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(46333)
)
ctx.Convey("When get user details from db", func(ctx convey.C) {
_, err := d.UserDetails(c, []int64{mid})
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}