es_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "go-common/app/job/main/search/conf"
  8. "go-common/app/job/main/search/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func WithES(f func(d *Dao)) func() {
  12. return func() {
  13. dir, _ := filepath.Abs("../cmd/goconvey.toml")
  14. flag.Set("conf", dir)
  15. flag.Parse()
  16. conf.Init()
  17. d := New(conf.Conf)
  18. f(d)
  19. }
  20. }
  21. func Test_WithES(t *testing.T) {
  22. Convey("Test_WithES", t, WithES(func(d *Dao) {
  23. var (
  24. err error
  25. c = context.TODO()
  26. )
  27. err = d.Ping(c)
  28. So(err, ShouldBeNil)
  29. }))
  30. }
  31. func Test_BulkDatabusData(t *testing.T) {
  32. Convey("Test_BulkDatabusData", t, WithES(func(d *Dao) {
  33. var (
  34. err error
  35. c = context.TODO()
  36. attrs = &model.Attrs{
  37. DataSQL: &model.AttrDataSQL{},
  38. }
  39. )
  40. attrs.ESName = "archive"
  41. attrs.DataSQL.DataIndexSuffix = ""
  42. d.BulkDatabusData(c, attrs, false)
  43. So(err, ShouldBeNil)
  44. }))
  45. }
  46. func Test_BulkDBData(t *testing.T) {
  47. Convey("Test_BulkDBData", t, WithES(func(d *Dao) {
  48. var (
  49. err error
  50. c = context.TODO()
  51. attrs = &model.Attrs{
  52. DataSQL: &model.AttrDataSQL{},
  53. }
  54. )
  55. attrs.ESName = "archive"
  56. attrs.DataSQL.DataIndexSuffix = ""
  57. d.BulkDBData(c, attrs, false)
  58. So(err, ShouldBeNil)
  59. }))
  60. }
  61. func Test_PingESCluster(t *testing.T) {
  62. Convey("Test_PingESCluster", t, WithES(func(d *Dao) {
  63. var (
  64. c = context.TODO()
  65. err error
  66. )
  67. err = d.pingESCluster(c)
  68. So(err, ShouldBeNil)
  69. }))
  70. }