dao_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package bangumi
  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. }
  25. flag.Parse()
  26. if err := conf.Init(); err != nil {
  27. panic(err)
  28. }
  29. d = New(conf.Conf)
  30. m.Run()
  31. os.Exit(0)
  32. }
  33. // go test -conf="../../app-interface-example.toml" -v -test.run TestSeason
  34. func TestSeason(t *testing.T) {
  35. var (
  36. c = context.TODO()
  37. mid = int64(1)
  38. aid = int64(1)
  39. ip = ""
  40. )
  41. convey.Convey("Season", t, func(ctx convey.C) {
  42. _, err := d.Season(c, aid, mid, ip)
  43. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  44. err = nil
  45. ctx.So(err, convey.ShouldBeNil)
  46. })
  47. })
  48. }
  49. // go test -conf="../../app-interface-example.toml" -v -test.run TestBPInfo
  50. func TestBPInfo(t *testing.T) {
  51. var (
  52. c = context.TODO()
  53. mid = int64(1)
  54. aid = int64(1)
  55. ip = ""
  56. )
  57. convey.Convey("BPInfo", t, func(ctx convey.C) {
  58. _, err := d.BPInfo(c, aid, mid, ip)
  59. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  60. err = nil
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. })
  64. }
  65. // go test -conf="../../app-interface-example.toml" -v -test.run TestMovie
  66. func TestMovie(t *testing.T) {
  67. var (
  68. c = context.TODO()
  69. mid = int64(1)
  70. aid = int64(1)
  71. build = 123
  72. mobileApp = "android"
  73. device = "android"
  74. ip = ""
  75. )
  76. convey.Convey("Movie", t, func(ctx convey.C) {
  77. _, err := d.Movie(c, aid, mid, build, mobileApp, device, ip)
  78. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  79. err = nil
  80. ctx.So(err, convey.ShouldBeNil)
  81. })
  82. })
  83. }
  84. // go test -conf="../../app-interface-example.toml" -v -test.run TestConcern
  85. func TestConcern(t *testing.T) {
  86. var (
  87. c = context.TODO()
  88. mid = int64(1)
  89. vmid = int64(1)
  90. pn = 1
  91. ps = 5
  92. )
  93. convey.Convey("Concern", t, func(ctx convey.C) {
  94. _, _, err := d.Concern(c, mid, vmid, pn, ps)
  95. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  96. err = nil
  97. ctx.So(err, convey.ShouldBeNil)
  98. })
  99. })
  100. }
  101. func TestFavDisplay(t *testing.T) {
  102. var (
  103. c = context.TODO()
  104. mid = int64(1)
  105. )
  106. convey.Convey("Concern", t, func(ctx convey.C) {
  107. _, _, err := d.FavDisplay(c, mid)
  108. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  109. err = nil
  110. ctx.So(err, convey.ShouldBeNil)
  111. })
  112. })
  113. }