dao_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package archive
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "os"
  7. "testing"
  8. "go-common/app/interface/main/app-player/conf"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.app-svr.app-player")
  17. flag.Set("conf_token", "e477d98a7c5689623eca4f32f6af735c")
  18. flag.Set("tree_id", "52581")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. }
  26. flag.Parse()
  27. if err := conf.Init(); err != nil {
  28. panic(err)
  29. }
  30. d = New(conf.Conf)
  31. m.Run()
  32. os.Exit(0)
  33. }
  34. func TestPing(t *testing.T) {
  35. var (
  36. c = context.Background()
  37. )
  38. convey.Convey("Ping", t, func(ctx convey.C) {
  39. err := d.Ping(c)
  40. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. })
  43. })
  44. }
  45. func TestArchiveCache(t *testing.T) {
  46. var (
  47. c = context.Background()
  48. aid = int64(10110670)
  49. )
  50. convey.Convey("ArchiveCache", t, func(ctx convey.C) {
  51. arc, err := d.ArchiveCache(c, aid)
  52. fmt.Printf("%#v", arc)
  53. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. })
  56. })
  57. }
  58. func TestViews(t *testing.T) {
  59. var (
  60. c = context.Background()
  61. aids = []int64{10110670}
  62. )
  63. convey.Convey("Views", t, func(ctx convey.C) {
  64. _, err := d.Views(c, aids)
  65. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  66. ctx.So(err, convey.ShouldBeNil)
  67. })
  68. })
  69. }