dao_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/block/conf"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. dao *Dao
  12. ctx = context.TODO()
  13. )
  14. func TestMain(m *testing.M) {
  15. defer os.Exit(0)
  16. flag.Set("conf", "../cmd/block-admin-test.toml")
  17. var err error
  18. if err = conf.Init(); err != nil {
  19. panic(err)
  20. }
  21. dao = New()
  22. defer dao.Close()
  23. m.Run()
  24. }
  25. func TestDB(t *testing.T) {
  26. Convey("db", t, func() {
  27. err := dao.SendSysMsg(ctx, "123", []int64{1, 2, 3}, "test title", "test content", "")
  28. So(err, ShouldBeNil)
  29. _, err = dao.HistoryCount(ctx, 46333)
  30. So(err, ShouldBeNil)
  31. _, err = dao.History(ctx, 46333, 0, 100)
  32. So(err, ShouldBeNil)
  33. _, err = dao.User(ctx, 46333)
  34. So(err, ShouldBeNil)
  35. _, err = dao.Users(ctx, []int64{46333})
  36. So(err, ShouldBeNil)
  37. _, err = dao.UserDetails(ctx, []int64{46333})
  38. So(err, ShouldBeNil)
  39. })
  40. }
  41. func TestRPC(t *testing.T) {
  42. Convey("rpc", t, func() {
  43. mid := int64(46333)
  44. _, err := dao.SpyScore(ctx, mid)
  45. So(err, ShouldBeNil)
  46. _, err = dao.FigureRank(ctx, mid)
  47. So(err, ShouldBeNil)
  48. _, _, _, _, err = dao.AccountInfo(ctx, mid)
  49. So(err, ShouldBeNil)
  50. })
  51. }
  52. func TestTool(t *testing.T) {
  53. Convey("tool", t, func() {
  54. var (
  55. mids = []int64{1, 2, 3, 46333, 35858}
  56. )
  57. str := midsToParam(mids)
  58. So(str, ShouldEqual, "1,2,3,46333,35858")
  59. })
  60. }
  61. func TestHTTP(t *testing.T) {
  62. Convey("http", t, func() {
  63. var (
  64. mid int64 = 46333
  65. telInfo string
  66. mailInfo string
  67. err error
  68. )
  69. telInfo, err = dao.TelInfo(ctx, mid)
  70. So(err, ShouldBeNil)
  71. mailInfo, err = dao.MailInfo(ctx, mid)
  72. So(err, ShouldBeNil)
  73. t.Logf("telinfo : %s , mailinfo : %s", telInfo, mailInfo)
  74. })
  75. }