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,35 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/live/xuserex/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/xuserex/conf:go_default_library",
"//library/cache/memcache:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/live/xuserex/dao/notice:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,33 @@
package dao
import (
"context"
"go-common/app/service/live/xuserex/conf"
"go-common/library/cache/memcache"
)
// Dao dao
type Dao struct {
c *conf.Config
mc *memcache.Pool
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
mc: memcache.NewPool(c.Memcache),
}
return
}
// Close close the resource.
func (d *Dao) Close() {
d.mc.Close()
}
// Ping dao ping
func (d *Dao) Ping(c context.Context) error {
return nil
}

View File

@@ -0,0 +1,62 @@
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.cache.go",
"mc.cache.go",
"roomNotice.go",
],
importpath = "go-common/app/service/live/xuserex/dao/notice",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/live/resource/sdk:go_default_library",
"//app/service/live/xuser/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/model/roomNotice:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/database/hbase.v2:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/stat/prom: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.cache_test.go",
"mc.cache_test.go",
"roomNotice_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/service/live/xuserex/conf:go_default_library",
"//app/service/live/xuserex/model/roomNotice:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,57 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package roomNotice is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache: -sync=true -nullcache=&roomNotice.MonthConsume{Amount:-1} -check_null_code=$.Amount==-1
MonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
}
*/
package notice
import (
"context"
"go-common/app/service/live/xuserex/model/roomNotice"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _cache
// MonthConsume get data from cache if miss will call source method, then add to cache.
func (d *Dao) MonthConsume(c context.Context, id int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
addCache := true
res, err = d.CacheMonthConsume(c, id, targetID, date)
if err != nil {
addCache = false
err = nil
}
defer func() {
if nil != res && res.Amount == -1 {
res = nil
}
}()
if res != nil {
prom.CacheHit.Incr("MonthConsume")
return
}
prom.CacheMiss.Incr("MonthConsume")
res, err = d.RawMonthConsume(c, id, targetID, date)
log.Info("MonthConsume_RawMonthConsume uid (%v) targetId (%v) date (%v) res (%+v)", id, targetID, date, res)
if err != nil {
return
}
miss := res
if miss == nil {
miss = &roomNotice.MonthConsume{Amount: -1}
}
if !addCache {
return
}
d.AddCacheMonthConsume(c, id, targetID, date, miss)
return
}

View File

@@ -0,0 +1,26 @@
package notice
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestRoomNoticeMonthConsume(t *testing.T) {
convey.Convey("MonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10000)
targetID = int64(1008)
date = "20190101"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.MonthConsume(c, id, targetID, date)
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,67 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package roomNotice is a generated mc cache package.
It is generated from:
type _mc interface {
// 获取某个月消费
// mc: -key=keyShouldNotice
CacheMonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
// 保存获取某个月消费
// mc: -key=keyShouldNotice -expire=d.keyShouldNoticeExpire -encode=json|gzip
AddCacheMonthConsume(c context.Context, UID int64, targetID int64, date string, value *roomNotice.MonthConsume) error
}
*/
package notice
import (
"context"
"fmt"
"go-common/app/service/live/xuserex/model/roomNotice"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// CacheMonthConsume 获取某个月消费
func (d *Dao) CacheMonthConsume(c context.Context, id int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyShouldNotice(id, targetID, date)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheMonthConsume")
log.Errorv(c, log.KV("CacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = &roomNotice.MonthConsume{}
err = conn.Scan(reply, res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheMonthConsume")
log.Errorv(c, log.KV("CacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheMonthConsume 保存获取某个月消费
func (d *Dao) AddCacheMonthConsume(c context.Context, id int64, targetID int64, date string, value *roomNotice.MonthConsume) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := keyShouldNotice(id, targetID, date)
item := &memcache.Item{Key: key, Object: value, Expiration: keyShouldNoticeExpire, Flags: memcache.FlagJSON}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheMonthConsume")
log.Errorv(c, log.KV("AddCacheMonthConsume", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}

View File

@@ -0,0 +1,52 @@
package notice
import (
"context"
"go-common/app/service/live/xuserex/model/roomNotice"
"testing"
"github.com/smartystreets/goconvey/convey"
)
// TestRoomNoticeAddCacheMonthConsume test.
func TestRoomNoticeAddCacheMonthConsume(t *testing.T) {
convey.Convey("AddCacheMonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10000)
targetID = int64(1008)
date = "20190101"
value = &roomNotice.MonthConsume{
Uid: id,
Ruid: targetID,
Amount: 10,
Date: -1,
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.AddCacheMonthConsume(c, id, targetID, date, value)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
// TestRoomNoticeCacheMonthConsume auto test.
func TestRoomNoticeCacheMonthConsume(t *testing.T) {
convey.Convey("CacheMonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(10000)
targetID = int64(1008)
date = "20190101"
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.CacheMonthConsume(c, id, targetID, date)
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,345 @@
package notice
import (
"context"
"go-common/app/service/live/xuser/api/grpc/v1"
v1pb "go-common/app/service/live/xuserex/api/grpc/v1"
"go-common/app/service/live/xuserex/conf"
"go-common/library/cache/memcache"
"bytes"
"encoding/json"
"fmt"
"go-common/app/service/live/resource/sdk"
"go-common/app/service/live/xuserex/model/roomNotice"
"go-common/library/database/hbase.v2"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/stat/prom"
"strconv"
"time"
)
// Dao dao
type Dao struct {
c *conf.Config
mc *memcache.Pool
// acc rpc
client *bm.Client
hbase *hbase.Client
xuser *v1.Client
}
type guardGuideConf struct {
Open int64 `json:"open"`
Threshold int64 `json:"threshold"`
}
const (
// 缓存过期时间
keyShouldNoticeExpire = 3600
keyNoticePre = "kn_v1_%d_%d_%s"
// HBaseMonthlyConsumeTable .
HBaseMonthlyConsumeTable = "livemonthconsume"
// BuyGuardGuideTitanKey .
BuyGuardGuideTitanKey = "buy_guard_guide"
// TaskFinishKey .
TaskFinishKey = "task_finish_%s"
)
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
mc: memcache.NewPool(c.Memcache),
client: bm.NewClient(c.BMClient),
hbase: hbase.NewClient(c.HBase),
}
conn, err := v1.NewClient(c.Warden)
if err != nil {
panic(err)
}
dao.xuser = conn
return
}
func keyShouldNotice(UID int64, targetID int64, date string) string {
return fmt.Sprintf(keyNoticePre, UID, targetID, date)
}
// IsNotice returns whether should pop a purchase notice.
func (dao *Dao) IsNotice(c context.Context, UID int64, targetID int64) (*v1pb.RoomNoticeBuyGuardResp, error) {
term := dao.GetTermBegin()
begin := term.Unix()
end := dao.GetTermEnd()
resp := &v1pb.RoomNoticeBuyGuardResp{
Begin: begin,
End: end.Unix(),
Now: time.Now().Unix(),
Title: "感谢支持主播",
Content: "成为船员为主播保驾护航吧~",
Button: "开通大航海",
}
shouldNotice, err := dao.getShouldNotice(c, UID, targetID, term)
if err != nil {
log.Error("dao getShouldNotice uid(%v)roomid(%v)term(%v) error(%v)", UID, targetID, term.Format("2006-01-02"), err)
err = nil
return resp, err
}
resp.ShouldNotice = int64(shouldNotice)
return resp, nil
}
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache: -sync=true -nullcache=&roomNotice.MonthConsume{Amount:-1} -check_null_code=$.Amount==-1
MonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/mc
type _mc interface {
// 获取某个月消费
// mc: -key=keyShouldNotice
CacheMonthConsume(c context.Context, UID int64, targetID int64, date string) (*roomNotice.MonthConsume, error)
// 保存获取某个月消费
// mc: -key=keyShouldNotice -expire=d.keyShouldNoticeExpire -encode=json|gzip
AddCacheMonthConsume(c context.Context, UID int64, targetID int64, date string, value *roomNotice.MonthConsume) error
}
func (dao *Dao) getThreshold() (threshold *guardGuideConf, err error) {
threshold = &guardGuideConf{}
guideConf, err := titansSdk.Get(BuyGuardGuideTitanKey)
log.Info("getThreshold_key(%v) conf(%+v)", BuyGuardGuideTitanKey, guideConf)
if err != nil {
log.Error("getThreshold(%v) error(%v)", BuyGuardGuideTitanKey, err)
return
}
if "" == guideConf {
return
}
if err = json.Unmarshal([]byte(guideConf), threshold); err != nil {
log.Error("json Unmarshal guideconf(%+v) error(%v)", guideConf, err)
return
}
log.Info("getThreshold_unmarshal_succ key(%v) conf (%v) Threshold(%+v)", BuyGuardGuideTitanKey, guideConf, threshold)
return
}
func (dao *Dao) getShouldNotice(ctx context.Context, UID int64, targetID int64, term time.Time) (shouldNotice int, err error) {
shouldNotice = 0
taskFinish, err := dao.GetTaskFinish(ctx, term)
if err != nil {
return shouldNotice, err
}
if !taskFinish {
log.Info("task_not_finish")
return shouldNotice, err
}
// 获取配置的收入门槛
threshold, err := dao.getThreshold()
if err != nil {
log.Error("get_threshold_error(%v)", err)
return
}
if nil == threshold {
log.Error("get_threshold_nil")
return
}
if 0 == threshold.Open {
log.Info("guard_guide not Open (%+v)", threshold)
return
}
monthConsume, err := dao.MonthConsume(ctx, UID, targetID, dao.termToString(term))
log.Info("get_monthConsume(%+v) Threshold (%+v)", monthConsume, threshold)
if err != nil {
log.Error("get_monthConsum_err uid(%d) targetid(%v) term (%v) error(%v)", UID, targetID, term, err)
return
}
if nil == monthConsume {
return
}
if int64(monthConsume.Amount) >= threshold.Threshold*1000 { // coin to rmb
isGuard, err := dao.isGuard(ctx, UID, targetID)
log.Info("show guard guide uid(%v) target (%v) guard (%v) Threshold (%v)", UID, targetID, isGuard, threshold)
if err != nil {
log.Error("get gaurd UID(%v) targetid (%v) error(%v)", UID, targetID, err)
return shouldNotice, err
}
if !isGuard {
shouldNotice = 1
}
}
return
}
func hbaseRowKey(UID int64, targetID int64, date string) string {
return fmt.Sprintf("%s_%d_%d", date, UID, targetID)
}
//RawMonthConsume get month consume from hbase
func (dao *Dao) RawMonthConsume(ctx context.Context, UID int64, targetID int64, date string) (res *roomNotice.MonthConsume, err error) {
var (
tableName = HBaseMonthlyConsumeTable
key = hbaseRowKey(UID, targetID, date)
)
result, err := dao.hbase.GetStr(ctx, tableName, key)
log.Info("RawMonthConsume_getstr tableName (%v) key (%v) res (%v)", tableName, key, result)
if err != nil {
log.Error("dao.hbase.GetStr tableName(%s)|mid(%d)|key(%v)|error(%v)", tableName, UID, key, err)
err = ecode.CreativeDataErr
return
}
if result == nil {
return
}
res = &roomNotice.MonthConsume{}
for _, c := range result.Cells {
if c == nil {
continue
}
v, _ := strconv.ParseInt(string(c.Value[:]), 10, 64)
if !bytes.Equal(c.Family, []byte("info")) {
log.Error("family_type_err(%v) error", c.Family)
continue
}
switch {
case bytes.Equal(c.Qualifier, []byte("uid")):
res.Uid = v
case bytes.Equal(c.Qualifier, []byte("ruid")):
res.Ruid = v
case bytes.Equal(c.Qualifier, []byte("amount")):
res.Amount = v
case bytes.Equal(c.Qualifier, []byte("time")):
res.Date = v
}
}
log.Info("RawMonthConsume_succ uid (%v) target (%v) date (%v) res (%+v)", UID, targetID, date, res)
return
}
// GetTermBegin return first day of last month
func (dao *Dao) GetTermBegin() time.Time {
year, month, _ := time.Now().Date()
thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
return thisMonth.AddDate(0, -1, 0)
}
// GetTermEnd returns last second of last month
func (dao *Dao) GetTermEnd() time.Time {
year, month, _ := time.Now().Date()
thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
second, _ := time.ParseDuration("-1s")
return thisMonth.Add(second)
}
// IsValidTerm returns whether a term is valid.
func (dao *Dao) IsValidTerm(term time.Time) bool {
return true
}
// TOOD
func (dao *Dao) isGuard(c context.Context, UID int64, targetID int64) (isGuard bool, err error) {
ret, err := dao.xuser.GetByUIDTargetID(c, &v1.GetByUidTargetIdReq{
Uid: UID,
TargetId: targetID,
})
log.Info("dao.xuser.GetByUIDTargetID uid (%v) target (%v) res (%v)", UID, targetID, ret)
if err != nil {
log.Error("get guard uid (%v) target (%v) error(%v)", UID, targetID, err)
return
}
if nil == ret || nil == ret.Data || 0 == len(ret.Data) {
log.Info("not_guard uid (%v) target (%v) res (%v)", UID, targetID, ret)
return
}
isGuard = true
return
}
// GetTaskFinish .
func (dao *Dao) GetTaskFinish(c context.Context, term time.Time) (isOn bool, err error) {
conn := dao.mc.Get(c)
defer conn.Close()
key := dao.keyTaskFinish(term)
reply, err := conn.Get(key)
log.Info("GetTaskFinish key (%v) term (%v)", key, term)
if err != nil {
if err == memcache.ErrNotFound {
log.Info("GetTaskFinish_not_found key (%v) term (%v)", key, term)
err = nil
return
}
prom.BusinessErrCount.Incr("mc:GetTaskFinish")
log.Error("GetTaskFinish_fail key(%v) error(%v)", key, err)
return
}
res := &roomNotice.TaskFinish{}
err = conn.Scan(reply, &res)
if err != nil {
prom.BusinessErrCount.Incr("mc:GetTaskFinish")
log.Error("GetTaskFinish_fail_scan key(%v) error(%v)", key, err)
return
}
log.Info("GetTaskFinish_succ key (%v) term (%v) res(%+v)", key, term, res)
if res == nil {
return
}
if 1 == res.Finish {
isOn = true
}
return
}
// SetTaskFinish .
func (dao *Dao) SetTaskFinish(c context.Context, term time.Time, isFinish int64) (err error) {
conn := dao.mc.Get(c)
defer conn.Close()
key := dao.keyTaskFinish(term)
value := &roomNotice.TaskFinish{
Finish: isFinish,
}
log.Info("SetTaskFinish key (%v) term (%v) value (%+v)", key, term, value)
item := &memcache.Item{
Key: key,
Object: value,
Flags: memcache.FlagJSON,
Expiration: 0,
}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:SetTaskFinish")
log.Error("SetTaskFinish_fail key(%v) value (%+v) error(%v)", key, value, err)
return
}
log.Info("SetTaskFinish_succ key (%v) term (%v) value (%+v)", key, term, value)
return
}
func (dao *Dao) termToString(term time.Time) string {
return term.Format("20060102")
}
func (dao *Dao) keyTaskFinish(term time.Time) (key string) {
return fmt.Sprintf(TaskFinishKey, dao.termToString(term))
}

View File

@@ -0,0 +1,195 @@
package notice
import (
"context"
"go-common/app/service/live/xuserex/conf"
"testing"
"time"
"flag"
"github.com/smartystreets/goconvey/convey"
"os"
)
var (
d *Dao
UID = int64(10000)
targetID = int64(10000)
date = "20190101"
term = time.Now()
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "live.live.xuserex")
flag.Set("conf_token", "4e6ace268a9ee6d04fad131ad551f61e")
flag.Set("tree_id", "82470")
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.Set("deploy.env", "uat")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func TestRoomNoticeNew(t *testing.T) {
convey.Convey("New", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
ctx.Convey("Then dao should not be nil.", func(ctx convey.C) {
ctx.So(d, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticekeyShouldNotice(t *testing.T) {
convey.Convey("keyShouldNotice", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := keyShouldNotice(UID, targetID, date)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeIsNotice(t *testing.T) {
convey.Convey("IsNotice", t, func(ctx convey.C) {
convey.Convey("When everything goes positive", func(ctx convey.C) {
c := context.TODO()
p1, err := d.IsNotice(c, UID, targetID)
ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticegetThreshold(t *testing.T) {
convey.Convey("getThreshold", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
threshold, err := d.getThreshold()
ctx.Convey("Then err should be nil.threshold should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(threshold, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticegetShouldNotice(t *testing.T) {
convey.Convey("getShouldNotice", t, func() {
var (
ctx = context.Background()
)
convey.Convey("When everything goes positive", func() {
shouldNotice, err := d.getShouldNotice(ctx, UID, targetID, term)
convey.Convey("Then err should be nil.shouldNotice should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(shouldNotice, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticehbaseRowKey(t *testing.T) {
convey.Convey("hbaseRowKey", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := hbaseRowKey(UID, targetID, date)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeRawMonthConsume(t *testing.T) {
convey.Convey("RawMonthConsume", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
res, err := d.RawMonthConsume(c, UID, targetID, date)
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 TestRoomNoticeGetTermBegin(t *testing.T) {
convey.Convey("GetTermBegin", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := d.GetTermBegin()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeGetTermEnd(t *testing.T) {
convey.Convey("GetTermEnd", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := d.GetTermEnd()
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeIsValidTerm(t *testing.T) {
convey.Convey("IsValidTerm", t, func(ctx convey.C) {
ctx.Convey("When everything goes positive", func(ctx convey.C) {
p1 := d.IsValidTerm(term)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
})
}
func TestRoomNoticeisGuard(t *testing.T) {
convey.Convey("isGuard", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
isGuard, err := d.isGuard(c, UID, targetID)
ctx.Convey("Then err should be nil.isGuard should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(isGuard, convey.ShouldNotBeNil)
})
})
})
}
func TestGetTaskFinish(t *testing.T) {
convey.Convey("GetTaskFinish", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
term := d.GetTermBegin()
isFinish, err := d.GetTaskFinish(c, term)
ctx.Convey("Then err should be nil.isGuard should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(isFinish, convey.ShouldNotBeNil)
})
})
})
}