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,75 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"dao.cache_test.go",
"dao_test.go",
"mc.cache_test.go",
"up_group_test.go",
"up_mc_test.go",
"up_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/up/api/v1:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.cache.go",
"dao.go",
"mc.cache.go",
"up.go",
"up_group.go",
"up_mc.go",
],
importpath = "go-common/app/service/main/up/dao/manager",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/up/api/v1:go_default_library",
"//app/service/main/up/conf:go_default_library",
"//app/service/main/up/dao:go_default_library",
"//app/service/main/up/dao/global:go_default_library",
"//app/service/main/up/model:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/stat/prom:go_default_library",
"//library/sync/errgroup:go_default_library",
"//library/sync/pipeline/fanout:go_default_library",
"//library/xstr: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"],
)

View File

@@ -0,0 +1,139 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package manager is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache: -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpSpecial(c context.Context, mid int64) (us *upgrpc.UpSpecial, err error)
// cache: -batch=100 -max_group=1 -batch_err=break -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpsSpecial(c context.Context, mids []int64) (map[int64]*upgrpc.UpSpecial, error)
}
*/
package manager
import (
"context"
"sync"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/library/stat/prom"
"go-common/library/sync/errgroup"
)
var _ _cache
// UpSpecial get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpSpecial(c context.Context, id int64) (res *upgrpc.UpSpecial, err error) {
addCache := true
res, err = d.CacheUpSpecial(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if res != nil && len(res.GroupIDs) > 0 && res.GroupIDs[0] == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("UpSpecial")
return
}
prom.CacheMiss.Incr("UpSpecial")
res, err = d.RawUpSpecial(c, id)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &upgrpc.UpSpecial{GroupIDs: []int64{-1}}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpSpecial(c, id, miss)
})
return
}
// UpsSpecial get data from cache if miss will call source method, then add to cache.
func (d *Dao) UpsSpecial(c context.Context, keys []int64) (res map[int64]*upgrpc.UpSpecial, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheUpsSpecial(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("UpsSpecial", int64(len(keys)-len(miss)))
for k, v := range res {
if v != nil && len(v.GroupIDs) > 0 && v.GroupIDs[0] == -1 {
delete(res, k)
}
}
missLen := len(miss)
if missLen == 0 {
return
}
missData := make(map[int64]*upgrpc.UpSpecial, missLen)
prom.CacheMiss.Add("UpsSpecial", int64(missLen))
var mutex sync.Mutex
group, ctx := errgroup.WithContext(c)
if missLen > 1 {
group.GOMAXPROCS(1)
}
var run = func(ms []int64) {
group.Go(func() (err error) {
data, err := d.RawUpsSpecial(ctx, ms)
mutex.Lock()
for k, v := range data {
missData[k] = v
}
mutex.Unlock()
return
})
}
var (
i int
n = missLen / 100
)
for i = 0; i < n; i++ {
run(miss[i*n : (i+1)*n])
}
if len(miss[i*n:]) > 0 {
run(miss[i*n:])
}
err = group.Wait()
if res == nil {
res = make(map[int64]*upgrpc.UpSpecial, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
for _, key := range miss {
if res[key] == nil {
missData[key] = &upgrpc.UpSpecial{GroupIDs: []int64{-1}}
}
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheUpsSpecial(c, missData)
})
return
}

View File

@@ -0,0 +1,40 @@
package manager
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerUpSpecial(t *testing.T) {
convey.Convey("UpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(27515256)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.UpSpecial(c, id)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestManagerUpsSpecial(t *testing.T) {
convey.Convey("UpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
keys = []int64{27515256}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.UpsSpecial(c, keys)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,146 @@
package manager
import (
"context"
gosql "database/sql"
"net/url"
"strings"
"time"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao/global"
"go-common/library/cache/memcache"
"go-common/library/database/sql"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/sync/pipeline/fanout"
"go-common/library/xstr"
)
const (
//URLUNames url for names
URLUNames = "/x/admin/manager/users/unames"
//URLUids url for uids
URLUids = "/x/admin/manager/users/uids"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
managerDB *sql.DB
HTTPClient *bm.Client
// cache tool
cache *fanout.Fanout
// mc
mc *memcache.Pool
// upSpecial expiration
upSpecialExpire int32
}
// New fn
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
managerDB: sql.NewMySQL(c.DB.Manager),
// http client
HTTPClient: bm.NewClient(c.HTTPClient.Normal),
mc: memcache.NewPool(c.Memcache.Up),
upSpecialExpire: int32(time.Duration(c.Memcache.UpSpecialExpire) / time.Second),
cache: global.GetWorker(),
}
return d
}
// Close fn
func (d *Dao) Close() {
if d.managerDB != nil {
d.managerDB.Close()
}
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return d.managerDB.Ping(c)
}
func prepareAndExec(c context.Context, db *sql.DB, sqlstr string, args ...interface{}) (res gosql.Result, err error) {
var stmt *sql.Stmt
stmt, err = db.Prepare(sqlstr)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, sqlstr)
return
}
defer stmt.Close()
res, err = stmt.Exec(c, args...)
if err != nil {
log.Error("data base fail, err=%v", err)
return
}
return
}
func prepareAndQuery(c context.Context, db *sql.DB, sqlstr string, args ...interface{}) (rows *sql.Rows, err error) {
var stmt *sql.Stmt
stmt, err = db.Prepare(sqlstr)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, sqlstr)
return
}
defer stmt.Close()
rows, err = stmt.Query(c, args...)
if err != nil {
log.Error("data base fail, err=%v", err)
return
}
return
}
//GetUNamesByUids get uname by uid
func (d *Dao) GetUNamesByUids(c context.Context, uids []int64) (res map[int64]string, err error) {
var param = url.Values{}
var uidStr = xstr.JoinInts(uids)
param.Set("uids", uidStr)
var httpRes struct {
Code int `json:"code"`
Data map[int64]string `json:"data"`
Message string `json:"message"`
}
err = d.HTTPClient.Get(c, d.c.Host.Manager+URLUNames, "", param, &httpRes)
if err != nil {
log.Error("d.client.Get(%s) error(%v)", d.c.Host.Manager+URLUNames+"?"+param.Encode(), err)
return
}
if httpRes.Code != 0 {
log.Error("url(%s) error(%v), code(%d), message(%s)", d.c.Host.Manager+URLUNames+"?"+param.Encode(), err, httpRes.Code, httpRes.Message)
}
res = httpRes.Data
return
}
//GetUIDByNames get uid by uname
func (d *Dao) GetUIDByNames(c context.Context, names []string) (res map[string]int64, err error) {
var param = url.Values{}
var namesStr = strings.Join(names, ",")
param.Set("unames", namesStr)
var httpRes struct {
Code int `json:"code"`
Data map[string]int64 `json:"data"`
Message string `json:"message"`
}
err = d.HTTPClient.Get(c, d.c.Host.Manager+URLUids, "", param, &httpRes)
if err != nil {
log.Error("d.client.Get(%s) error(%v)", d.c.Host.Manager+URLUids+"?"+param.Encode(), err)
return
}
if httpRes.Code != 0 {
log.Error("url(%s) error(%v), code(%d), message(%s)", d.c.Host.Manager+URLUids+"?"+param.Encode(), err, httpRes.Code, httpRes.Message)
}
res = httpRes.Data
return
}

View File

@@ -0,0 +1,119 @@
package manager
import (
"context"
"flag"
"os"
"testing"
"go-common/app/service/main/up/conf"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/dao/global"
"go-common/library/net/http/blademaster"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", dao.AppID)
flag.Set("conf_token", dao.UatToken)
flag.Set("tree_id", dao.TreeID)
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")
} else {
flag.Set("conf", "../../cmd/up-service.toml")
}
if os.Getenv("UT_LOCAL_TEST") != "" {
flag.Set("conf", "../../cmd/up-service.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
global.Init(conf.Conf)
d = New(conf.Conf)
d.HTTPClient = blademaster.NewClient(conf.Conf.HTTPClient.Normal)
m.Run()
os.Exit(0)
}
func TestManagerPing(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Ping", t, func(ctx convey.C) {
err := d.Ping(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestManagerprepareAndExec(t *testing.T) {
var (
c = context.TODO()
db = d.managerDB
sqlstr = _selectByID
args = interface{}(0)
)
convey.Convey("prepareAndExec", t, func(ctx convey.C) {
res, err := prepareAndExec(c, db, sqlstr, args)
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)
})
})
}
func TestManagerprepareAndQuery(t *testing.T) {
var (
c = context.TODO()
db = d.managerDB
sqlstr = _selectByID
args = interface{}(0)
)
convey.Convey("prepareAndQuery", t, func(ctx convey.C) {
rows, err := prepareAndQuery(c, db, sqlstr, args)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
}
func TestManagerGetUNamesByUids(t *testing.T) {
var (
c = context.TODO()
uids = []int64{100}
)
convey.Convey("GetUNamesByUids", t, func(ctx convey.C) {
res, err := d.GetUNamesByUids(c, uids)
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)
})
})
}
func TestManagerGetUIDByNames(t *testing.T) {
var (
c = context.TODO()
names = []string{"wangzhe01"}
)
convey.Convey("GetUIDByNames", t, func(ctx convey.C) {
res, err := d.GetUIDByNames(c, names)
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)
})
})
}

View File

@@ -0,0 +1,172 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package manager is a generated mc cache package.
It is generated from:
type _mc interface {
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpSpecial(c context.Context, mid int64, us *upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpSpecial(c context.Context, mid int64) (res *upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpSpecial(c context.Context, mid int64) (err error)
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpsSpecial(c context.Context, mu map[int64]*upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpsSpecial(c context.Context, mid []int64) (res map[int64]*upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpsSpecial(c context.Context, mids []int64) (err error)
}
*/
package manager
import (
"context"
"fmt"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// AddCacheUpSpecial Set data to mc
func (d *Dao) AddCacheUpSpecial(c context.Context, id int64, val *upgrpc.UpSpecial) (err error) {
if val == nil {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := upSpecialCacheKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upSpecialExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpSpecial")
log.Errorv(c, log.KV("AddCacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// CacheUpSpecial get data from mc
func (d *Dao) CacheUpSpecial(c context.Context, id int64) (res *upgrpc.UpSpecial, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upSpecialCacheKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheUpSpecial")
log.Errorv(c, log.KV("CacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &upgrpc.UpSpecial{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpSpecial")
log.Errorv(c, log.KV("CacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheUpSpecial delete data from mc
func (d *Dao) DelCacheUpSpecial(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := upSpecialCacheKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheUpSpecial")
log.Errorv(c, log.KV("DelCacheUpSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheUpsSpecial Set data to mc
func (d *Dao) AddCacheUpsSpecial(c context.Context, values map[int64]*upgrpc.UpSpecial) (err error) {
if len(values) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
for id, val := range values {
key := upSpecialCacheKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: d.upSpecialExpire, Flags: memcache.FlagProtobuf}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheUpsSpecial")
log.Errorv(c, log.KV("AddCacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}
// CacheUpsSpecial get data from mc
func (d *Dao) CacheUpsSpecial(c context.Context, ids []int64) (res map[int64]*upgrpc.UpSpecial, err error) {
l := len(ids)
if l == 0 {
return
}
keysMap := make(map[string]int64, l)
keys := make([]string, 0, l)
for _, id := range ids {
key := upSpecialCacheKey(id)
keysMap[key] = id
keys = append(keys, key)
}
conn := d.mc.Get(c)
defer conn.Close()
replies, err := conn.GetMulti(keys)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpsSpecial")
log.Errorv(c, log.KV("CacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("keys", keys))
return
}
for key, reply := range replies {
var v *upgrpc.UpSpecial
v = &upgrpc.UpSpecial{}
err = conn.Scan(reply, v)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheUpsSpecial")
log.Errorv(c, log.KV("CacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
if res == nil {
res = make(map[int64]*upgrpc.UpSpecial, len(keys))
}
res[keysMap[key]] = v
}
return
}
// DelCacheUpsSpecial delete data from mc
func (d *Dao) DelCacheUpsSpecial(c context.Context, ids []int64) (err error) {
if len(ids) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
for _, id := range ids {
key := upSpecialCacheKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
continue
}
prom.BusinessErrCount.Incr("mc:DelCacheUpsSpecial")
log.Errorv(c, log.KV("DelCacheUpsSpecial", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}

View File

@@ -0,0 +1,102 @@
package manager
import (
"context"
upgrpc "go-common/app/service/main/up/api/v1"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerAddCacheUpSpecial(t *testing.T) {
convey.Convey("AddCacheUpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(0)
val = &upgrpc.UpSpecial{}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.AddCacheUpSpecial(c, id, val)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestManagerCacheUpSpecial(t *testing.T) {
convey.Convey("CacheUpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(0)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.CacheUpSpecial(c, id)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestManagerDelCacheUpSpecial(t *testing.T) {
convey.Convey("DelCacheUpSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
id = int64(0)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.DelCacheUpSpecial(c, id)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestManagerAddCacheUpsSpecial(t *testing.T) {
convey.Convey("AddCacheUpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
values map[int64]*upgrpc.UpSpecial
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.AddCacheUpsSpecial(c, values)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestManagerCacheUpsSpecial(t *testing.T) {
convey.Convey("CacheUpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
ids = []int64{27515256}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
res, err := d.CacheUpsSpecial(c, ids)
convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
convCtx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestManagerDelCacheUpsSpecial(t *testing.T) {
convey.Convey("DelCacheUpsSpecial", t, func(convCtx convey.C) {
var (
c = context.Background()
ids = []int64{}
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
err := d.DelCacheUpsSpecial(c, ids)
convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
convCtx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,372 @@
package manager
import (
"context"
"database/sql"
"errors"
"fmt"
"strings"
"time"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_upsWithGroupBase = "SELECT ups.id,mid,up_group.id as group_id ,up_group.short_tag as group_tag,up_group.name as group_name,ups.note,ups.ctime, ups.mtime, ups.uid FROM ups INNER JOIN up_group on ups.type=up_group.id "
_upsWithGroupBaseWithColor = "SELECT ups.id,mid,up_group.id as group_id ,up_group.short_tag as group_tag,up_group.name as group_name,ups.note,ups.ctime, ups.mtime, ups.uid, up_group.colors FROM ups INNER JOIN up_group on ups.type=up_group.id "
_upsWithGroup = _upsWithGroupBaseWithColor + "limit ? offset ? "
_upsWithGroupByMtime = _upsWithGroupBaseWithColor + "where ups.mtime >= ?"
_delByMid = "DELETE FROM ups where id = ?"
_insertMidType = "INSERT INTO ups (mid, type, note, ctime, mtime, uid) values "
_selectByMidTypeWithGroup = _upsWithGroupBase + "where mid = ? and type = ?"
_updateByID = "update ups set type=?, note=?, uid=?, mtime=? where id = ?"
//MysqlTimeFormat mysql time format
MysqlTimeFormat = "2006-01-02 15:04:05"
_selectByID = _upsWithGroupBase + "where ups.id = ?"
_selectCount = "SELECT COUNT(0) FROM ups INNER JOIN up_group on ups.type=up_group.id "
_upSpecialSQL = "SELECT type FROM ups WHERE mid = ?"
_upsSpecialSQL = "SELECT mid, type FROM ups WHERE mid IN (%s)"
_upGroupsMidsSQL = "SELECT id, mid, type FROM ups WHERE id > ? AND type IN (%s) LIMIT ?"
)
// UpSpecials load all ups with group info
func (d *Dao) UpSpecials(c context.Context) (ups []*model.UpSpecial, err error) {
log.Info("start refresh ups table")
stmt, err := d.managerDB.Prepare(_upsWithGroup)
if err != nil {
log.Error("d.managerDB.Prepare error(%v)", err)
return
}
defer stmt.Close()
var offset = 0
var limit = 1000
var cnt = 0
var isFirst = true
for isFirst || cnt == limit {
isFirst = false
rows, err1 := stmt.Query(c, limit, offset)
if err1 != nil {
err = err1
log.Error("stmt.Query error(%v)", err1)
return
}
cnt = 0
for rows.Next() {
cnt++
var up *model.UpSpecial
up, err = parseUpGroupWithColor(rows)
ups = append(ups, up)
}
rows.Close()
if err != nil {
return
}
log.Info("reading data from table, read count=%d", cnt)
offset += cnt
}
log.Info("end refresh ups table, read count=%d", offset)
return
}
//RefreshUpSpecialIncremental refresh cache incrementally
func (d *Dao) RefreshUpSpecialIncremental(c context.Context, lastMTime time.Time) (ups []*model.UpSpecial, err error) {
var timeStr = lastMTime.Format(MysqlTimeFormat)
log.Info("start refresh ups table mtime>%s", timeStr)
stmt, err := d.managerDB.Prepare(_upsWithGroupByMtime)
if err != nil {
log.Error("d.managerDB.Prepare error(%v)", err)
return
}
defer stmt.Close()
var cnt = 0
rows, err1 := stmt.Query(c, timeStr)
if err1 != nil {
err = err1
log.Error("stmt.Query error(%v)", err1)
return
}
cnt = 0
for rows.Next() {
cnt++
var up *model.UpSpecial
up, err = parseUpGroupWithColor(rows)
if err != nil {
log.Error("scan row err, %v", err)
break
}
ups = append(ups, up)
}
rows.Close()
if err != nil {
return
}
log.Info("reading data from table, read count=%d", cnt)
return
}
//DelSpecialByID delete special by id
func (d *Dao) DelSpecialByID(c context.Context, id int64) (res sql.Result, err error) {
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(_delByMid)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, _delByMid)
return
}
defer stmt.Close()
res, err = stmt.Exec(c, id)
if err != nil {
log.Error("delete mid from ups fail, id=%d, err=%v", id, err)
}
return
}
//InsertSpecial insert special
func (d *Dao) InsertSpecial(c context.Context, special *model.UpSpecial, mids ...int64) (res sql.Result, err error) {
var count = len(mids)
if count == 0 {
err = errors.New("no data need update")
return
}
var insertSchema []string
var vals []interface{}
var nowStr = time.Now().Format(MysqlTimeFormat)
for _, mid := range mids {
insertSchema = append(insertSchema, "(?,?,?,?,?,?)")
vals = append(vals, mid, special.GroupID, special.Note, nowStr, nowStr, special.UID)
}
var insertSQL = _insertMidType + strings.Join(insertSchema, ",")
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(insertSQL)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, insertSQL)
return
}
defer stmt.Close()
res, err = stmt.Exec(c, vals...)
if err != nil {
log.Error("insert ups fail, err=%v, groupid=%d, note=%s, mid=%v", err, special.GroupID, special.Note, mids)
}
return
}
//UpdateSpecialByID update special by id
func (d *Dao) UpdateSpecialByID(c context.Context, id int64, special *model.UpSpecial) (res sql.Result, err error) {
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(_updateByID)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, _updateByID)
return
}
defer stmt.Close()
var timeStr = time.Now().Format(MysqlTimeFormat)
res, err = stmt.Exec(c, special.GroupID, special.Note, special.UID, timeStr, id)
if err != nil {
log.Error("update ups fail, err=%v, groupid=%d, note=%s, id=%d", err, special.GroupID, special.Note, id)
}
return
}
//GetSpecialByMidGroup get special by mid and group
func (d *Dao) GetSpecialByMidGroup(c context.Context, mid int64, groupID int64) (res *model.UpSpecial, err error) {
var stmt *xsql.Stmt
stmt, err = d.managerDB.Prepare(_selectByMidTypeWithGroup)
if err != nil {
log.Error("stmt prepare fail, error(%v), sql=%s", err, _selectByMidTypeWithGroup)
return
}
defer stmt.Close()
row := stmt.QueryRow(c, mid, groupID)
var note sql.NullString
var up = model.UpSpecial{}
switch err = row.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime, &up.MTime, &up.UID); err {
case sql.ErrNoRows:
err = nil
return
case nil:
up.Note = note.String
res = &up
default:
log.Error("rows.Scan error(%v)", err)
return
}
return
}
//GetSpecialByID get special by id
func (d *Dao) GetSpecialByID(c context.Context, id int64) (res *model.UpSpecial, err error) {
rows, err := prepareAndQuery(c, d.managerDB, _selectByID, id)
if err != nil {
return
}
defer rows.Close()
var note sql.NullString
for rows.Next() {
var up = &model.UpSpecial{}
err = rows.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime, &up.MTime, &up.UID)
up.Note = note.String
res = up
break
}
return
}
//GetSepcialCount get special count
func (d *Dao) GetSepcialCount(c context.Context, conditions ...dao.Condition) (count int, err error) {
var conditionStr, args, hasOperator = dao.ConcatCondition(conditions...)
var where = " WHERE "
if !hasOperator {
where = ""
}
rows, err := prepareAndQuery(c, d.managerDB, _selectCount+where+conditionStr, args...)
if err != nil {
log.Error("get special db fail, err=%+v", err)
return
}
defer rows.Close()
for rows.Next() {
rows.Scan(&count)
}
return
}
func parseUpGroupWithColor(rows *xsql.Rows) (up *model.UpSpecial, err error) {
var note sql.NullString
var colors sql.NullString
up = &model.UpSpecial{}
err = rows.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime, &up.MTime, &up.UID, &colors)
if err != nil {
log.Error("scan row err, %v", err)
return
}
up.Note = note.String
if colors.Valid {
var colors = strings.Split(colors.String, "|")
if len(colors) >= 2 {
up.FontColor = colors[0]
up.BgColor = colors[1]
}
}
return
}
//GetSpecial get special from db
func (d *Dao) GetSpecial(c context.Context, conditions ...dao.Condition) (res []*model.UpSpecial, err error) {
var conditionStr, args, hasOperator = dao.ConcatCondition(conditions...)
var where = " WHERE "
if !hasOperator {
where = ""
}
rows, err := prepareAndQuery(c, d.managerDB, _upsWithGroupBaseWithColor+where+conditionStr, args...)
if err != nil {
log.Error("get special db fail, err=%+v", err)
return
}
defer rows.Close()
for rows.Next() {
var up *model.UpSpecial
up, err = parseUpGroupWithColor(rows)
if err != nil {
log.Error("scan row err, %v", err)
break
}
res = append(res, up)
}
return
}
//GetSpecialByMid get speical by mid
func (d *Dao) GetSpecialByMid(c context.Context, mid int64) (res []*model.UpSpecial, err error) {
var condition = dao.Condition{
Key: "ups.mid",
Operator: "=",
Value: mid,
}
return d.GetSpecial(c, condition)
}
// RawUpSpecial get up special propertys
func (d *Dao) RawUpSpecial(c context.Context, mid int64) (us *upgrpc.UpSpecial, err error) {
rows, err := d.managerDB.Query(c, _upSpecialSQL, mid)
if err != nil {
return
}
defer rows.Close()
us = new(upgrpc.UpSpecial)
for rows.Next() {
var groupID int64
if err = rows.Scan(&groupID); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
us.GroupIDs = append(us.GroupIDs, groupID)
}
return
}
// RawUpsSpecial get mult up special propertys
func (d *Dao) RawUpsSpecial(c context.Context, mids []int64) (mu map[int64]*upgrpc.UpSpecial, err error) {
rows, err := d.managerDB.Query(c, fmt.Sprintf(_upsSpecialSQL, xstr.JoinInts(mids)))
if err != nil {
return
}
defer rows.Close()
mu = make(map[int64]*upgrpc.UpSpecial, len(mids))
for rows.Next() {
var mid, groupID int64
if err = rows.Scan(&mid, &groupID); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
if mu[mid] == nil {
mu[mid] = new(upgrpc.UpSpecial)
}
mu[mid].GroupIDs = append(mu[mid].GroupIDs, groupID)
}
return
}
// UpGroupsMids get mids in one group.
func (d *Dao) UpGroupsMids(c context.Context, groupIDs []int64, lastID int64, ps int) (lid int64, gmids map[int64][]int64, err error) {
rows, err := d.managerDB.Query(c, fmt.Sprintf(_upGroupsMidsSQL, xstr.JoinInts(groupIDs)), lastID, ps)
if err != nil {
return
}
defer rows.Close()
gmids = make(map[int64][]int64)
for rows.Next() {
var id, gid, mid int64
if err = rows.Scan(&id, &mid, &gid); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
if id > lid {
lid = id
}
gmids[gid] = append(gmids[gid], mid)
}
return
}

View File

@@ -0,0 +1,138 @@
package manager
import (
"context"
"database/sql"
"fmt"
"strings"
upgrpc "go-common/app/service/main/up/api/v1"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/model"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
_insertGroup = "INSERT INTO up_group (name, tag, short_tag, colors, remark) VALUES (?,?,?,?,?)"
_checkGroupExist = "SELECT COUNT(0) FROM up_group WHERE (name=? OR tag=? OR short_tag=?) "
_updateGroupByID = "UPDATE up_group SET name=?, tag=?, short_tag=?, colors=?, remark=? WHERE id=?"
_removeGroupByID = "UPDATE up_group SET state=0 WHERE id=?"
_selectGroup = "SELECT id, name, tag, short_tag, remark, colors, state FROM up_group "
_upGroupsSQL = "SELECT id, name, tag, short_tag, remark, colors FROM up_group WHERE state = 1"
)
//AddGroup add group in db
func (d *Dao) AddGroup(c context.Context, groupAddInfo *model.AddGroupArg) (res sql.Result, err error) {
var color = fmt.Sprintf("%s|%s", groupAddInfo.FontColor, groupAddInfo.BgColor)
res, err = prepareAndExec(c, d.managerDB, _insertGroup, groupAddInfo.Name, groupAddInfo.Tag, groupAddInfo.ShortTag, color, groupAddInfo.Remark)
return
}
//CheckGroupExist check if group exist
func (d *Dao) CheckGroupExist(c context.Context, groupAddInfo *model.AddGroupArg, exceptid int64) (exist bool, err error) {
var sqlStr = _checkGroupExist
var args = []interface{}{groupAddInfo.Name, groupAddInfo.Tag, groupAddInfo.ShortTag}
if exceptid != 0 {
sqlStr += " AND id != ?"
args = append(args, exceptid)
}
rows, err := prepareAndQuery(c, d.managerDB, sqlStr, args...)
if err != nil {
return
}
defer rows.Close()
var count int
for rows.Next() {
err = rows.Scan(&count)
break
}
if err != nil {
return
}
exist = count > 0
return
}
//UpdateGroup update group
func (d *Dao) UpdateGroup(c context.Context, groupAddInfo *model.EditGroupArg) (res sql.Result, err error) {
if groupAddInfo.AddArg == nil {
return
}
var color = fmt.Sprintf("%s|%s", groupAddInfo.AddArg.FontColor, groupAddInfo.AddArg.BgColor)
res, err = prepareAndExec(c, d.managerDB, _updateGroupByID, groupAddInfo.AddArg.Name, groupAddInfo.AddArg.Tag, groupAddInfo.AddArg.ShortTag, color, groupAddInfo.AddArg.Remark, groupAddInfo.ID)
return
}
//RemoveGroup remove group
func (d *Dao) RemoveGroup(c context.Context, arg *model.RemoveGroupArg) (res sql.Result, err error) {
res, err = prepareAndExec(c, d.managerDB, _removeGroupByID, arg.ID)
return
}
//GetGroup get group
func (d *Dao) GetGroup(c context.Context, arg *model.GetGroupArg) (res []*model.UpGroup, err error) {
var con = dao.Condition{
Key: "state",
Operator: "=",
Value: arg.State,
}
var conditionStr, vals, _ = dao.ConcatCondition(con)
rows, err := prepareAndQuery(c, d.managerDB, _selectGroup+"WHERE "+conditionStr, vals...)
if err != nil {
return
}
defer rows.Close()
// id, name, tag, short_tag, remark, colors
var colorStr string
for rows.Next() {
var group = model.UpGroup{}
err = rows.Scan(&group.ID, &group.Name, &group.Tag, &group.ShortTag, &group.Remark, &colorStr, &group.State)
if err != nil {
log.Error("scan row failed, err=%v", err)
break
}
var colors = strings.Split(colorStr, "|")
if len(colors) >= 2 {
group.FontColor = colors[0]
group.BgColor = colors[1]
}
res = append(res, &group)
}
return
}
// UpGroups get up special group data.
func (d *Dao) UpGroups(c context.Context) (mug map[int64]*upgrpc.UpGroup, err error) {
rows, err := d.managerDB.Query(c, _upGroupsSQL)
if err != nil {
return
}
defer rows.Close()
mug = make(map[int64]*upgrpc.UpGroup)
for rows.Next() {
var (
colorStr string
colors []string
ug = new(upgrpc.UpGroup)
)
if err = rows.Scan(&ug.ID, &ug.Name, &ug.Tag, &ug.ShortTag, &ug.Note, &colorStr); err != nil {
if err == xsql.ErrNoRows {
err = nil
}
return
}
colors = strings.Split(colorStr, "|")
if len(colors) >= 2 {
ug.FontColor = colors[0]
ug.BgColor = colors[1]
}
mug[ug.ID] = ug
}
return
}

View File

@@ -0,0 +1,82 @@
package manager
import (
"context"
"go-common/app/service/main/up/model"
"testing"
"github.com/smartystreets/goconvey/convey"
"strings"
)
func TestManagerAddGroup(t *testing.T) {
var (
c = context.TODO()
groupAddInfo = &model.AddGroupArg{}
)
convey.Convey("AddGroup", t, func(ctx convey.C) {
_, err := d.AddGroup(c, groupAddInfo)
if strings.Contains(err.Error(), "Error 1062") {
err = nil
}
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestManagerCheckGroupExist(t *testing.T) {
var (
c = context.TODO()
groupAddInfo = &model.AddGroupArg{}
exceptid = int64(0)
)
convey.Convey("CheckGroupExist", t, func(ctx convey.C) {
exist, err := d.CheckGroupExist(c, groupAddInfo, exceptid)
ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(exist, convey.ShouldNotBeNil)
})
})
}
func TestManagerUpdateGroup(t *testing.T) {
var (
c = context.TODO()
groupAddInfo = &model.EditGroupArg{}
)
convey.Convey("UpdateGroup", t, func(ctx convey.C) {
res, err := d.UpdateGroup(c, groupAddInfo)
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.ShouldBeNil)
})
})
}
func TestManagerRemoveGroup(t *testing.T) {
var (
c = context.TODO()
arg = &model.RemoveGroupArg{}
)
convey.Convey("RemoveGroup", t, func(ctx convey.C) {
res, err := d.RemoveGroup(c, arg)
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)
})
})
}
func TestManagerGetGroup(t *testing.T) {
var (
c = context.TODO()
arg = &model.GetGroupArg{}
)
convey.Convey("GetGroup", t, func(ctx convey.C) {
_, err := d.GetGroup(c, arg)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,41 @@
package manager
import (
"context"
"fmt"
upgrpc "go-common/app/service/main/up/api/v1"
)
const (
_upSpecialKey = "up_special_%d"
)
// upSpecialCacheKey 缓存key
func upSpecialCacheKey(mid int64) string {
return fmt.Sprintf(_upSpecialKey, mid)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache: -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpSpecial(c context.Context, mid int64) (us *upgrpc.UpSpecial, err error)
// cache: -batch=100 -max_group=1 -batch_err=break -nullcache=&upgrpc.UpSpecial{GroupIDs:[]int64{-1}} -check_null_code=$!=nil&&len($.GroupIDs)>0&&$.GroupIDs[0]==-1
UpsSpecial(c context.Context, mids []int64) (map[int64]*upgrpc.UpSpecial, error)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/mc
type _mc interface {
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpSpecial(c context.Context, mid int64, us *upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpSpecial(c context.Context, mid int64) (res *upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpSpecial(c context.Context, mid int64) (err error)
// mc: -key=upSpecialCacheKey -expire=d.upSpecialExpire -encode=pb
AddCacheUpsSpecial(c context.Context, mu map[int64]*upgrpc.UpSpecial) (err error)
// mc: -key=upSpecialCacheKey
CacheUpsSpecial(c context.Context, mid []int64) (res map[int64]*upgrpc.UpSpecial, err error)
// mc: -key=upSpecialCacheKey
DelCacheUpsSpecial(c context.Context, mids []int64) (err error)
}

View File

@@ -0,0 +1,21 @@
package manager
import (
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerupSpecialCacheKey(t *testing.T) {
convey.Convey("upSpecialCacheKey", t, func(convCtx convey.C) {
var (
mid = int64(0)
)
convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
p1 := upSpecialCacheKey(mid)
convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
convCtx.So(p1, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,181 @@
package manager
import (
"context"
"go-common/app/service/main/up/dao"
"go-common/app/service/main/up/model"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerUpSpecials(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("UpSpecials", t, func(ctx convey.C) {
ups, err := d.UpSpecials(c)
ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(ups, convey.ShouldNotBeNil)
})
})
}
func TestManagerRefreshUpSpecialIncremental(t *testing.T) {
var (
c = context.TODO()
lastMTime = time.Now()
)
convey.Convey("RefreshUpSpecialIncremental", t, func(ctx convey.C) {
ups, err := d.RefreshUpSpecialIncremental(c, lastMTime)
ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(len(ups), convey.ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestManagerDelSpecialByID(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("DelSpecialByID", t, func(ctx convey.C) {
res, err := d.DelSpecialByID(c, id)
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)
})
})
}
func TestManagerInsertSpecial(t *testing.T) {
var (
c = context.TODO()
special = &model.UpSpecial{}
mids = int64(0)
)
convey.Convey("InsertSpecial", t, func(ctx convey.C) {
res, err := d.InsertSpecial(c, special, mids)
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)
})
})
}
func TestManagerUpdateSpecialByID(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
special = &model.UpSpecial{}
)
convey.Convey("UpdateSpecialByID", t, func(ctx convey.C) {
res, err := d.UpdateSpecialByID(c, id, special)
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)
})
})
}
func TestManagerGetSpecialByMidGroup(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
groupID = int64(0)
)
convey.Convey("GetSpecialByMidGroup", t, func(ctx convey.C) {
res, err := d.GetSpecialByMidGroup(c, mid, groupID)
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.ShouldBeNil)
})
})
}
func TestManagerGetSpecialByID(t *testing.T) {
var (
c = context.TODO()
id = int64(0)
)
convey.Convey("GetSpecialByID", t, func(ctx convey.C) {
res, err := d.GetSpecialByID(c, id)
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.ShouldBeNil)
})
})
}
func TestManagerGetSepcialCount(t *testing.T) {
var (
c = context.TODO()
conditions dao.Condition
)
convey.Convey("GetSepcialCount", t, func(ctx convey.C) {
count, err := d.GetSepcialCount(c, conditions)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(count, convey.ShouldNotBeNil)
})
})
}
func TestManagerGetSpecial(t *testing.T) {
var (
c = context.TODO()
conditions dao.Condition
)
convey.Convey("GetSpecial", t, func(ctx convey.C) {
res, err := d.GetSpecial(c, conditions)
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)
})
})
}
func TestManagerGetSpecialByMid(t *testing.T) {
var (
c = context.TODO()
mid = int64(0)
)
convey.Convey("GetSpecialByMid", t, func(ctx convey.C) {
res, err := d.GetSpecialByMid(c, 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.ShouldBeNil)
})
})
}
func TestManagerRawUpSpecial(t *testing.T) {
var (
c = context.TODO()
mid = int64(27515314)
)
convey.Convey("RawUpSpecial", t, func(ctx convey.C) {
res, err := d.RawUpSpecial(c, 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)
})
})
}
func TestManagerRawUpsSpecial(t *testing.T) {
var (
c = context.TODO()
mids = []int64{27515314}
)
convey.Convey("RawUpsSpecial", t, func(ctx convey.C) {
res, err := d.RawUpsSpecial(c, mids)
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)
})
})
}