dao_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package relation
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/interface/main/app-interface/conf"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.app-svr.app-interface")
  16. flag.Set("conf_token", "1mWvdEwZHmCYGoXJCVIdszBOPVdtpXb3")
  17. flag.Set("tree_id", "2688")
  18. flag.Set("conf_version", "docker-1")
  19. flag.Set("deploy_env", "uat")
  20. flag.Set("conf_host", "config.bilibili.co")
  21. flag.Set("conf_path", "/tmp")
  22. flag.Set("region", "sh")
  23. flag.Set("zone", "sh001")
  24. } else {
  25. flag.Set("conf", "../../cmd/app-interface-test.toml")
  26. }
  27. flag.Parse()
  28. if err := conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. d = New(conf.Conf)
  32. os.Exit(m.Run())
  33. // time.Sleep(time.Second)
  34. }
  35. func TestStat(t *testing.T) {
  36. var (
  37. c = context.Background()
  38. mid = int64(1)
  39. )
  40. convey.Convey("Stat", t, func(ctx convey.C) {
  41. _, err := d.Stat(c, mid)
  42. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. })
  45. })
  46. }
  47. func TestFollowersUnread(t *testing.T) {
  48. var (
  49. c = context.Background()
  50. mid = int64(1)
  51. )
  52. convey.Convey("FollowersUnread", t, func(ctx convey.C) {
  53. _, err := d.FollowersUnread(c, mid)
  54. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. })
  57. })
  58. }
  59. func TestFollowings(t *testing.T) {
  60. var (
  61. c = context.Background()
  62. mid = int64(1)
  63. )
  64. convey.Convey("Followings", t, func(ctx convey.C) {
  65. _, err := d.Followings(c, mid)
  66. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. }
  71. func TestRelations(t *testing.T) {
  72. var (
  73. c = context.Background()
  74. mid = int64(1)
  75. fids = []int64{1}
  76. )
  77. convey.Convey("Relations", t, func(ctx convey.C) {
  78. _, err := d.Relations(c, mid, fids)
  79. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. })
  82. })
  83. }
  84. func TestTag(t *testing.T) {
  85. var (
  86. c = context.Background()
  87. mid = int64(1)
  88. tid = int64(1)
  89. )
  90. convey.Convey("Tag", t, func(ctx convey.C) {
  91. _, err := d.Tag(c, mid, tid)
  92. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. })
  95. })
  96. }
  97. func TestFollowersUnreadCount(t *testing.T) {
  98. var (
  99. c = context.Background()
  100. mid = int64(2)
  101. )
  102. convey.Convey("FollowersUnreadCount", t, func(ctx convey.C) {
  103. _, err := d.FollowersUnreadCount(c, mid)
  104. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. })
  107. })
  108. }