dao_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package data
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/admin/main/videoup/conf"
  6. "testing"
  7. . "github.com/smartystreets/goconvey/convey"
  8. "os"
  9. )
  10. func WithDao(f func(d *Dao)) func() {
  11. return func() {
  12. Reset(func() {})
  13. f(d)
  14. }
  15. }
  16. func TestArchiveRelated(t *testing.T) {
  17. Convey("ArchiveRelated", t, WithDao(func(d *Dao) {
  18. httpMock("GET", d.relatedURI).Reply(200).JSON(`{"code":0,"data":[{"key":"123","value":"123"}]}`)
  19. _, err := d.ArchiveRelated(context.TODO(), []int64{10010, 10086})
  20. So(err, ShouldBeNil)
  21. }))
  22. }
  23. func TestMain(m *testing.M) {
  24. if os.Getenv("DEPLOY_ENV") != "" {
  25. flag.Set("app_id", "main.archive.videoup-admin")
  26. flag.Set("conf_token", "gRSfeavV7kJdY9875Gf29pbd2wrdKZ1a")
  27. flag.Set("tree_id", "2307")
  28. flag.Set("conf_version", "docker-1")
  29. flag.Set("deploy_env", "uat")
  30. flag.Set("conf_host", "config.bilibili.co")
  31. flag.Set("conf_path", "/tmp")
  32. flag.Set("region", "sh")
  33. flag.Set("zone", "sh001")
  34. } else {
  35. flag.Set("conf", "../../cmd/videoup-admin.toml")
  36. }
  37. flag.Parse()
  38. if err := conf.Init(); err != nil {
  39. panic(err)
  40. }
  41. d = New(conf.Conf)
  42. os.Exit(m.Run())
  43. }
  44. func TestMonitorOids(t *testing.T) {
  45. Convey("MonitorOids", t, WithDao(func(d *Dao) {
  46. httpMock("GET", d.moniOidsURI).Reply(200).JSON(`{"code":0,"data":[{"oid":123,"time":123}]}`)
  47. _, err := d.MonitorOids(context.TODO(), 1)
  48. So(err, ShouldBeNil)
  49. }))
  50. }