dao_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package archive
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/app-view/conf"
  9. "go-common/app/service/main/archive/model/archive"
  10. "go-common/library/net/rpc"
  11. xtime "go-common/library/time"
  12. "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. d *Dao
  16. )
  17. func TestMain(m *testing.M) {
  18. if os.Getenv("DEPLOY_ENV") != "" {
  19. flag.Set("app_id", "main.app-svr.app-view")
  20. flag.Set("conf_token", "3a4CNLBhdFbRQPs7B4QftGvXHtJo92xw")
  21. flag.Set("tree_id", "4575")
  22. flag.Set("conf_version", "docker-1")
  23. flag.Set("deploy_env", "uat")
  24. flag.Set("conf_host", "config.bilibili.co")
  25. flag.Set("conf_path", "/tmp")
  26. flag.Set("region", "sh")
  27. flag.Set("zone", "sh001")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. m.Run()
  35. os.Exit(0)
  36. }
  37. func TestViewRPC(t *testing.T) {
  38. convey.Convey("TestViewRPC", t, func(ctx convey.C) {
  39. var addr = "172.22.36.185:6089" // new
  40. // addr = "172.22.38.5:6089" // old
  41. client := rpc.Dial(addr, xtime.Duration(100*time.Millisecond), nil)
  42. var (
  43. view *archive.View3
  44. views map[int64]*archive.View3
  45. err error
  46. )
  47. if err = client.Call(context.TODO(), "RPC.View3", &archive.ArgAid{Aid: 10111165}, &view); err != nil {
  48. ctx.Println(err)
  49. return
  50. }
  51. ctx.Println(view)
  52. if err = client.Call(context.TODO(), "RPC.Views3", &archive.ArgAids{Aids: []int64{10111165}}, &views); err != nil {
  53. ctx.Println(err)
  54. return
  55. }
  56. ctx.Println(views)
  57. })
  58. }
  59. func TestPing(t *testing.T) {
  60. var (
  61. c = context.TODO()
  62. )
  63. convey.Convey("Ping", t, func(ctx convey.C) {
  64. d.Ping(c)
  65. })
  66. }
  67. func TestArchive3(t *testing.T) {
  68. var (
  69. c = context.TODO()
  70. aid = int64(0)
  71. )
  72. convey.Convey("Archive3", t, func(ctx convey.C) {
  73. _, err := d.Archive3(c, aid)
  74. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  75. ctx.So(err, convey.ShouldBeNil)
  76. })
  77. })
  78. }
  79. func TestArchives(t *testing.T) {
  80. var (
  81. c = context.TODO()
  82. aids = []int64{1}
  83. )
  84. convey.Convey("Archives", t, func(ctx convey.C) {
  85. _, err := d.Archives(c, aids)
  86. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. })
  89. })
  90. }
  91. func TestShot(t *testing.T) {
  92. var (
  93. c = context.TODO()
  94. aid = int64(1)
  95. cid = int64(2)
  96. )
  97. convey.Convey("Shot", t, func(ctx convey.C) {
  98. d.Shot(c, aid, cid)
  99. })
  100. }
  101. func TestUpCount2(t *testing.T) {
  102. var (
  103. c = context.TODO()
  104. mid = int64(1)
  105. )
  106. convey.Convey("UpCount2", t, func(ctx convey.C) {
  107. _, err := d.UpCount2(c, mid)
  108. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  109. ctx.So(err, convey.ShouldBeNil)
  110. })
  111. })
  112. }
  113. func TestUpArcs3(t *testing.T) {
  114. var (
  115. c = context.TODO()
  116. mid = int64(1)
  117. pn = int(1)
  118. ps = int(20)
  119. )
  120. convey.Convey("UpArcs3", t, func(ctx convey.C) {
  121. d.UpArcs3(c, mid, pn, ps)
  122. })
  123. }
  124. func TestProgress(t *testing.T) {
  125. var (
  126. c = context.TODO()
  127. aid = int64(1)
  128. mid = int64(1)
  129. )
  130. convey.Convey("Progress", t, func(ctx convey.C) {
  131. _, err := d.Progress(c, aid, mid)
  132. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  133. ctx.So(err, convey.ShouldBeNil)
  134. })
  135. })
  136. }
  137. func TestArchive(t *testing.T) {
  138. var (
  139. c = context.TODO()
  140. aid = int64(-1)
  141. )
  142. convey.Convey("Archive", t, func(ctx convey.C) {
  143. _, err := d.Archive(c, aid)
  144. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  145. ctx.So(err, convey.ShouldNotBeNil)
  146. })
  147. })
  148. }