exp_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package dao
  2. import (
  3. "context"
  4. "sync"
  5. "testing"
  6. "time"
  7. "go-common/app/service/live/userexp/conf"
  8. "go-common/library/log"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. once sync.Once
  13. d *Dao
  14. ctx = context.TODO()
  15. )
  16. func initConf() {
  17. if err := conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. log.Init(conf.Conf.Log)
  21. defer log.Close()
  22. }
  23. func startService() {
  24. initConf()
  25. d = New(conf.Conf)
  26. time.Sleep(time.Second * 2)
  27. }
  28. func TestInitExp(t *testing.T) {
  29. Convey("Init Exp", t, func() {
  30. once.Do(startService)
  31. _, err := d.InitExp(ctx, 10001, 0, 0)
  32. So(err, ShouldBeNil)
  33. })
  34. }
  35. func TestExp(t *testing.T) {
  36. Convey("Init Exp", t, func() {
  37. once.Do(startService)
  38. rs, err := d.Exp(ctx, 10001)
  39. So(err, ShouldBeNil)
  40. t.Logf("QueryExp %v", rs)
  41. })
  42. }
  43. func TestMultiExp(t *testing.T) {
  44. Convey("Multi Exp", t, func() {
  45. once.Do(startService)
  46. rs, err := d.MultiExp(ctx, []int64{10001, 10002})
  47. So(err, ShouldBeNil)
  48. t.Logf("QueryExp rs=%v", rs)
  49. })
  50. }
  51. func TestAddUexp(t *testing.T) {
  52. Convey("Add Uexp", t, func() {
  53. once.Do(startService)
  54. _, err := d.AddUexp(ctx, 10001, 111)
  55. So(err, ShouldBeNil)
  56. })
  57. }
  58. func TestAddRexp(t *testing.T) {
  59. Convey("Add Uexp", t, func() {
  60. once.Do(startService)
  61. _, err := d.AddRexp(ctx, 11111, 111)
  62. So(err, ShouldBeNil)
  63. })
  64. }