dao_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "go-common/app/admin/main/push/conf"
  8. "go-common/app/admin/main/push/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var d *Dao
  12. func init() {
  13. dir, _ := filepath.Abs("../cmd/push-admin-test.toml")
  14. flag.Set("conf", dir)
  15. conf.Init()
  16. d = New(conf.Conf)
  17. }
  18. func WithDao(f func(d *Dao)) func() {
  19. return func() {
  20. f(d)
  21. }
  22. }
  23. func Test_Dao(t *testing.T) {
  24. Convey("dao test", t, WithDao(func(d *Dao) {
  25. d.Ping(context.TODO())
  26. }))
  27. }
  28. func Test_AddDPCondition(t *testing.T) {
  29. Convey("AddDPCondition", t, WithDao(func(d *Dao) {
  30. cond := &model.DPCondition{
  31. Task: 123,
  32. Job: "456",
  33. Condition: "cond",
  34. SQL: "sql",
  35. Status: 2,
  36. StatusURL: "status url",
  37. File: "file",
  38. }
  39. id, err := d.AddDPCondition(context.Background(), cond)
  40. So(err, ShouldBeNil)
  41. So(id, ShouldBeGreaterThan, 0)
  42. }))
  43. }
  44. func Test_DPCondition(t *testing.T) {
  45. Convey("DPContion", t, WithDao(func(d *Dao) {
  46. res, err := d.DPCondition(context.Background(), "456")
  47. So(err, ShouldBeNil)
  48. t.Logf("res(%+v)", res)
  49. }))
  50. }
  51. func Test_AddTask(t *testing.T) {
  52. Convey("add task", t, WithDao(func(d *Dao) {
  53. t := &model.Task{Job: "123", AppID: 2}
  54. _, err := d.AddTask(context.Background(), t)
  55. So(err, ShouldBeNil)
  56. }))
  57. }
  58. func Test_TaskInfo(t *testing.T) {
  59. Convey("task info", t, WithDao(func(d *Dao) {
  60. task, err := d.TaskInfo(context.Background(), 117)
  61. So(err, ShouldBeNil)
  62. t.Logf("task(%+v)", task)
  63. }))
  64. }
  65. func Test_Partitions(t *testing.T) {
  66. Convey("partitions", t, WithDao(func(d *Dao) {
  67. res, err := d.Partitions(context.Background())
  68. So(err, ShouldBeNil)
  69. t.Logf("partitions(%v)", res)
  70. }))
  71. }