es_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/search/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/olivere/elastic.v5"
  8. )
  9. func TestDaoUpdateMapBulk(t *testing.T) {
  10. convey.Convey("UpdateMapBulk", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. esName = ""
  14. bulkData = []BulkMapItem{}
  15. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. //err :=
  18. d.UpdateMapBulk(c, esName, bulkData)
  19. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  20. //ctx.So(err, convey.ShouldBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoUpdateBulk(t *testing.T) {
  26. convey.Convey("UpdateBulk", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. esName = ""
  30. bulkData = []BulkItem{}
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. //err :=
  34. d.UpdateBulk(c, esName, bulkData)
  35. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  36. //ctx.So(err, convey.ShouldBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoUpsertBulk(t *testing.T) {
  42. convey.Convey("UpsertBulk", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. esCluster = ""
  46. up = &model.UpsertParams{}
  47. )
  48. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  49. err := d.UpsertBulk(c, esCluster, up)
  50. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. })
  53. })
  54. })
  55. }
  56. func TestDaosearchResult(t *testing.T) {
  57. convey.Convey("searchResult", t, func(ctx convey.C) {
  58. var (
  59. c = context.Background()
  60. esClusterName = ""
  61. indexName = ""
  62. query elastic.Query
  63. bsp = &model.BasicSearchParams{}
  64. )
  65. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  66. res, err := d.searchResult(c, esClusterName, indexName, query, bsp)
  67. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(res, convey.ShouldNotBeNil)
  70. })
  71. })
  72. })
  73. }
  74. func TestDaoQueryResult(t *testing.T) {
  75. convey.Convey("QueryResult", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. query elastic.Query
  79. sp = &model.QueryParams{
  80. AppIDConf: &model.QueryConfDetail{
  81. ESCluster: "",
  82. },
  83. }
  84. qbDebug = &model.QueryDebugResult{}
  85. )
  86. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  87. _, qrDebug, err := d.QueryResult(c, query, sp, qbDebug)
  88. ctx.Convey("Then err should be nil.res,qrDebug should not be nil.", func(ctx convey.C) {
  89. ctx.So(err, convey.ShouldBeNil)
  90. ctx.So(qrDebug, convey.ShouldNotBeNil)
  91. //ctx.So(res, convey.ShouldNotBeNil)
  92. })
  93. })
  94. })
  95. }
  96. func TestDaoBulkIndex(t *testing.T) {
  97. convey.Convey("BulkIndex", t, func(ctx convey.C) {
  98. var (
  99. c = context.Background()
  100. esName = ""
  101. bulkData = []BulkItem{}
  102. )
  103. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  104. //err :=
  105. d.BulkIndex(c, esName, bulkData)
  106. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  107. //ctx.So(err, convey.ShouldBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestDaoExistIndex(t *testing.T) {
  113. convey.Convey("ExistIndex", t, func(ctx convey.C) {
  114. var (
  115. c = context.Background()
  116. esClusterName = ""
  117. indexName = ""
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. exist, _ := d.ExistIndex(c, esClusterName, indexName)
  121. ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
  122. //ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(exist, convey.ShouldNotBeNil)
  124. })
  125. })
  126. })
  127. }