log_test.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. "go-common/app/admin/main/search/model"
  8. )
  9. func TestDaoNewLog(t *testing.T) {
  10. convey.Convey("NewLog", t, func(ctx convey.C) {
  11. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  12. d.NewLog()
  13. ctx.Convey("No return values", func(ctx convey.C) {
  14. })
  15. })
  16. })
  17. }
  18. func TestDaoGetLogInfo(t *testing.T) {
  19. convey.Convey("GetLogInfo", t, func(ctx convey.C) {
  20. var (
  21. appID = ""
  22. id = int(0)
  23. )
  24. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  25. business, ok := d.GetLogInfo(appID, id)
  26. ctx.Convey("Then business,ok should not be nil.", func(ctx convey.C) {
  27. ctx.So(ok, convey.ShouldNotBeNil)
  28. ctx.So(business, convey.ShouldNotBeNil)
  29. })
  30. })
  31. })
  32. }
  33. func TestDaoinitMapping(t *testing.T) {
  34. convey.Convey("initMapping", t, func(ctx convey.C) {
  35. var (
  36. appID = ""
  37. )
  38. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  39. business, err := d.initMapping(appID)
  40. ctx.Convey("Then business should not be nil.", func(ctx convey.C) {
  41. ctx.So(business, convey.ShouldNotBeNil)
  42. ctx.So(err, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestDaologIndexName(t *testing.T) {
  48. convey.Convey("logIndexName", t, func(ctx convey.C) {
  49. var (
  50. c = context.Background()
  51. p = &model.LogParams{
  52. CTimeFrom: "2010-01-01 00:00:00",
  53. CTimeTo: "2020-01-01 00:00:00",
  54. }
  55. business = &model.Business{
  56. ID: 0,
  57. AppID: "log_audit",
  58. }
  59. )
  60. ctx.Convey("2006", func(ctx convey.C) {
  61. business.IndexFormat = "2006"
  62. res, err := d.logIndexName(c, p, business)
  63. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. ctx.So(res, convey.ShouldNotBeNil)
  66. })
  67. })
  68. ctx.Convey("2006-01", func(ctx convey.C) {
  69. business.IndexFormat = "2006-01"
  70. res, err := d.logIndexName(c, p, business)
  71. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(res, convey.ShouldNotBeNil)
  74. })
  75. })
  76. ctx.Convey("2006-01-week", func(ctx convey.C) {
  77. business.IndexFormat = "2006-01-week"
  78. res, err := d.logIndexName(c, p, business)
  79. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. ctx.So(res, convey.ShouldNotBeNil)
  82. })
  83. })
  84. ctx.Convey("2006-01-02", func(ctx convey.C) {
  85. business.IndexFormat = "2006-01-02"
  86. res, err := d.logIndexName(c, p, business)
  87. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  88. ctx.So(err, convey.ShouldBeNil)
  89. ctx.So(res, convey.ShouldNotBeNil)
  90. })
  91. })
  92. ctx.Convey("all", func(ctx convey.C) {
  93. business.IndexFormat = "all"
  94. res, err := d.logIndexName(c, p, business)
  95. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. ctx.So(res, convey.ShouldNotBeNil)
  98. })
  99. })
  100. })
  101. }
  102. func TestDaogetLogAuditIndexName(t *testing.T) {
  103. convey.Convey("getLogAuditIndexName", t, func(ctx convey.C) {
  104. var (
  105. business = int(0)
  106. indexName = ""
  107. format = ""
  108. time = time.Now()
  109. )
  110. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  111. index := getLogAuditIndexName(business, indexName, format, time)
  112. ctx.Convey("Then index should not be nil.", func(ctx convey.C) {
  113. ctx.So(index, convey.ShouldNotBeNil)
  114. })
  115. })
  116. })
  117. }
  118. func TestDaogetQuery(t *testing.T) {
  119. convey.Convey("getQuery", t, func(ctx convey.C) {
  120. var (
  121. pr map[string][]interface{}
  122. indexMapping map[string]string
  123. )
  124. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  125. query := d.getQuery(pr, indexMapping)
  126. ctx.Convey("Then query should not be nil.", func(ctx convey.C) {
  127. ctx.So(query, convey.ShouldNotBeNil)
  128. })
  129. })
  130. })
  131. }
  132. func TestDaoLogAudit(t *testing.T) {
  133. convey.Convey("LogAudit", t, func(ctx convey.C) {
  134. var (
  135. c = context.Background()
  136. pr map[string][]interface{}
  137. sp = &model.LogParams{}
  138. business = &model.Business{}
  139. )
  140. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  141. res, err := d.LogAudit(c, pr, sp, business)
  142. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  143. ctx.So(err, convey.ShouldBeNil)
  144. ctx.So(res, convey.ShouldNotBeNil)
  145. })
  146. })
  147. })
  148. }
  149. func TestDaoLogAuditGroupBy(t *testing.T) {
  150. convey.Convey("LogAuditGroupBy", t, func(ctx convey.C) {
  151. var (
  152. c = context.Background()
  153. pr = map[string][]interface{}{
  154. "group": {"group"},
  155. }
  156. sp = &model.LogParams{}
  157. business = &model.Business{}
  158. )
  159. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  160. res, err := d.LogAuditGroupBy(c, pr, sp, business)
  161. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. ctx.So(res, convey.ShouldNotBeNil)
  164. })
  165. })
  166. })
  167. }
  168. func TestDaoLogAuditDelete(t *testing.T) {
  169. convey.Convey("LogAuditDelete", t, func(ctx convey.C) {
  170. var (
  171. c = context.Background()
  172. pr map[string][]interface{}
  173. sp = &model.LogParams{}
  174. business = &model.Business{}
  175. )
  176. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  177. res, err := d.LogAuditDelete(c, pr, sp, business)
  178. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  179. ctx.So(err, convey.ShouldBeNil)
  180. ctx.So(res, convey.ShouldNotBeNil)
  181. })
  182. })
  183. })
  184. }
  185. func TestDaoLogUserAction(t *testing.T) {
  186. convey.Convey("LogUserAction", t, func(ctx convey.C) {
  187. var (
  188. c = context.Background()
  189. pr map[string][]interface{}
  190. sp = &model.LogParams{}
  191. business = &model.Business{}
  192. )
  193. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  194. res, err := d.LogUserAction(c, pr, sp, business)
  195. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  196. ctx.So(err, convey.ShouldBeNil)
  197. ctx.So(res, convey.ShouldNotBeNil)
  198. })
  199. })
  200. })
  201. }
  202. func TestDaoLogUserActionDelete(t *testing.T) {
  203. convey.Convey("LogUserActionDelete", t, func(ctx convey.C) {
  204. var (
  205. c = context.Background()
  206. pr map[string][]interface{}
  207. sp = &model.LogParams{}
  208. business = &model.Business{}
  209. )
  210. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  211. res, err := d.LogUserActionDelete(c, pr, sp, business)
  212. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  213. ctx.So(err, convey.ShouldBeNil)
  214. ctx.So(res, convey.ShouldNotBeNil)
  215. })
  216. })
  217. })
  218. }
  219. func TestDaoUDepTs(t *testing.T) {
  220. convey.Convey("UDepTs", t, func(ctx convey.C) {
  221. var (
  222. c = context.Background()
  223. uids = []string{}
  224. )
  225. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  226. res, err := d.UDepTs(c, uids)
  227. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  228. ctx.So(err, convey.ShouldBeNil)
  229. ctx.So(res, convey.ShouldNotBeNil)
  230. })
  231. })
  232. })
  233. }
  234. func TestDaoIP(t *testing.T) {
  235. convey.Convey("IP", t, func(ctx convey.C) {
  236. var (
  237. c = context.Background()
  238. )
  239. ip := []string{
  240. "127.0.0.1",
  241. }
  242. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  243. //res, err :=
  244. d.IP(c, ip)
  245. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  246. //ctx.So(err, convey.ShouldBeNil)
  247. //ctx.So(res, convey.ShouldNotBeNil)
  248. })
  249. })
  250. })
  251. }
  252. func TestDaoLogCount(t *testing.T) {
  253. convey.Convey("LogCount", t, func(ctx convey.C) {
  254. var (
  255. c = context.Background()
  256. name = ""
  257. business = int(0)
  258. uid = interface{}(0)
  259. )
  260. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  261. d.LogCount(c, name, business, uid)
  262. ctx.Convey("No return values", func(ctx convey.C) {
  263. })
  264. })
  265. })
  266. }