dao_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package archive
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/app/admin/main/videoup/conf"
  6. "testing"
  7. . "github.com/smartystreets/goconvey/convey"
  8. "gopkg.in/h2non/gock.v1"
  9. "os"
  10. "strings"
  11. )
  12. var (
  13. d *Dao
  14. )
  15. func WithDao(f func(d *Dao)) func() {
  16. return func() {
  17. Reset(func() {})
  18. f(d)
  19. }
  20. }
  21. func TestWeightLog(t *testing.T) {
  22. Convey("WeightLog", t, WithDao(func(d *Dao) {
  23. d.WeightLog(context.TODO(), 2604)
  24. }))
  25. }
  26. func TestGetNextTask(t *testing.T) {
  27. Convey("GetNextTask", t, WithDao(func(d *Dao) {
  28. _, err := d.GetNextTask(context.TODO(), 102)
  29. So(err, ShouldBeNil)
  30. }))
  31. }
  32. func httpMock(method, url string) *gock.Request {
  33. r := gock.New(url)
  34. r.Method = strings.ToUpper(method)
  35. d.clientR.SetTransport(gock.DefaultTransport)
  36. return r
  37. }
  38. func TestMain(m *testing.M) {
  39. if os.Getenv("DEPLOY_ENV") != "" {
  40. flag.Set("app_id", "main.archive.videoup-admin")
  41. flag.Set("conf_token", "gRSfeavV7kJdY9875Gf29pbd2wrdKZ1a")
  42. flag.Set("tree_id", "2307")
  43. flag.Set("conf_version", "docker-1")
  44. flag.Set("deploy_env", "uat")
  45. flag.Set("conf_host", "config.bilibili.co")
  46. flag.Set("conf_path", "/tmp")
  47. flag.Set("region", "sh")
  48. flag.Set("zone", "sh001")
  49. } else {
  50. flag.Set("conf", "../../cmd/videoup-admin.toml")
  51. }
  52. flag.Parse()
  53. if err := conf.Init(); err != nil {
  54. panic(err)
  55. }
  56. d = New(conf.Conf)
  57. os.Exit(m.Run())
  58. }