search_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package search
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "go-common/app/admin/main/feed/conf"
  10. searchModel "go-common/app/admin/main/feed/model/search"
  11. "go-common/library/log"
  12. "github.com/smartystreets/goconvey/convey"
  13. )
  14. var (
  15. s *Service
  16. c = context.Background()
  17. )
  18. func init() {
  19. var (
  20. err error
  21. )
  22. dir, _ := filepath.Abs("../../cmd/feed-admin-test.toml")
  23. flag.Set("conf", dir)
  24. conf.Init()
  25. if s = New(conf.Conf); err != nil {
  26. log.Error("bgmdao.New error(%v)", err)
  27. return
  28. }
  29. }
  30. func TestIsTodayAutoPubHot(t *testing.T) {
  31. convey.Convey("isTodayAutoPubHot", t, func(ctx convey.C) {
  32. var (
  33. c = context.Background()
  34. err error
  35. res bool
  36. )
  37. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  38. res, err = s.isTodayAutoPubHot(c)
  39. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  40. ctx.So(err, convey.ShouldBeNil)
  41. ctx.So(res, convey.ShouldNotBeNil)
  42. })
  43. })
  44. })
  45. }
  46. func TestIsTodayAutoPubDark(t *testing.T) {
  47. convey.Convey("isTodayAutoPubDark", t, func(ctx convey.C) {
  48. var (
  49. err error
  50. res bool
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. res, err = s.isTodayAutoPubDark(c)
  54. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(res, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestParseTime(t *testing.T) {
  62. convey.Convey("parseTime", t, func(ctx convey.C) {
  63. var (
  64. err error
  65. res time.Time
  66. )
  67. timeTwelve := time.Now().Format("2006-01-02 ") + "12:00:00"
  68. layout := "2006-01-02 15:04:05"
  69. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  70. res, err = s.parseTime(timeTwelve, layout)
  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. fmt.Println(res)
  76. })
  77. })
  78. }
  79. func TestHotwordFromDB(t *testing.T) {
  80. convey.Convey("HotwordFromDB", t, func(ctx convey.C) {
  81. var (
  82. err error
  83. res []searchModel.Intervene
  84. )
  85. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  86. res, _, err = s.HotwordFromDB("2018-09-05")
  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. fmt.Println(res)
  92. })
  93. })
  94. }
  95. func TestDarkwordFromDB(t *testing.T) {
  96. convey.Convey("HotwordFromDB", t, func(ctx convey.C) {
  97. var (
  98. err error
  99. res []searchModel.Dark
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  102. res, _, err = s.DarkwordFromDB(time.Now().Format("2006-01-02"))
  103. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  104. ctx.So(err, convey.ShouldBeNil)
  105. ctx.So(res, convey.ShouldNotBeNil)
  106. })
  107. fmt.Println(res)
  108. })
  109. })
  110. }
  111. func TestOpenHotList(t *testing.T) {
  112. convey.Convey("HotwordFromDB", t, func(ctx convey.C) {
  113. var (
  114. err error
  115. res []searchModel.Intervene
  116. )
  117. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  118. //c = context.Background()
  119. //res, err = s.OpenHotList(c)
  120. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(res, convey.ShouldNotBeNil)
  123. })
  124. fmt.Println(res)
  125. })
  126. })
  127. }
  128. func TestHotList(t *testing.T) {
  129. convey.Convey("HotList", t, func(ctx convey.C) {
  130. var (
  131. err error
  132. res []searchModel.Intervene
  133. )
  134. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  135. //res, err = s.HotList(c)
  136. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. ctx.So(res, convey.ShouldNotBeNil)
  139. })
  140. fmt.Println(res)
  141. })
  142. })
  143. }
  144. func TestDarkList(t *testing.T) {
  145. convey.Convey("DarkList", t, func(ctx convey.C) {
  146. var (
  147. err error
  148. res []searchModel.Intervene
  149. )
  150. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  151. //res, err = s.DarkList(c)
  152. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  153. ctx.So(err, convey.ShouldBeNil)
  154. ctx.So(res, convey.ShouldNotBeNil)
  155. })
  156. fmt.Println(res)
  157. })
  158. })
  159. }
  160. func TestBlackList(t *testing.T) {
  161. convey.Convey("BlackList", t, func(ctx convey.C) {
  162. var (
  163. err error
  164. res []searchModel.Black
  165. )
  166. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  167. res, err = s.BlackList()
  168. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  169. ctx.So(err, convey.ShouldBeNil)
  170. ctx.So(res, convey.ShouldNotBeNil)
  171. })
  172. fmt.Println(res)
  173. })
  174. })
  175. }
  176. func TestDelBlack(t *testing.T) {
  177. convey.Convey("DelBlack", t, func(ctx convey.C) {
  178. var (
  179. err error
  180. res []searchModel.Black
  181. )
  182. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  183. //res, err = s.DelBlack()
  184. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  185. ctx.So(err, convey.ShouldBeNil)
  186. ctx.So(res, convey.ShouldNotBeNil)
  187. })
  188. fmt.Println(res)
  189. })
  190. })
  191. }
  192. func TestAddBlack(t *testing.T) {
  193. convey.Convey("AddBlack", t, func(ctx convey.C) {
  194. var (
  195. err error
  196. res []searchModel.Black
  197. )
  198. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  199. //err = s.AddBlack()
  200. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  201. ctx.So(err, convey.ShouldBeNil)
  202. ctx.So(res, convey.ShouldNotBeNil)
  203. })
  204. fmt.Println(res)
  205. })
  206. })
  207. }
  208. func TestCheckBlack(t *testing.T) {
  209. convey.Convey("checkBlack", t, func(ctx convey.C) {
  210. var (
  211. err error
  212. res bool
  213. )
  214. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  215. res, err = s.checkBlack("test")
  216. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  217. ctx.So(err, convey.ShouldBeNil)
  218. ctx.So(res, convey.ShouldNotBeNil)
  219. })
  220. fmt.Println(res)
  221. })
  222. })
  223. }
  224. func TestCheckInter(t *testing.T) {
  225. convey.Convey("checkInter", t, func(ctx convey.C) {
  226. var (
  227. err error
  228. res bool
  229. )
  230. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  231. res, err = s.checkInter("test", 0)
  232. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  233. ctx.So(err, convey.ShouldBeNil)
  234. ctx.So(res, convey.ShouldNotBeNil)
  235. })
  236. fmt.Println(res)
  237. })
  238. })
  239. }
  240. func TestCheckTimeConflict(t *testing.T) {
  241. convey.Convey("checkTimeConflict", t, func(ctx convey.C) {
  242. var (
  243. err error
  244. res bool
  245. model = searchModel.InterveneAdd{
  246. Rank: 10,
  247. Stime: 1536134791,
  248. Etime: 1536134791,
  249. }
  250. )
  251. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  252. res, err = s.checkTimeConflict(model, 0)
  253. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  254. ctx.So(err, convey.ShouldBeNil)
  255. ctx.So(res, convey.ShouldNotBeNil)
  256. })
  257. fmt.Println(res)
  258. })
  259. })
  260. }
  261. func TestAddInter(t *testing.T) {
  262. convey.Convey("checkTimeConflict", t, func(ctx convey.C) {
  263. var (
  264. err error
  265. res bool
  266. )
  267. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  268. //res, err = s.AddInter(model, 0)
  269. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  270. ctx.So(err, convey.ShouldBeNil)
  271. ctx.So(res, convey.ShouldNotBeNil)
  272. })
  273. fmt.Println(res)
  274. })
  275. })
  276. }
  277. func TestUpdateInter(t *testing.T) {
  278. convey.Convey("UpdateInter", t, func(ctx convey.C) {
  279. var (
  280. err error
  281. res bool
  282. )
  283. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  284. //res, err = s.AddInter(model, 0)
  285. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  286. ctx.So(err, convey.ShouldBeNil)
  287. ctx.So(res, convey.ShouldNotBeNil)
  288. })
  289. fmt.Println(res)
  290. })
  291. })
  292. }
  293. func TestUpdateSearch(t *testing.T) {
  294. convey.Convey("UpdateSearch", t, func(ctx convey.C) {
  295. var (
  296. err error
  297. res bool
  298. )
  299. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  300. //res, err = s.AddInter(model, 0)
  301. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  302. ctx.So(err, convey.ShouldBeNil)
  303. ctx.So(res, convey.ShouldNotBeNil)
  304. })
  305. fmt.Println(res)
  306. })
  307. })
  308. }
  309. func TestDeleteHot(t *testing.T) {
  310. convey.Convey("DeleteHot", t, func(ctx convey.C) {
  311. var (
  312. err error
  313. res bool
  314. )
  315. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  316. err = s.DeleteHot(c, 10, 2, "quguolin", 100)
  317. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  318. ctx.So(err, convey.ShouldBeNil)
  319. ctx.So(res, convey.ShouldNotBeNil)
  320. })
  321. fmt.Println(res)
  322. })
  323. })
  324. }
  325. func TestDeleteDark(t *testing.T) {
  326. convey.Convey("DeleteDark", t, func(ctx convey.C) {
  327. var (
  328. err error
  329. res bool
  330. )
  331. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  332. err = s.DeleteDark(c, 10, "quguolin", 100)
  333. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  334. ctx.So(err, convey.ShouldBeNil)
  335. ctx.So(res, convey.ShouldNotBeNil)
  336. })
  337. fmt.Println(res)
  338. })
  339. })
  340. }
  341. func TestOpenAddDarkword(t *testing.T) {
  342. convey.Convey("OpenAddDarkword", t, func(ctx convey.C) {
  343. var (
  344. err error
  345. res bool
  346. value searchModel.OpenDark
  347. )
  348. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  349. err = s.OpenAddDarkword(c, value)
  350. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  351. ctx.So(err, convey.ShouldBeNil)
  352. ctx.So(res, convey.ShouldNotBeNil)
  353. })
  354. fmt.Println(res)
  355. })
  356. })
  357. }
  358. func TestOpenAddHotword(t *testing.T) {
  359. convey.Convey("OpenAddHotword", t, func(ctx convey.C) {
  360. var (
  361. err error
  362. res bool
  363. //value searchModel.OpenHot
  364. )
  365. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  366. //err = s.OpenAddHotword(c, value)
  367. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  368. ctx.So(err, convey.ShouldBeNil)
  369. ctx.So(res, convey.ShouldNotBeNil)
  370. })
  371. fmt.Println(res)
  372. })
  373. })
  374. }
  375. func TestGetHotPub(t *testing.T) {
  376. convey.Convey("GetHotPub", t, func(ctx convey.C) {
  377. var (
  378. err error
  379. res bool
  380. //value searchModel.OpenHot
  381. )
  382. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  383. //err = s.OpenAddHotword(c, value)
  384. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  385. ctx.So(err, convey.ShouldBeNil)
  386. ctx.So(res, convey.ShouldNotBeNil)
  387. })
  388. fmt.Println(res)
  389. })
  390. })
  391. }
  392. func TestGetDarkPub(t *testing.T) {
  393. convey.Convey("GetDarkPub", t, func(ctx convey.C) {
  394. var (
  395. err error
  396. res bool
  397. //value searchModel.OpenHot
  398. )
  399. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  400. //err = s.GetDarkPub(c, value)
  401. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  402. ctx.So(err, convey.ShouldBeNil)
  403. ctx.So(res, convey.ShouldNotBeNil)
  404. })
  405. fmt.Println(res)
  406. })
  407. })
  408. }
  409. func TestSetHotPub(t *testing.T) {
  410. convey.Convey("SetHotPub", t, func(ctx convey.C) {
  411. var (
  412. err error
  413. res bool
  414. //value searchModel.OpenHot
  415. )
  416. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  417. err = s.SetHotPub(c, "quguolin", 100)
  418. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  419. ctx.So(err, convey.ShouldBeNil)
  420. ctx.So(res, convey.ShouldNotBeNil)
  421. })
  422. fmt.Println(res)
  423. })
  424. })
  425. }
  426. func TestHotPubLog(t *testing.T) {
  427. convey.Convey("HotPubLog", t, func(ctx convey.C) {
  428. var (
  429. err error
  430. res bool
  431. value []searchModel.Intervene
  432. )
  433. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  434. err = s.HotPubLog(value)
  435. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  436. ctx.So(err, convey.ShouldBeNil)
  437. ctx.So(res, convey.ShouldNotBeNil)
  438. })
  439. fmt.Println(res)
  440. })
  441. })
  442. }
  443. func TestGetHotPubLog(t *testing.T) {
  444. convey.Convey("GetHotPubLog", t, func(ctx convey.C) {
  445. var (
  446. err error
  447. res []searchModel.Intervene
  448. pub bool
  449. )
  450. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  451. res, pub, err = s.GetHotPubLog("2018-09-03")
  452. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  453. ctx.So(err, convey.ShouldBeNil)
  454. //ctx.So(res, convey.ShouldNotBeNil)
  455. })
  456. fmt.Println(res, pub)
  457. })
  458. })
  459. }
  460. func TestGetDarkPubLog(t *testing.T) {
  461. convey.Convey("GetDarkPubLog", t, func(ctx convey.C) {
  462. var (
  463. err error
  464. res []searchModel.Dark
  465. pub bool
  466. )
  467. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  468. res, pub, err = s.GetDarkPubLog("2018-09-03")
  469. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  470. ctx.So(err, convey.ShouldBeNil)
  471. //ctx.So(res, convey.ShouldNotBeNil)
  472. })
  473. fmt.Println(res, pub)
  474. })
  475. })
  476. }
  477. func TestSetDarkPub(t *testing.T) {
  478. convey.Convey("SetDarkPub", t, func(ctx convey.C) {
  479. var (
  480. err error
  481. res []searchModel.Intervene
  482. )
  483. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  484. s.SetDarkPub(c, "quguolin", 10)
  485. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  486. ctx.So(err, convey.ShouldBeNil)
  487. //ctx.So(res, convey.ShouldNotBeNil)
  488. })
  489. fmt.Println(res)
  490. })
  491. })
  492. }
  493. func TestDarkPubLog(t *testing.T) {
  494. convey.Convey("DarkPubLog", t, func(ctx convey.C) {
  495. var (
  496. err error
  497. dark []searchModel.Dark
  498. )
  499. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  500. s.DarkPubLog(dark)
  501. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  502. ctx.So(err, convey.ShouldBeNil)
  503. //ctx.So(res, convey.ShouldNotBeNil)
  504. })
  505. })
  506. })
  507. }