Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"cache.go",
"dao.cache.go",
"dao.go",
"mc.cache.go",
"mysql.go",
],
importpath = "go-common/app/service/main/card/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/card/conf:go_default_library",
"//app/service/main/card/model:go_default_library",
"//library/cache:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/net/metadata:go_default_library",
"//library/stat/prom:go_default_library",
"//library/sync/errgroup:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/golang.org/x/sync/singleflight: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 = [
"cache_test.go",
"dao.cache_test.go",
"dao_test.go",
"mc.cache_test.go",
"mysql_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/card/conf:go_default_library",
"//app/service/main/card/model:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,20 @@
package dao
import (
"context"
"strconv"
"go-common/app/service/main/card/model"
)
func (d *Dao) cacheSFEquip(id int64) string {
return strconv.FormatInt(id, 10)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache: -batch=50 -max_group=10 -batch_err=continue -nullcache=&model.UserEquip{CardID:-1} -check_null_code=$!=nil&&$.CardID==-1
Equips(c context.Context, keys []int64) (map[int64]*model.UserEquip, error)
// cache: -nullcache=&model.UserEquip{CardID:-1} -check_null_code=$!=nil&&$.CardID==-1 -singleflight=true
Equip(c context.Context, key int64) (*model.UserEquip, error)
}

View File

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

View File

@@ -0,0 +1,164 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package dao is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache: -batch=50 -max_group=10 -batch_err=continue -nullcache=&model.UserEquip{CardID:-1} -check_null_code=$!=nil&&$.CardID==-1
Equips(c context.Context, keys []int64) (map[int64]*model.UserEquip, error)
// cache: -nullcache=&model.UserEquip{CardID:-1} -check_null_code=$!=nil&&$.CardID==-1 -singleflight=true
Equip(c context.Context, key int64) (*model.UserEquip, error)
}
*/
package dao
import (
"context"
"sync"
"go-common/app/service/main/card/model"
"go-common/library/net/metadata"
"go-common/library/stat/prom"
"go-common/library/sync/errgroup"
"golang.org/x/sync/singleflight"
)
var _ _cache
var cacheSingleFlights = [1]*singleflight.Group{{}}
// Equips get data from cache if miss will call source method, then add to cache.
func (d *Dao) Equips(c context.Context, keys []int64) (res map[int64]*model.UserEquip, err error) {
if len(keys) == 0 {
return
}
addCache := true
res, err = d.CacheEquips(c, keys)
if 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("Equips", int64(len(keys)-len(miss)))
defer func() {
for k, v := range res {
if v != nil && v.CardID == -1 {
delete(res, k)
}
}
}()
if len(miss) == 0 {
return
}
var missData map[int64]*model.UserEquip
missLen := len(miss)
prom.CacheMiss.Add("Equips", int64(missLen))
mutex := sync.Mutex{}
for i := 0; i < missLen; i += 50 * 10 {
var subKeys []int64
group := &errgroup.Group{}
ctx := c
if (i + 50*10) > missLen {
subKeys = miss[i:]
} else {
subKeys = miss[i : i+50*10]
}
missSubLen := len(subKeys)
for j := 0; j < missSubLen; j += 50 {
var ks []int64
if (j + 50) > missSubLen {
ks = subKeys[j:]
} else {
ks = subKeys[j : j+50]
}
group.Go(func() (err error) {
data, err := d.RawEquips(ctx, ks)
mutex.Lock()
for k, v := range data {
if missData == nil {
missData = make(map[int64]*model.UserEquip, len(keys))
}
missData[k] = v
}
mutex.Unlock()
return
})
}
err1 := group.Wait()
if err1 != nil {
err = err1
}
}
if res == nil {
res = make(map[int64]*model.UserEquip)
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
for _, key := range keys {
if res[key] == nil {
if missData == nil {
missData = make(map[int64]*model.UserEquip, len(keys))
}
missData[key] = &model.UserEquip{CardID: -1}
}
}
if !addCache {
return
}
d.cache.Save(func() {
d.AddCacheEquips(metadata.WithContext(c), missData)
})
return
}
// Equip get data from cache if miss will call source method, then add to cache.
func (d *Dao) Equip(c context.Context, id int64) (res *model.UserEquip, err error) {
addCache := true
res, err = d.CacheEquip(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if res != nil && res.CardID == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("Equip")
return
}
var rr interface{}
sf := d.cacheSFEquip(id)
rr, err, _ = cacheSingleFlights[0].Do(sf, func() (r interface{}, e error) {
prom.CacheMiss.Incr("Equip")
r, e = d.RawEquip(c, id)
return
})
res = rr.(*model.UserEquip)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &model.UserEquip{CardID: -1}
}
if !addCache {
return
}
d.cache.Save(func() {
d.AddCacheEquip(metadata.WithContext(c), id, miss)
})
return
}

View File

@@ -0,0 +1,40 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoEquips(t *testing.T) {
convey.Convey("Equips", t, func(ctx convey.C) {
var (
c = context.Background()
keys = []int64{1, 2, 3, 4}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Equips(c, keys)
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 TestDaoEquip(t *testing.T) {
convey.Convey("Equip", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(2)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.Equip(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)
})
})
})
}

View File

@@ -0,0 +1,51 @@
package dao
import (
"context"
"time"
"go-common/app/service/main/card/conf"
"go-common/library/cache"
"go-common/library/cache/memcache"
xsql "go-common/library/database/sql"
)
// Dao dao
type Dao struct {
c *conf.Config
// memcache
mc *memcache.Pool
mcExpire int32
// db
db *xsql.DB
// cache async save
cache *cache.Cache
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
// card memcache
mc: memcache.NewPool(c.Memcache.Config),
mcExpire: int32(time.Duration(c.Memcache.CardExpire) / time.Second),
db: xsql.NewMySQL(c.MySQL),
// cache chan
cache: cache.New(1, 1024),
}
return
}
// Close close the resource.
func (d *Dao) Close() {
d.mc.Close()
d.db.Close()
}
// Ping dao ping
func (d *Dao) Ping(c context.Context) (err error) {
if err = d.pingMC(c); err != nil {
return
}
return d.db.Ping(c)
}

View File

@@ -0,0 +1,35 @@
package dao
import (
"flag"
"os"
"testing"
"go-common/app/service/main/card/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "card-service")
flag.Set("conf_token", "e7ab64e6f5b4382145a90fdd470cb831")
flag.Set("tree_id", "59006")
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/test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,159 @@
package dao
import (
"context"
"fmt"
"strconv"
"go-common/app/service/main/card/model"
mc "go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
"github.com/pkg/errors"
)
const (
_prequip = "e_"
)
func equipKey(mid int64) string {
return _prequip + strconv.FormatInt(mid, 10)
}
// pingMC ping memcache.
func (d *Dao) pingMC(c context.Context) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
err = conn.Set(&mc.Item{
Key: "ping",
Value: []byte("pong"),
})
return
}
// CacheEquips get data from mc
func (d *Dao) CacheEquips(c context.Context, mids []int64) (res map[int64]*model.UserEquip, err error) {
keys := make([]string, 0, len(mids))
keyMidMap := make(map[string]int64, len(mids))
for _, mid := range mids {
key := equipKey(mid)
if _, ok := keyMidMap[key]; !ok {
// duplicate mid
keyMidMap[key] = mid
keys = append(keys, key)
}
}
conn := d.mc.Get(c)
defer conn.Close()
rs, err := conn.GetMulti(keys)
if err != nil {
if err == mc.ErrNotFound {
err = nil
return
}
err = errors.Wrap(err, "dao equips cache")
return
}
res = make(map[int64]*model.UserEquip, len(mids))
for k, r := range rs {
e := &model.UserEquip{}
conn.Scan(r, e)
res[keyMidMap[k]] = e
}
return
}
// CacheEquip get user card equip from cache.
func (d *Dao) CacheEquip(c context.Context, mid int64) (v *model.UserEquip, err error) {
key := equipKey(mid)
conn := d.mc.Get(c)
defer conn.Close()
r, err := conn.Get(key)
if err != nil {
if err == mc.ErrNotFound {
err = nil
return
}
err = errors.Wrap(err, "dao cache equip")
return
}
v = &model.UserEquip{}
if err = conn.Scan(r, v); err != nil {
err = errors.Wrap(err, "dao cache scan equip")
}
return
}
// AddCacheEquips Set data to mc
func (d *Dao) AddCacheEquips(c context.Context, values map[int64]*model.UserEquip) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
for k, v := range values {
item := &mc.Item{
Key: equipKey(k),
Object: v,
Flags: mc.FlagProtobuf,
Expiration: d.mcExpire,
}
if err = conn.Set(item); err != nil {
err = errors.Wrap(err, "dao add equips cache")
}
}
return
}
// AddCacheEquip set user card equip info into cache.
func (d *Dao) AddCacheEquip(c context.Context, mid int64, v *model.UserEquip) (err error) {
item := &mc.Item{
Key: equipKey(mid),
Object: v,
Flags: mc.FlagProtobuf,
Expiration: d.mcExpire,
}
conn := d.mc.Get(c)
defer conn.Close()
if err = conn.Set(item); err != nil {
err = errors.Wrap(err, "dao add equip cache")
}
return
}
// DelCacheEquips delete data from mc
func (d *Dao) DelCacheEquips(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 := equipKey(id)
if err = conn.Delete(key); err != nil {
if err == mc.ErrNotFound {
err = nil
continue
}
prom.BusinessErrCount.Incr("mc:DelCacheEquips")
log.Errorv(c, log.KV("DelCacheEquips", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
}
return
}
// DelCacheEquip delete data from mc
func (d *Dao) DelCacheEquip(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := equipKey(id)
if err = conn.Delete(key); err != nil {
if err == mc.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheEquip")
log.Errorv(c, log.KV("DelCacheEquip", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}

View File

@@ -0,0 +1,130 @@
package dao
import (
"context"
"testing"
"go-common/app/service/main/card/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoequipKey(t *testing.T) {
convey.Convey("equipKey", t, func(ctx convey.C) {
var (
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := equipKey(mid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestDaopingMC(t *testing.T) {
convey.Convey("pingMC", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.pingMC(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoCacheEquips(t *testing.T) {
convey.Convey("CacheEquips", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{1, 2, 3}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.CacheEquips(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)
})
})
})
}
func TestDaoCacheEquip(t *testing.T) {
convey.Convey("CacheEquip", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(2)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
_, err := d.CacheEquip(c, mid)
ctx.Convey("Then err should be nil.v should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddCacheEquips(t *testing.T) {
convey.Convey("AddCacheEquips", t, func(ctx convey.C) {
var (
c = context.Background()
values map[int64]*model.UserEquip
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddCacheEquips(c, values)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoAddCacheEquip(t *testing.T) {
convey.Convey("AddCacheEquip", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
v = &model.UserEquip{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.AddCacheEquip(c, mid, v)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoDelCacheEquips(t *testing.T) {
convey.Convey("DelCacheEquips", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.DelCacheEquips(c, ids)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoDelCacheEquip(t *testing.T) {
convey.Convey("DelCacheEquip", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.DelCacheEquip(c, id)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,121 @@
package dao
import (
"context"
"fmt"
"go-common/app/service/main/card/model"
xsql "go-common/library/database/sql"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_selUserEquip = "SELECT mid,card_id,expire_time FROM user_card_equip WHERE mid=? AND deleted = 0;"
_selUserEquips = "SELECT mid,card_id,expire_time FROM user_card_equip WHERE mid IN (%s) AND deleted = 0;"
_selEffectiveCard = "SELECT id,name,state,is_hot,card_url,big_crad_url,card_type,order_num,group_id,ctime,mtime FROM card_info WHERE state = 0 AND deleted = 0 ORDER BY order_num DESC;"
_selEffectiveCardGroup = "SELECT id,name,state,ctime,mtime,order_num FROM card_group WHERE state = 0 AND deleted = 0;"
_cardEquip = "INSERT INTO user_card_equip(mid,card_id,expire_time)VALUES(?,?,?) ON DUPLICATE KEY UPDATE card_id =?,expire_time=?,deleted=0;"
_cardDemount = "UPDATE user_card_equip SET deleted = 1 WHERE mid = ?;"
)
// RawEquip get user equip info.
func (d *Dao) RawEquip(c context.Context, mid int64) (r *model.UserEquip, err error) {
r = new(model.UserEquip)
row := d.db.QueryRow(c, _selUserEquip, mid)
if err = row.Scan(&r.Mid, &r.CardID, &r.ExpireTime); err != nil {
if err == xsql.ErrNoRows {
err = nil
r = nil
return
}
r = nil
err = errors.Wrapf(err, "dao equip mid(%d)", mid)
}
return
}
// RawEquips get user equip infos.
func (d *Dao) RawEquips(c context.Context, mids []int64) (res map[int64]*model.UserEquip, err error) {
var rows *xsql.Rows
res = make(map[int64]*model.UserEquip, len(mids))
midStr := xstr.JoinInts(mids)
if rows, err = d.db.Query(c, fmt.Sprintf(_selUserEquips, midStr)); err != nil {
err = errors.Wrapf(err, "dao equips mids(%s)", midStr)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.UserEquip)
if err = rows.Scan(&r.Mid, &r.CardID, &r.ExpireTime); err != nil {
err = errors.Wrapf(err, "dao equips scan mids(%s)", midStr)
res = nil
return
}
res[r.Mid] = r
}
err = rows.Err()
return
}
// EffectiveCards query all effective cards .
func (d *Dao) EffectiveCards(c context.Context) (res []*model.Card, err error) {
var rows *xsql.Rows
if rows, err = d.db.Query(c, _selEffectiveCard); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.Card)
if err = rows.Scan(&r.ID, &r.Name, &r.State, &r.IsHot, &r.CardURL, &r.BigCradURL, &r.CardType, &r.OrderNum,
&r.GroupID, &r.Ctime, &r.Mtime); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
// EffectiveGroups query all effective groups .
func (d *Dao) EffectiveGroups(c context.Context) (res []*model.CardGroup, err error) {
var rows *xsql.Rows
if rows, err = d.db.Query(c, _selEffectiveCardGroup); err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
r := new(model.CardGroup)
if err = rows.Scan(&r.ID, &r.Name, &r.State, &r.Ctime, &r.Mtime, &r.OrderNum); err != nil {
err = errors.WithStack(err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}
// CardEquip card equip.
func (d *Dao) CardEquip(c context.Context, e *model.UserEquip) (err error) {
if _, err = d.db.Exec(c, _cardEquip, e.Mid, e.CardID, e.ExpireTime, e.CardID, e.ExpireTime); err != nil {
err = errors.WithStack(err)
return
}
return
}
// DeleteEquip delete card equip.
func (d *Dao) DeleteEquip(c context.Context, mid int64) (err error) {
if _, err = d.db.Exec(c, _cardDemount, mid); err != nil {
err = errors.WithStack(err)
return
}
return
}

View File

@@ -0,0 +1,102 @@
package dao
import (
"context"
"testing"
"go-common/app/service/main/card/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoRawEquip(t *testing.T) {
convey.Convey("RawEquip", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(2)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
r, err := d.RawEquip(c, mid)
ctx.Convey("Then err should be nil.r should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(r, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoRawEquips(t *testing.T) {
convey.Convey("RawEquips", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{1, 2, 3}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RawEquips(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)
})
})
})
}
func TestDaoEffectiveCards(t *testing.T) {
convey.Convey("EffectiveCards", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.EffectiveCards(c)
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 TestDaoEffectiveGroups(t *testing.T) {
convey.Convey("EffectiveGroups", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.EffectiveGroups(c)
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 TestDaoCardEquip(t *testing.T) {
convey.Convey("CardEquip", t, func(ctx convey.C) {
var (
c = context.Background()
e = &model.UserEquip{}
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.CardEquip(c, e)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoDeleteEquip(t *testing.T) {
convey.Convey("DeleteEquip", t, func(ctx convey.C) {
var (
c = context.Background()
mid = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
err := d.DeleteEquip(c, mid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}