123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- package datadao
- import (
- "context"
- "testing"
- "time"
- "github.com/smartystreets/goconvey/convey"
- )
- func TestDatadaodescHelper(t *testing.T) {
- convey.Convey("descHelper", t, func(ctx convey.C) {
- var (
- d = &CacheBaseLoader{}
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- key := descHelper(d)
- ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
- ctx.So(key, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaonewCacheBaseLoader(t *testing.T) {
- convey.Convey("newCacheBaseLoader", t, func(ctx convey.C) {
- var (
- signID = int64(0)
- date = time.Now()
- val = interface{}(0)
- desc = ""
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := newCacheBaseLoader(signID, date, val, desc)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoKeyCacheBaseLoader(t *testing.T) {
- var (
- c = CacheBaseLoader{}
- )
- convey.Convey("Key", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- key := c.Key()
- ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
- ctx.So(key, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoValueCacheBaseLoader(t *testing.T) {
- var (
- c = CacheBaseLoader{Val: 1}
- )
- convey.Convey("Value", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- value := c.Value()
- ctx.Convey("Then value should not be nil.", func(ctx convey.C) {
- ctx.So(value, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoExpireCacheBaseLoader(t *testing.T) {
- var (
- c = CacheBaseLoader{Val: 1}
- )
- convey.Convey("Expire", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := c.Expire()
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoDesc(t *testing.T) {
- var (
- c = CacheBaseLoader{Val: 1}
- )
- convey.Convey("Desc", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := c.Desc()
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoNewCacheMcnDataWithTp(t *testing.T) {
- convey.Convey("NewCacheMcnDataWithTp", t, func(ctx convey.C) {
- var (
- signID = int64(0)
- date = time.Now()
- tp = ""
- val = interface{}(0)
- desc = ""
- loadFunc LoadFuncWithTp
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := NewCacheMcnDataWithTp(signID, date, tp, val, desc, loadFunc)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoKeyCacheMcnDataWithTp(t *testing.T) {
- var (
- s = cacheMcnDataWithTp{CacheBaseLoader: CacheBaseLoader{Val: 1}}
- )
- convey.Convey("Key", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- key := s.Key()
- ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
- ctx.So(key, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoLoadValuecacheMcnDataWithTp(t *testing.T) {
- convey.Convey("LoadValue", t, func(ctx convey.C) {
- var (
- c = context.Background()
- s = cacheMcnDataWithTp{
- CacheBaseLoader: CacheBaseLoader{Val: 1},
- LoadFunc: func(c context.Context, signID int64, date time.Time, tp string) (res interface{}, err error) {
- return d.GetIndexSource(c, signID, date, tp)
- },
- }
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- value, err := s.LoadValue(c)
- ctx.Convey("Then err should be nil.value should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(value, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoNewCacheMcnDataSignID(t *testing.T) {
- convey.Convey("NewCacheMcnDataSignID", t, func(ctx convey.C) {
- var (
- signID = int64(0)
- date = time.Now()
- val = interface{}(0)
- desc = ""
- loadFunc LoadFuncOnlySign
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- p1 := NewCacheMcnDataSignID(signID, date, val, desc, loadFunc)
- ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
- ctx.So(p1, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoKeycacheMcnDataSignID(t *testing.T) {
- var (
- s = cacheMcnDataSignID{CacheBaseLoader: CacheBaseLoader{Val: 1}}
- )
- convey.Convey("Key", t, func(ctx convey.C) {
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- key := s.Key()
- ctx.Convey("Then key should not be nil.", func(ctx convey.C) {
- ctx.So(key, convey.ShouldNotBeNil)
- })
- })
- })
- }
- func TestDatadaoLoadValuecacheMcnDataSignID(t *testing.T) {
- convey.Convey("LoadValue", t, func(ctx convey.C) {
- var (
- c = context.Background()
- s = cacheMcnDataSignID{
- CacheBaseLoader: CacheBaseLoader{Val: 1},
- LoadFunc: func(c context.Context, signID int64, date time.Time) (res interface{}, err error) {
- return d.GetMcnFans(c, signID, date)
- },
- }
- )
- ctx.Convey("When everything gose positive", func(ctx convey.C) {
- value, err := s.LoadValue(c)
- ctx.Convey("Then err should be nil.value should not be nil.", func(ctx convey.C) {
- ctx.So(err, convey.ShouldBeNil)
- ctx.So(value, convey.ShouldNotBeNil)
- })
- })
- })
- }
|